Adding linear drawing dimension to an assembly via API - Face Proxies fail

Adding linear drawing dimension to an assembly via API - Face Proxies fail

jonas.hoffmeisterFYFHQ
Enthusiast Enthusiast
346 Views
3 Replies
Message 1 of 4

Adding linear drawing dimension to an assembly via API - Face Proxies fail

jonas.hoffmeisterFYFHQ
Enthusiast
Enthusiast

Hi everyone, 

 

I am trying to add dimensions to an assembly. The relevant faces within the parts are named. I manage to get the components but I cannot get the drawing curves. Here is my code:

 

' Adding Dimensions

Dim oAssembly As AssemblyDocument
oAssembly = oSideView.ReferencedDocumentDescriptor.ReferencedDocument

Dim oModelDoc As Document
Dim Face1 As Face
Dim Face2 As Face

For i = 1 To oAssembly.ReferencedDocuments.Count

	oModelDoc = oAssembly.ReferencedDocuments(i)
	
	If oModelDoc.AttributeManager.FindObjects("*", "*", "Nutenseite1").Count > 0 Then
	
		Face1 = oModelDoc.AttributeManager.FindObjects("*", "*", "Nutenseite1").Item(1)
		
		MessageBox.Show("Found: " & Face1.InternalName()) ' this works! Named Object found!
	
	End If
	
	If oModelDoc.AttributeManager.FindObjects("*", "*", "Nutenseite2").Count > 0 Then
	
		Face2 = oModelDoc.AttributeManager.FindObjects("*", "*", "Nutenseite2").Item(1)
	
	End If
	
Next

Dim oOccFace1Proxy As FaceProxy
Dim oOccFace2Proxy As FaceProxy

Dim oCompOcc As ComponentOccurrence
oCompOcc = oAssembly.ComponentDefinition.Occurrences.ItemByName("Einlaufpfostenprofil")
MessageBox.Show("Selected Component: " & oCompOcc.Name()) 'Works!

Call oCompOcc.CreateGeometryProxy(Face1, oOccFace1Proxy) 'no error msg here. Programm does not fail
Call oCompOcc.CreateGeometryProxy(Face2, oOccFace2Proxy) 'no error msg here. Programm does not fail

Dim myCurveCandidates As DrawingCurvesEnumerator = oSideView.DrawingCurves(oOccFace1Proxy) 
MessageBox.Show(oSideView.DrawingCurves(oOccFace1Proxy).Count) 'gives me a zero
Dim myDrawingCurve As DrawingCurve = myCurveCandidates.Item(1) 'fails
Dim face1GeoIntent As GeometryIntent = oSheet.CreateGeometryIntent(myDrawingCurve)

myCurveCandidates = oTopView.DrawingCurves(oOccFace2Proxy)
myDrawingCurve = myCurveCandidates.Item(1)
Dim face2GeoIntent As GeometryIntent = oSheet.CreateGeometryIntent(myDrawingCurve)

Dim widthDimPoint As Point2d = oTG.CreatePoint2d(15, 10)

oSheet.DrawingDimensions.GeneralDimensions.AddLinear(widthDimPoint,face1GeoIntent,face2GeoIntent)

 

0 Likes
Accepted solutions (2)
347 Views
3 Replies
Replies (3)
Message 2 of 4

Michael.Navara
Advisor
Advisor
Accepted solution

It can be. Because your face proxy may be hidden by another one. Following code produces two zero results for first occurrence and non-zero result for second one in sample drawing.

 

 

 

Sub Main()

    Dim drawing As DrawingDocument = ThisDoc.Document
    Dim drawingView As DrawingView = drawing.ActiveSheet.DrawingViews(1)
    Dim asm As AssemblyDocument = drawingView.ReferencedDocumentDescriptor.ReferencedDocument
    For Each occ As ComponentOccurrence In asm.ComponentDefinition.Occurrences
        Logger.Debug(occ.Name)
        Dim occPartDef As PartComponentDefinition = occ.Definition
        Dim faces As Faces = occPartDef.SurfaceBodies(1).Faces
        For Each face As Face In faces
            If face.SurfaceType = SurfaceTypeEnum.kPlaneSurface Then
                Dim faceProxy As FaceProxy = Nothing
                occ.CreateGeometryProxy(face, faceProxy)

                Dim faceCurves As DrawingCurvesEnumerator = drawingView.DrawingCurves(faceProxy)
                Logger.Debug(faceCurves.Count)
            End If
        Next
    Next
End Sub

 

 

 

Sorry, I have some issue with sample dataset uploading... 😕

Just screenshot at this time 

MichaelNavara_0-1673282617507.png

 

0 Likes
Message 3 of 4

Michael.Navara
Advisor
Advisor
Accepted solution

Today upload works 🙂

In attachment is a sample assembly with code snippet.

0 Likes
Message 4 of 4

jonas.hoffmeisterFYFHQ
Enthusiast
Enthusiast

Thanks!

 

Omg, I wasn´t aware that hidden objects (via flush or similar) can cause troubles like this. Now that I spent the play around with your code and mine I got this sorted!

 

My code changed quite a bit. Final version below.

 

Thanks again for the sample file. Awesome help! 

 

' Adding Dimensions
Dim oCompOcc1, oCompOcc2 As ComponentOccurrence
Dim oPartDoc1, oPartDoc2 As PartDocument
Dim oEdge1, oEdge2 As Edge
Dim oFace1, oFace2 As Face
Dim oEdge1Proxy, oEdge2Proxy As EdgeProxy
Dim oFace1Proxy, oFace2Proxy As FaceProxy
Dim myCurveCandidates As DrawingCurvesEnumerator
Dim myDrawingCurve As DrawingCurve
Dim oGeoIntent1, oGeoIntent2 As GeometryIntent
Dim myNamedEntities As NamedEntities 
Dim myPos2d As Point2d

' MyPart
oCompOcc1 = oAssDoc.ComponentDefinition.Occurrences.ItemByName("MyPart")
Logger.Debug("Selected Component: " & oCompOcc1.Name())
oPartDoc = oCompOcc1.Definition.Document
myNamedEntities = iLogicVb.Automation.GetNamedEntities(oPartDoc)
oFace1 = myNamedEntities.FindEntity("Nutenseite3")
oFace2 = myNamedEntities.FindEntity("Nutenseite4")

Call oCompOcc1.CreateGeometryProxy(oFace1, oFace1Proxy)
Call oCompOcc1.CreateGeometryProxy(oFace2, oFace2Proxy)

myCurveCandidates = oSideView.DrawingCurves(oFace1Proxy) 
Logger.Debug("Curves Count: " & myCurveCandidates.Count)
myDrawingCurve = myCurveCandidates.Item(1) 
oGeoIntent1 = oSheet.CreateGeometryIntent(myDrawingCurve)

myCurveCandidates = oSideView.DrawingCurves(oFace2Proxy)
Logger.Debug("Curves Count: " & myCurveCandidates.Count)
myDrawingCurve = myCurveCandidates.Item(1)
oGeoIntent2 = oSheet.CreateGeometryIntent(myDrawingCurve)

myPos2d = oTG.CreatePoint2d(oSideView.Left + oSideView.Width + 1, oSideView.Top - oSideView.Height - 1) 

oSheet.DrawingDimensions.GeneralDimensions.AddLinear(myPos2d,oGeoIntent1,oGeoIntent2)

0 Likes