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".
Solved! Go to Solution.
Solved by nikita.kapustin. Go to Solution.
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
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
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.
Can't find what you're looking for? Ask the community or share your knowledge.