Creating constraint between part and part in subassembly

Creating constraint between part and part in subassembly

bartlomiej.czarniakBNLBF
Explorer Explorer
222 Views
1 Reply
Message 1 of 2

Creating constraint between part and part in subassembly

bartlomiej.czarniakBNLBF
Explorer
Explorer

Hi,

I think I've got issue with understanding proxies of subcomponents and I can't figure it out by myself... I've got nice working SUB that constrains part with other part by faces within one assembly. However I can't write a sub that creates constrain in assembly using part with named entity and in part that is contained in another assembly that is put into main assembly. Do I need to create geometry proxy of component occurence? Snip of code that I've got below. It crashes on adding constraint. As addition, can I use directly faces from features? Or do I need to create another proxy to use it? Any help appreciated... Using VS2022 as IDE and creating standalone app.

Public Sub Constrain(invapp As Inventor.Application, strPart1 As String, strPart2 As String)
        Dim oAssyDoc As Inventor.AssemblyDocument
        oAssyDoc = invapp.ActiveDocument

        Dim oCompDef As Inventor.AssemblyComponentDefinition
        oCompDef = oAssyDoc.ComponentDefinition

        Dim o1Comp As Inventor.ComponentOccurrence
        Dim o2Comp As Inventor.ComponentOccurrence
        Dim oSubAssy As Inventor.AssemblyComponentDefinition

        o1Comp = oCompDef.Occurrences.ItemByName(strPart1)
        oSubAssy = oCompDef.Occurrences.ItemByName(strPart2).Definition
        o2Comp = oSubAssy.Occurrences.ItemByName("PIPE:1")

        Dim oPart1 As Inventor.PartDocument
        Dim oPart2 As Inventor.PartDocument

        oPart1 = o1Comp.Definition.Document
        oPart2 = o2Comp.Definition.Document

        Dim o1PartFace As Inventor.Face
        Dim o2PartFace As Inventor.Face

        Dim oFP1 As Inventor.FaceProxy
        Dim oFP2 As Inventor.FaceProxy


        ' o1PartFace = oPart1.ComponentDefinition.Features.ExtrudeFeatures.Item("CylinderExtrude").Faces.Item(1)
        ' o2PartFace = oPart2.ComponentDefinition.Features.ExtrudeFeatures.Item("CutOutForNozzleExtrude").Faces.Item(1)

        o1PartFace = oPart1.AttributeManager.FindObjects(,, "NAME1")(1)
        o2PartFace = oPart2.AttributeManager.FindObjects(,, "NAME2")(1)

        o1Comp.CreateGeometryProxy(o1PartFace, oFP1)
        o2Comp.CreateGeometryProxy(o2PartFace, oFP2)

        oCompDef.Constraints.AddMateConstraint(oFP1, oFP2, 0, InferredTypeEnum.kInferredLine, InferredTypeEnum.kInferredLine,,)

    End Sub

bartlomiejczarniakBNLBF_0-1663626454969.png

 

0 Likes
Accepted solutions (1)
223 Views
1 Reply
Reply (1)
Message 2 of 2

bartlomiej.czarniakBNLBF
Explorer
Explorer
Accepted solution

Ok, so I got solution that fix my thinking about proxies and how they should be used.

Way to handle it is to add SubAssembly as Component Occurence, and create proxy of proxy. So I create proxy of face of part in subassembly and then I create proxy of this proxy. Two additional lines that fix the issue.

 

oSubAssyOcc = oCompDef.Occurrences.ItemByName(strPart2)

oSubAssyOcc.CreateGeometryProxy(oFP2, oFP2)