Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Insert constraint with different option using vba

1 REPLY 1
Reply
Message 1 of 2
k14348
449 Views, 1 Reply

Insert constraint with different option using vba

i wrote the concept below. Could u help me to rectify errors in this program...

'

Sub InsertConstraint()

Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oSelect As SelectTypeEnum
oSelect = Inventor.SelectionPriorityEnum.kEdgeSelectionPriority

'In this 10 sec i will select two round edges in an assembly

Application.Wait (Now + TimeValue("0:00:10"))

Dim oAsmCompDef As AssemblyComponentDefinition
Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

' Set a reference to the select set.
Dim oSelectSet As SelectSet
Set oSelectSet = ThisApplication.ActiveDocument.SelectSet

' Get the two edges from the select set.
Dim oEdge1 As Edge
Dim oEdge2 As Edge
Set oEdge1 = oSelectSet.Item(1)
Set oEdge2 = oSelectSet.Item(2)

' Create the insert constraint between the parts.
Dim oInsert As InsertConstraint
Set oInsert = oAsmCompDef.Constraints.AddInsertConstraint(oEdge1, oEdge2, True, 0)

oSelect = Inventor.SelectionPriorityEnum.kComponentSelectionPriority

End Sub

1 REPLY 1
Message 2 of 2
YuhanZhang
in reply to: k14348

Try below code:

 

Sub InsertConstraintSample()

Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oAsmCompDef As AssemblyComponentDefinition
Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

' Get the two edges from the select set.
Dim oEdge1 As Edge
Dim oEdge2 As Edge
Set oEdge1 = ThisApplication.CommandManager.Pick(kPartEdgeCircularFilter, "Select a circular edge in a component")
Set oEdge2 = ThisApplication.CommandManager.Pick(kPartEdgeCircularFilter, "Select a circular edge in another component")

' Create the insert constraint between the parts.
Dim oInsert As InsertConstraint
Set oInsert = oAsmCompDef.Constraints.AddInsertConstraint(oEdge1, oEdge2, True, 0)

End Sub


If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report