Create work point from axis and plane

Create work point from axis and plane

hieut1392
Enthusiast Enthusiast
602 Views
5 Replies
Message 1 of 6

Create work point from axis and plane

hieut1392
Enthusiast
Enthusiast

I want to create work point from intersection of axis and plane. Can you give me some hint?

 

hieut1392_0-1673286762838.png

 

Sub CreateWorkPoint()

Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.ActiveDocument

Dim oCompDef As ComponentDefinition
Set oCompDef = oPartDoc.ComponentDefinition

Dim face As Object
Set face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllPlanarEntities, "Select Face")
Dim axis As Object
Set axis = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllPlanarEntities, "Select Axis")

Call oCompDef.WorkPoints.Addby <---- I'm stuck here

End Sub

 

0 Likes
Accepted solutions (1)
603 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

Hi @hieut1392.  Here is something you can try out.  I just wrote this as a general iLogic rule, so I'm just using Sub Main, but you can change that if you need to.

 

Sub Main
	'pick face
	oObj = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Pick Flat Face.")
	If oObj Is Nothing OrElse (TypeOf oObj Is Face = False) Then Return
	Dim oFace As Face = oObj
	Dim oPlane As Plane = oFace.Geometry
	
	'pick work axis
	oObj = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kWorkAxisFilter, "Pick Work Axis.")
	If oObj Is Nothing OrElse (TypeOf oObj Is WorkAxis = False) Then Return
	Dim oAxis As WorkAxis = oObj
	
	Dim oPoint As Point = oPlane.IntersectWithLine(oAxis.Line)

	Dim oPDef As PartComponentDefinition = oFace.Parent.ComponentDefinition
	oPDef.WorkPoints.AddByPoint(oPoint)
End Sub

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

Michael.Navara
Advisor
Advisor
Accepted solution

The code mentioned by @WCrihfield doesn't work for me. Argument for method AddByPoint must be SketchPoint or Vertex.

Modified code below creates two types of WorkPoints. Fixed and constrained. See the comments.

Sub Main
	'pick face
	oObj = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Pick Flat Face.")
	If oObj Is Nothing OrElse (TypeOf oObj Is Face = False) Then Return
	Dim oFace As Face = oObj
	Dim oPlane As Plane = oFace.Geometry
	
	'pick work axis
	oObj = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kWorkAxisFilter, "Pick Work Axis.")
	If oObj Is Nothing OrElse (TypeOf oObj Is WorkAxis = False) Then Return
	Dim oAxis As WorkAxis = oObj
	
	Dim oPoint As Point = oPlane.IntersectWithLine(oAxis.Line)

	Dim oPDef As PartComponentDefinition = oFace.Parent.ComponentDefinition
	oPDef.WorkPoints.AddFixed(oPoint) 'Creates fixed workpoint
	oPDef.WorkPoints.AddByCurveAndEntity(oAxis, oFace) 'Creates WorkPoint constrained to workAxis and Face
End Sub

 

Message 4 of 6

WCrihfield
Mentor
Mentor

Good catch @Michael.Navara.  I must not have been paying close enough attention at the time.  It happens when thinking about too many things at the same time. 🤔😉

Edit:  I guess they need to update their documentation for the AddByCurveAndEntity method, to state that you can alse use a WorkAxis as input for the 'Curve' variable.  Documentation currently just says that it must be an Edge, or 2D sketch entity, or 3D sketch entity.  I did not think that a WorkAxis qualified as any of those.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 6

hieut1392
Enthusiast
Enthusiast

this code doesn't work for me too, but thank you any way.

0 Likes
Message 6 of 6

hieut1392
Enthusiast
Enthusiast

thank you.

0 Likes