Go
New
Find
Notify
Tools
Reply
  
-star Rating Rate It!  Login/Join 
Member
Picture of DOM107
Posted
This script moves a point in the same plane made by 3 points.
Language = VBScript

'*********************************************************************************
' Purpose: Move a point on the same plane as 3 selected points
'*********************************************************************************

Option Explicit          'require variable declarations

Sub Main (CanvasApp)

    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 = CanvasApp.GetActiveScene
        
    'Count number of selected points
    ActiveObjectsCount = Scene.GetActiveObjectCount
    ActivePointsCount = Scene.GetActivePointCount

    'only proceed if there are 4 active points
    If ActivePointsCount <> 4 AND ActiveObjectsCount <> 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=GeneralMessage&" (Plane points 1 and 2 are identical)"
		MsgBox(Message)
		Else
			If X1=X3 AND Y1=Y3 AND Z1=Z3 Then
			Message=GeneralMessage&" (Plane points 1 and 3 are identical)"
			MsgBox(Message)
			Else
				If X2=X3 AND Y2=Y3 AND Z2=Z3 Then
				Message=GeneralMessage&" (Plane points 2 and 3 are identical)"
				MsgBox(Message)
				Else
					Message="Plane points: "&X1&" "&Y1&" "&Z1&" // "&X2&" "&Y2&" "&Z2&" // "&X3&" "&Y3&" "&Z3
					Message=Message&" Point to be projected "&Xa&" "&Ya&" "&Za
					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="&Ap&" B="&Bp&" C="&Cp&" D="&Dp&" PointDistance="&PointDistance&" Projection="&Xp&" "&Yp&" "&Zp
					'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


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.
 
Posts: 489 | Registered: Sat September 04 2004Reply With QuoteEdit or Delete MessageReport This Post
Member
Picture of Amabilis Support
Posted Hide Post
Unfortunately, "no" is the answer to all three questions.

The goal is to move the point along a selected plane? A very handy feature. 3D Canvas has a function for moving a point along an edge, but not a plane. Well... I believe I originally intended it to move a point along a plane. It doesn't seem to do that unfortunately. I'll fix it. Just give me time. Smile

To move a point along an edge hold down the E and Z keys, click on a point and drag (left right). It only really works on a point along a divided edge (a point shared by only two faces).

I really should improve this since it is really handy. It's on my list.
 
Posts: 1412 | Registered: Thu November 06 2003Reply With QuoteEdit or Delete MessageReport This Post
Member
Picture of DOM107
Posted Hide Post
quote:
Originally posted by Amabilis Support:
To move a point along an edge hold down the E and Z keys, click on a point and drag (left right).

Thanks for the reply.

I didn't know this feature.
This is really useful : when dividing an edge, the points are evenly distributed along the edge. With the E/Z trick, it is possible to have a point elsewhere (I would have used this function before if I knew it existed).

Whatever you have in mind about moving a point along a plane, don't change the E/Z trick.

Btw, my script is not about moving a point along a plane but projecting it on a plane.

This message has been edited. Last edited by: DOM107,
 
Posts: 489 | Registered: Sat September 04 2004Reply With QuoteEdit or Delete MessageReport This Post
 Previous Topic | Next Topic powered by eve community  
 


© Amabilis Software 2003-2007