Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

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: 

Placing part in context of main assembly

1 REPLY 1
SOLVED
Reply
Message 1 of 2
Anonymous
454 Views, 1 Reply

Placing part in context of main assembly

Hi.

 

I have a problem with placing component into assembly using API in VB.NET. Below you can see a sample hierarchy in my assembly file:qKXVp2A

 

There is a main assembly file (MainAssembly.iam), which has a component (SubAssembly:1), and this component has another component (sub-component Part:1) with construction plane called "PL1". Into main assembly I need to insert another component (PartToInsert:1) which has created construction plane "PL_Insert" in it. After inserting this component I want to add Mate Constraint using "PL1" plane and "PL_Insert" plane. So the path to these planes in context of my main assembly is:

MainAssembly.iam -> SubAssembly:1 -> Part:1 -> PL1

MainAssembly.iam -> PL_Insert

 

I have biggest problem with getting access to PL1 plane in context of main assembly because this plane is nested into another components. I've developed a solution which works but it is too simple:

 Private Sub btnTEST_Click(sender As Object, e As EventArgs) Handles btnTEST.Click

        ' insert part (PartToInsert:1)
        Dim partPath As String
        Dim partToInsert As ComponentOccurrence
        Dim positionMatrix As Matrix = GlobalVariables._invApp.TransientGeometry.CreateMatrix
        partPath = <path_to_PartToInsert.ipt>
        partToInsert = GlobalVariables.assemblyCurrentDef.Occurrences.Add(partPath, positionMatrix)
        Dim partToInsDef As PartComponentDefinition
        partToInsDef = partToInsert.Definition

        ' parent (SubAssembly:1)
        Dim subPartParent As ComponentOccurrence
        subPartParent = GlobalVariables.assemblyCurrentDef.Occurrences.ItemByName("SubAssembly:1")
        Dim subPartParentDef As AssemblyComponentDefinition
        subPartParentDef = subPartParent.Definition

        ' fixed part (Part:1)
        Dim subPart As ComponentOccurrence
        subPart = subPartParentDef.Occurrences.ItemByName("Part:1")
        Dim subPartDef As PartComponentDefinition
        subPartDef = subPart.Definition

        ' create workplanes and proxies
        Dim planeP As WorkPlane
        Dim planePProxy As WorkPlaneProxy
        planeP = partToInsDef.WorkPlanes.Item("PL_Insert")
        'partToInsert.CreateGeometryProxy(planeP, planePProxy)
        GlobalVariables.assemblyCurrentDef.Occurrences.Item(2).CreateGeometryProxy(planeP, planePProxy)

        Dim subPartPlane As WorkPlane
        subPartPlane = subPartDef.WorkPlanes.Item("PL1")
        Dim subPartPlaneProxy As WorkPlaneProxy
        'subPart.CreateGeometryProxy(subPartPlane, subPartPlaneProxy)
        GlobalVariables.assemblyCurrentDef.Occurrences.Item(1).SubOccurrences.Item(1).CreateGeometryProxy(subPartPlane, subPartPlaneProxy)

        ' add constraint
        Dim mateConstr As AssemblyConstraint
        mateConstr = GlobalVariables.assemblyCurrentDef.Constraints.AddMateConstraint(planePproxy, subPartPlaneproxy, 0)

    End Sub

 

    

In orange color  I want to emphasize code which I was need to comment because it didn't work. I was getting an exception error and the workaround is:

GlobalVariables.assemblyCurrentDef.Occurrences.Item(1).SubOccurrences.Item(1).CreateGeometryProxy(subPartPlane, subPartPlaneProxy)

 

It isn't a good solution for me because I must rely on the index in Item properties and if I had more than one component in my main assembly it will be hard for me to obtain which index is correct. It also do not provide a solution when there is more complicated sub-component, which has another sub component, because I strictly defined a connection to Item to which proxy is created.

 

Could you tell me how should I create proxies to plane in component Part:1 in context of main assembly in more convenient way? And why orange code is not working? It will help me a lot if I could create these proxies using ComponentOccurrence object directly, just like in the orange commented lines of code.

1 REPLY 1
Message 2 of 2
Anonymous
in reply to: Anonymous

I've found a solution for my problem. In this post there is everything we should know about placing parts in context of multi-level assembly:

http://adndevblog.typepad.com/manufacturing/2016/02/include-sketch-from-a-part-multi-level-deep.html

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

Post to forums  

Autodesk Design & Make Report