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: 

Code(s) Needed - Constrain User Work Planes Between Components

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Cadderman
268 Views, 2 Replies

Code(s) Needed - Constrain User Work Planes Between Components

I have been using a code recently that will constrain two items together by their origin planes and it works brilliantly, saving many clicks.  It has me wondering if it is possible to go a step further.  I would love to be able to use a code which constrains two parts together by a user work plane that I can pick myself.

 

The process I have in mind:

  1.  Run the script
  2. Box appears "Select First Part" ---> User picks the part 
  3. Box appears "Select User Work Plane" ---> User selects desired work plane from all available within the selected part
  4. Box appears "Select Second Part" ---> User picks the part
  5. Box appears "Select User Work Plane" ---> User selects desired work plane from all available within the selected part
  6. Both items are now constrained (Flush Constraint) together on the selected work planes

 

If the above is possible, I would also be looking to create a variant of the code that carries out steps 1-4 above but assumes the second part user work plane has an identical name to that found in part 1.  This is just to streamline it a little bit.

 

An example use case is some steelwork I have been working with.  I have Content Centre unequal-leg rolled steel angles in my model.  Due to their shape and the plane in which they are all flush I cannot use my existing code to constrain the origin planes.  I have to constrain all of the "End Plane" user work planes that come as standard in these items.  

 

So my question to the code experts in this forum is: "Is the above possible?"

 

Thanks in advance!

Labels (1)
2 REPLIES 2
Message 2 of 3

Use this:

Public Sub Main()
    Dim oAsmCompDef As AssemblyComponentDefinition
    oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

    Dim oOcc1 As ComponentOccurrence
    oOcc1 = ThisApplication.CommandManager.Pick(Inventor.SelectionFilterEnum.kAssemblyOccurrenceFilter,"Pick 1") 'oAsmCompDef.Occurrences.Item(1)

    Dim oOcc2 As ComponentOccurrence
    oOcc2 = ThisApplication.CommandManager.Pick(Inventor.SelectionFilterEnum.kAssemblyOccurrenceFilter,"Pick 2") 'oAsmCompDef.Occurrences.Item(2)

    Dim oPartPlane1 As WorkPlane
    oPartPlane1 = ThisApplication.CommandManager.Pick(Inventor.SelectionFilterEnum.kWorkPlaneFilter,"Pick Workplane 1")'oOcc1.Definition.WorkPlanes.Item(3)

    Dim oPartPlane2 As WorkPlane
    oPartPlane2 = ThisApplication.CommandManager.Pick(Inventor.SelectionFilterEnum.kWorkPlaneFilter,"Pick Workplane 2")'oOcc2.Definition.WorkPlanes.Item(3)

    Call oOcc1.CreateGeometryProxy(oPartPlane1, oAsmPlane1)

    Dim oAsmPlane2 As WorkPlaneProxy
    Call oOcc2.CreateGeometryProxy(oPartPlane2, oAsmPlane2)

    Call oAsmCompDef.Constraints.AddMateConstraint(oAsmPlane1, oAsmPlane2, 0)
End Sub

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
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: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 !

Message 3 of 3

Thank you so much @bradeneuropeArthur !!! That code is great. Much appreciated!

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

Post to forums  

Autodesk Design & Make Report