I logic to Select vertex on part and create WorPoint

I logic to Select vertex on part and create WorPoint

neodd70
Enthusiast Enthusiast
1,994 Views
10 Replies
Message 1 of 11

I logic to Select vertex on part and create WorPoint

neodd70
Enthusiast
Enthusiast

I am trying to create either an iLogic Rule or a VBA Macro that when the Macro/Rule is run the user needs to select a vertex on the part and the iLogic code will take the X, Y and Z coordinates from that vertex selection and create a WorkPoint at that location. I am using the CommandManager.Pick to have the user select the vertex but when I try to add a WorkPoint using the Measure.MinimumDistance I get an error that there is an Object required. I am not a programmer so I am trying to fumble my way thru to get this to work. Is there anyone that would be able to look at the code I have and tell me what I have done wrong. Any help would be greatly appreciated.

 

Sub Single_Bend_Door_Add_WorkPoints()

Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oDef As PartComponentDefinition
Set oDef = oDoc.ComponentDefinition

Dim oPoint As Vertex
Set oPoint = ThisApplication.CommandManager.Pick(kPartVertexFilter, "Right Side")
Dim wp1 As WorkPoint
Set wp1 = oDef.WorkPoints.AddByPoint(Measure.MinimumDistance(oPoint.Point.X, oPoint.Point.Y, oPoint.Point.Z))


End Sub
0 Likes
Accepted solutions (2)
1,995 Views
10 Replies
Replies (10)
Message 2 of 11

JhoelForshav
Mentor
Mentor
Accepted solution

try this as an iLogic rule

SyntaxEditor Code Snippet

Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument

Dim oDef As PartComponentDefinition
oDef = oDoc.ComponentDefinition

Dim oPoint = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartVertexFilter, "Right Side")
oDef.WorkPoints.AddByPoint(oPoint)

 Hope it helps 🙂

Message 3 of 11

bradeneuropeArthur
Mentor
Mentor
Accepted solution

Change to code a little:

Sub Single_Bend_Door_Add_WorkPoints()

Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oDef As PartComponentDefinition
Set oDef = oDoc.ComponentDefinition

Dim oPoint As Vertex
Set oPoint = ThisApplication.CommandManager.Pick(kPartVertexFilter, "Right Side")
Dim wp1 As WorkPoint
Set wp1 = oDef.WorkPoints.AddByPoint(oPoint)


End Sub

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 4 of 11

neodd70
Enthusiast
Enthusiast

 jhoel.forshav & bradeneurope

Both of those work exactly as I was wanting them too. Thank you very much. Now to figure out how to change the name of the new WorkPoint.

0 Likes
Message 5 of 11

neodd70
Enthusiast
Enthusiast

I figured out out how to rename my WorkPoints but another issue I am trying to work thru is how to differentiate between a Vertex of a solid and the point of a sketch. I can Change the kAllPartVertexFilter to kAllPointEntities so that I can now select the point of a sketch but that disables the ability to select a Vertex.  How would I be able to select either a sketch point or a Vertex.

0 Likes
Message 6 of 11

bradeneuropeArthur
Mentor
Mentor
I will take a look

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 7 of 11

neodd70
Enthusiast
Enthusiast

I was able to get what I needed from the code you helped with. I have a similar situation where I need to have the user select 4 points on a door, Upper and Lower, Left and Right Vertices but this time it's in an assembly I tried my hand at code once more but I've hit a stumbling block with the Object problem again.  Here is the code I have so Far. This Time it's in ilogic. If there is a way of doing this without having to add the workpoints that would be great. Basically I just need to dimension from the YZ Plane to the bottom right and left points and from the top right and left points of the door to retrieve their dimension in the X axis so I can plug those numbers into a parameter that sets the length from midpoint in each direction of a secondary part. Any Help would be appreciated.

Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oAsmDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition

oPoint = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllEntitiesFilter, "Please Select the Front Lower Left Vertex of the Door")
Dim wp1 As WorkPoint = oAsmDef.WorkPoints.AddByPoint(oPoint)
wp1.Name = "wpt1"
oPoint = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllEntitiesFilter, "Please Select the Front Lower Right Vertex of the Door")
Dim wp2 As WorkPoint = oAsmDef.WorkPoints.AddByPoint(oPoint)
wp2.Name = "wpt1"
oPoint = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllEntitiesFilter, "Please Select the Upper Left Vertex of the Door")
Dim wp3 As WorkPoint = oAsmDef.WorkPoints.AddByPoint(oPoint)
wp3.Name = "wpt1"
oPoint = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllEntitiesFilter, "Please Select the Upper Right Vertex of the Door")
Dim wp4 As WorkPoint = oAsmDef.WorkPoints.AddByPoint(oPoint)
wp4.Name = "wpt1"

LowerTrainLeftDim = Measure.MinimumDistance("wpt1", "YZ Plane")
LowerTrainRightDim = Measure.MinimumDistance("wpt2", "YZ Plane")
UpperTrainLeftDim = Measure.MinimumDistance("wpt3", "YZ Plane")
UpperTrainRightDim = Measure.MinimumDistance("wpt4", "YZ Plane")

 

0 Likes
Message 8 of 11

neodd70
Enthusiast
Enthusiast

So I realized that the object I was missing was to Dim my oPoint as a Vertex but now when I run my code I get an error that it just failed without any explanation of what failed. Would somebody be able to tell me what I am doing wrong here. I have searched the forums and the only thing I was able to find was setting a Fixed WorkPoint with typed in coordinates but nothing on picking a vertex of a part in an Assembly as where I want to place the WorkPoint.  Here is the Code I have.

Sub Door_Corners()

Dim oAsmDoc As AssemblyDocument
Set oAsmDoc = ThisApplication.ActiveDocument
Dim oAsmDef As AssemblyComponentDefinition
Set oAsmDef = oAsmDoc.ComponentDefinition

Dim oPoint As Vertex
Set oPoint = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartVertexFilter, "Please Select the Front Lower Left Vertex of the Door")
Dim wp1 As WorkPoint
Set wp1 = oAsmDef.WorkPoints.AddByPoint(oPoint)

End Sub

 

0 Likes
Message 9 of 11

Anonymous
Not applicable

HI,

I try to use your program in my part, it shows error as in attached image.

I have a sketch which contains the projected cuts edges, From that I need to find points & then I have to create a sketch in it.

 

 

 

0 Likes
Message 10 of 11

neodd70
Enthusiast
Enthusiast

@Anonymous When running a rule from the iLogic IDE you need to have a Main Sub and then call your other Sub from within the Main or just put your code in the Main Sub. Also the "Set" command is an invalid command in the iLogic IDE so those just need to be removed. Try this

Sub Main()
	Door_Corners()
End Sub

Sub Door_Corners()

Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument

Dim oDef As PartComponentDefinition
oDef = oDoc.ComponentDefinition

Dim oPoint As Vertex
oPoint = ThisApplication.CommandManager.Pick(kPartVertexFilter, "Right Side")

Dim wp1 As WorkPoint
wp1 = oDef.WorkPoints.AddByPoint(oPoint)

End Sub
0 Likes
Message 11 of 11

Anonymous
Not applicable

@neodd70 ,

I need to extract points (Line intersection) from the projected sketch. Pls see the attached image, In that image I have marked an area in red.

I need a program to create a closed sketch as I shown or just to identify the points to create a sketch.

 

BR,

Arun Rajasekaran

0 Likes