November 23, 2006
at 6:21 am /
#10289
This script moves a point in the same plane made by 3 points.
[pre class=’ip-ubbcode-code-pre’]
Language = VBScript
‘*********************************************************************************
‘ Purpose: Move a point on the same plane as 3 selected points
‘*********************************************************************************
Option Explicit ‘require variable declarations
Sub Main (3DCApp)
Dim GeneralMessage
Dim Message
Dim Scene
Dim Object
Dim X1, Y1, Z1
Dim X2, Y2, Z2
Dim X3, Y3, Z3
Dim Xa, Ya, Za
Dim Xp, Yp, Zp
Dim Ap, Bp, Cp, Dp
Dim i
Dim PointDistance
Dim ActivePointsCount
Dim ActiveObjectsCount
Dim CurrentPoint, PointP
GeneralMessage=’Please select the point to be projected on a plane followed by 3 different points making up the plane’
‘get the scene
Set Scene = 3DCApp.GetActiveScene
‘Count number of selected points
ActiveObjectsCount = Scene.GetActiveObjectCount
ActivePointsCount = Scene.GetActivePointCount
‘only proceed if there are 4 active points
If ActivePointsCount andlt;andgt; 4 AND ActiveObjectsCount andlt;andgt; 4 Then
MsgBox GeneralMessage
Else
Set Object = Scene.GetActiveObject(0)
‘ Get the point to be projected
PointP = Scene.GetActivePoint(0)
Object.GetPoint PointP, Xa, Ya, Za
‘ Get first point
CurrentPoint = Scene.GetActivePoint(1)
Object.GetPoint CurrentPoint, X1, Y1, Z1
‘ Get second point
CurrentPoint = Scene.GetActivePoint(2)
Object.GetPoint CurrentPoint, X2, Y2, Z2
‘ Get third point
CurrentPoint = Scene.GetActivePoint(3)
Object.GetPoint CurrentPoint, X3, Y3, Z3
‘ Checks in case of welded points selection
If X1=X2 AND Y1=Y2 AND Z1=Z2 Then
Message=GeneralMessageand’ (Plane points 1 and 2 are identical)’
MsgBox(Message)
Else
If X1=X3 AND Y1=Y3 AND Z1=Z3 Then
Message=GeneralMessageand’ (Plane points 1 and 3 are identical)’
MsgBox(Message)
Else
If X2=X3 AND Y2=Y3 AND Z2=Z3 Then
Message=GeneralMessageand’ (Plane points 2 and 3 are identical)’
MsgBox(Message)
Else
Message=’Plane points: ‘andX1and’ ‘andY1and’ ‘andZ1and’ // ‘andX2and’ ‘andY2and’ ‘andZ2and’ // ‘andX3and’ ‘andY3and’ ‘andZ3
Message=Messageand’ Point to be projected ‘andXaand’ ‘andYaand’ ‘andZa
MsgBox(Message)
‘ Compute plane parameters
Ap = (Y2 – Y1)*(Z3 – Z1) – (Z2 – Z1)*(Y3 – Y1)
Bp = -(X2 – X1)*(Z3 – Z1) + (Z2 – Z1)*(X3 – X1)
Cp = (X2 – X1)*(Y3 – Y1) – (Y2 – Y1)*(X3 – X1)
i = SQR(Ap^2+Bp^2+Cp^2)
‘ Normalize
Ap=Ap/i
Bp=Bp/i
Cp=Cp/i
Dp = -Ap*X1 – Bp*Y1 – Cp*Z1
‘ Distance from plane
PointDistance = Ap*Xa+Bp*Ya+Cp*Za+Dp
‘Compute the new coordinates
Xp=Xa-PointDistance*Ap
Yp=Ya-PointDistance*Bp
Zp=Za-PointDistance*Cp
‘Message=’A=’andApand’ B=’andBpand’ C=’andCpand’
‘andDpand’ PointDistance=’andPointDistanceand’ Projection=’andXpand’ ‘andYpand’ ‘andZp
‘MsgBox(Message)
‘ Set new coordinates
Object.SetPoint PointP, Xp, Yp, Zp
‘ Finally write a Script operation layer to save the change
Object.WriteScriptOperationLayer
End IF
End IF
End If
End If
End Sub
[/pre]
Thanks in advance for clarifying a few points:
1) Is it possible to select the points in 2 steps instead of one: 3 selected points are used at the beginning of the script and then the user is asked to select the point to project? From the little I know of 3DC scripting, it doesn’t seem possible.
2) Is it possible to select points from different objects? As it is the script can only work on points of the same object.
3) I wanted to make a variation of the script replacing the plane making up the plane by a face. However, I don’t see a way of selecting a point and a face before the script execution. It could be done if the answer is yes to point 1.