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: 

Workpoints from assembly to part

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
nikita.kapustin
622 Views, 3 Replies

Workpoints from assembly to part

Hello,

Try to transfer all workpoints from assembly to part by code:

Dim assDoc As AssemblyDocument = InvApp.ActiveDocument
Dim assDocDef As AssemblyComponentDefinition = assDoc.ComponentDefinition

Dim oFace As FaceProxy = InvApp.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select part")

Dim oPartOcc As ComponentOccurrence = oFace.ContainingOccurrence
Dim oPartCompDef As PartComponentDefinition = oPartOcc.Definition

For Each wPoint As WorkPoint In assDocDef.WorkPoints
           Dim vecPoint As Vector = InvApp.TransientGeometry.CreateVector(wPoint.Point.X, wPoint.Point.Y, wPoint.Point.Z)
           Dim vecRel As Vector = InvApp.TransientGeometry.CreateVector(oPartOcc.Transformation.Translation.X, oPartOcc.Transformation.Translation.Y, oPartOcc.Transformation.Translation.Z)
           Dim vecSub As Vector = InvApp.TransientGeometry.CreateVector(vecPoint.X - vecRel.X, vecPoint.Y - vecRel.Y, vecPoint.Z - vecRel.Z)
           Dim partPoint As Inventor.Point = InvApp.TransientGeometry.CreatePoint
           partPoint.TranslateBy(vecSub)
           oPartCompDef.WorkPoints.AddFixed(partPoint)
Next

It works correct when assembly and part oriented in one direction. But when orientation is different, transfer of workpoints isn't correct. Can somebody help? Assembly in the attachment - incorrect transfer to "Part11".

3 REPLIES 3
Message 2 of 4

Or try a different approach, they are workpoints, so just include them.  Using the 'geometry proxy' system does all the geometric translation for you. 

 

Search for a post where I recently posted my latest version of GetSubOccurrenceProxyByName that is very fast (last week).

 

Example to get the drawing Inventor.Centermark from a model WorkPoint

Dim cmMaxTopSideView As Centermark = SetSubOccWorkPointVisibility(vBase, "LOAD:1", "MaxTop", True)

    Public Function SetSubOccWorkPointVisibility(ByRef v As DrawingView, ByRef subOccName As String, ByRef wpName As String, ByVal visibility As Boolean) As Centermark
        Try
            Dim doc As Inventor.Document = v.ReferencedDocumentDescriptor.ReferencedDocument
            Dim wp As WorkPoint = Nothing
            Dim cd As ComponentDefinition = Nothing
            If doc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
                cd = CType(doc, AssemblyDocument).ComponentDefinition
            ElseIf doc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
                cd = CType(doc, PartDocument).ComponentDefinition
            End If
            If cd IsNot Nothing Then
                Dim co As ComponentOccurrence = GetSubOccurrenceProxyByName(cd, subOccName)
                If co IsNot Nothing Then
                    wp = FindWorkPoint(co.Definition, wpName)
                    If wp IsNot Nothing Then
                        Dim wpp As WorkPointProxy = Nothing
                        co.CreateGeometryProxy(wp, wpp)
                        v.SetVisibility(wpp, True)
                        For Each cm As Centermark In v.Parent.Centermarks
                            If TypeOf cm.AttachedEntity Is WorkPoint Then
                                Dim wpEx As WorkPoint = cm.AttachedEntity
                                If wpEx.Name = wpp.Name Then
                                    Return cm
                                End If
                            End If
                        Next
                        'Return v.Parent.Centermarks(v.Parent.Centermarks.Count)
                    End If
                End If
            End If
        Catch ex As Exception
            Dim eh As New ErrorHandler(ex)
            eh.HandleIt()
        End Try
        Return Nothing
    End Function
    Public Function FindWorkPoint(ByRef cd As ComponentDefinition, ByVal wpName As String) As WorkPoint
        Dim wps As WorkPoints = Nothing
        If cd.Type = ObjectTypeEnum.kAssemblyComponentDefinitionObject Then
            Dim acd As AssemblyComponentDefinition = cd
            wps = acd.WorkPoints
        ElseIf cd.Type = ObjectTypeEnum.kPartComponentDefinitionObject Then
            Dim pcd As PartComponentDefinition = cd
            wps = pcd.WorkPoints
        End If
        If wps IsNot Nothing Then
            For Each wp As WorkPoint In wps
                If wp.Name = wpName Then Return wp
            Next
        End If
        Return Nothing
    End Function
jvj
Message 3 of 4

Thanks, but I can not understand how to use your code for transfer geometry from assembly to part, and i find more simple method. It based on using inverted matrix of part:

Dim assDoc As AssemblyDocument = InvApp.ActiveDocument
Dim assDocDef As AssemblyComponentDefinition = assDoc.ComponentDefinition

Dim oFace As FaceProxy = InvApp.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select part")

Dim oPartOcc As ComponentOccurrence = oFace.ContainingOccurrence
Dim oPartCompDef As PartComponentDefinition = oPartOcc.Definition
Dim subMat As Matrix = oPartOcc.Transformation
subMat.Invert()

For Each wPoint As WorkPoint In assDocDef.WorkPoints
         Dim partPoint As Inventor.Point = InvApp.TransientGeometry.CreatePoint
         partPoint.TransformBy(subMat)
         oPartCompDef.WorkPoints.AddFixed(partPoint)
Next
Message 4 of 4

I can see why, my routine created centermarks from workpoints in a drawing document, your routine creates workpoints from workpoints in a model document.  Sorry for the confusion, glad you figured it out.

jvj

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report