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:
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!
Solved! Go to Solution.
Solved by bradeneuropeArthur. Go to Solution.
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 !
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.