Message 1 of 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all, Having a little trouble working through this issue. I am trying to retrieve a drawing curve from a part inside a sub assembly. The code below works find when the part is inside an assembly but not if it is deeper inside a sub assembly. Any idea what the issue could be? Is it proxy related? for context the part is an ipart member so the ipart factory needs to be read to find the face in the member.
Errors out here.
Sub Main
Dim drawDoc As DrawingDocument = ThisDoc.Document
For Each drawSheet As Sheet In drawDoc.Sheets
For Each drawView As DrawingView In drawSheet.DrawingViews
Dim viewDoc As Document = drawView.ReferencedDocumentDescriptor.ReferencedDocument
' Get the assembly document for the view.
If viewDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
Dim asmDoc As AssemblyDocument = viewDoc
Dim occ As ComponentOccurrence
For Each oDoc In asmDoc.AllReferencedDocuments
Dim RefOccs As ComponentOccurrencesEnumerator = asmDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(oDoc)
If RefOccs.Count = 0 Then Continue For
occ = RefOccs(1)
'For Each occ As ComponentOccurrence In asmDoc.ComponentDefinition.Occurrences
If Not occ.Name.Contains("Part1") Then Continue For
MessageBox.Show(occ.Name, "Title")
' Get curve, location of each dimension leg start point.
Dim curve1 As DrawingCurve = GetCurve("Part1_Left", occ, drawView)
Dim curve2 As DrawingCurve = GetCurve("Part1_Right", occ, drawView)
Dim tg As TransientGeometry = ThisApplication.TransientGeometry
Dim pt1 As Point2d = tg.CreatePoint2d(curve1.StartPoint.X + 2, curve1.StartPoint.Y)
Dim genDims As GeneralDimensions = drawSheet.DrawingDimensions.GeneralDimensions
Dim dim1 As LinearGeneralDimension = genDims.AddLinear(pt1, drawSheet.CreateGeometryIntent(curve1), drawSheet.CreateGeometryIntent(curve2))
dim1.CenterText
Next
Else
MessageBox.Show("Is a part view Skiping", "Title")
Continue For
End If
Next
Next
End Sub
' Work through either part or ipart looking for named faces then the curves.
Function GetCurve(faceName As String, occ As ComponentOccurrence, drawView As DrawingView) As DrawingCurve
'https://modthemachine.typepad.com/my_weblog/2020/09/get-named-face-of-ipartfactory.html
Dim doc As PartDocument = occ.Definition.Document
Dim drawViewCurves As DrawingCurvesEnumerator
Dim drawCurve As DrawingCurve
Dim partFace As Face
Dim partFaceProxy As FaceProxy
Dim namedEntities As NamedEntities
If doc.ComponentDefinition.IsiPartMember Then
Dim factoryDoc As PartDocument = doc.ComponentDefinition.iPartMember.ReferencedDocumentDescriptor.ReferencedDocument
namedEntities = iLogicVb.Automation.GetNamedEntities(factoryDoc)
partFace = namedEntities.FindEntity(faceName)
For Each f2 As Face In doc.ComponentDefinition.SurfaceBodies(1).Faces
If f2.ReferencedEntity Is partFace Then
' Get the face into the context of the assembly
occ.CreateGeometryProxy(f2, partFaceProxy)
' Finds the drawing edge that represents the one with the named entity.
Try
drawViewCurves = drawView.DrawingCurves(partFaceProxy)
Catch
Logger.Info("Error getting DrawViewCurves")
End Try
Try
drawCurve = drawViewCurves.Item(1)
Catch
Logger.Info("Error getting DrawViewCurve")
End Try
Return drawCurve
Exit Function
End If
Next
Else
namedEntities = iLogicVb.Automation.GetNamedEntities(doc)
partFace = namedEntities.FindEntity(faceName)
' Get the face into the context of the assembly.
occ.CreateGeometryProxy(partFace, partFaceProxy)
drawViewCurves = drawView.DrawingCurves(partFaceProxy)
drawCurve = drawViewCurves.Item(1)
Return drawCurve
End If
End Function
If this solved a problem, please click (accept) as solution.
Or if this helped you, please, click (like)
Regards
Alan
Or if this helped you, please, click (like)
Regards
Alan
Solved! Go to Solution.