How to measure the length of a flange with API

How to measure the length of a flange with API

Anonymous
Not applicable
866 Views
7 Replies
Message 1 of 8

How to measure the length of a flange with API

Anonymous
Not applicable

How could I measure the length of a flange with the API.

 

I thought there would just be a simple FlangeDefinition.WidthExtent.Value 

 

My rule goes something like this (its in VBA but open to iLogic aswel), maybe I'm going about it the wrong way?

 

Sub Main()

' Get active document
Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.ActiveDocument

 

' Make sure the active document is a sheet metal document.
If oPartDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
MsgBox ("A sheet metal document must be open.")
Exit Sub
End If

 

' Get component definition of part
Dim oCompDef As SheetMetalComponentDefinition
Set oCompDef = oPartDoc.ComponentDefinition

 

' Get the referenced document feature collection
Dim oFlangesFeatures As PartFeatures
Set oFlangeFeatures = oCompDef.Features.FlangeFeatures

 

Dim oFlange As FlangeFeature

For Each oFlange In oFlangeFeatures

     Call oFlange.SetEndOfPart(True)

     Dim oDef As FlangeDefinition
     Set oDef = oFlange.Definition

     Dim oEdge As Edge
     For Each oEdge In oDef.Edges

          Dim oExtent As PartFeatureExtent
          Set oExtent = oDef.GetWidthExtent(oEdge)

          Dim oWidth As Double

          ' How do I get width !!! ?????

     Next

Next

 

End Sub

0 Likes
867 Views
7 Replies
Replies (7)
Message 2 of 8

perrysc
Enthusiast
Enthusiast

When you say "length", what exactly do you mean by that? Can you point it out on a test model?

0 Likes
Message 3 of 8

Anonymous
Not applicable

not the height... the length of the edge, which can also be determined by various width extent options (centred, offset, from-to etc)

0 Likes
Message 4 of 8

perrysc
Enthusiast
Enthusiast

 

Ah, I see. This should work, I believe.

 

Sub Main()

' Get active document
Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.ActiveDocument

' Make sure the active document is a sheet metal document.
If oPartDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
MsgBox ("A sheet metal document must be open.")
Exit Sub
End If

 

' Get component definition of part
Dim oCompDef As SheetMetalComponentDefinition
Set oCompDef = oPartDoc.ComponentDefinition

 

' Get the referenced document feature collection
Dim oFlangesFeatures As PartFeatures
Set oFlangeFeatures = oCompDef.Features.FlangeFeatures

 

Dim oFlange As FlangeFeature
Dim oEdge As Edge
Dim oEdgeStart() As Double
Dim oEdgeEnd() As Double
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oEdgeStartPoint As Point = oTG.CreatePoint(0,0,0)
Dim oEdgeEndPoint As Point = oTG.CreatePoint(0,0,0)
Dim oEdgeWidth As Double For Each oFlange In oFlangeFeatures
oEdge = oFlange.Definition.Edges.Item(1) 'Assumes this is a singled-edged flange.
oEdge.Evaluator.GetEndPoints(oEdgeStart(),oEdgeEnd()) 'Gets the two double arrays that contain the coordinates for the endpoints.
oEdgeStartPoint.PutPointData(oEdgeStart()) 'Sets a Point object at the relevant coordinates.
oEdgeEndPoint.PutPointData(oEdgeEnd()) 'Sets a Point object at the relevant coordinates
oEdgeWidth = oEdgeStartPoint.DistanceTo(oEdgeEndPoint) 'Gets the distance between the two Points Next End Sub

 

0 Likes
Message 5 of 8

Anonymous
Not applicable

@perrysc thanks for the attempt.

 

I got these error:

 

Error on Line 39 : Number of indices is less than the number of dimensions of the indexed array.
Error on Line 39 : Number of indices is less than the number of dimensions of the indexed array.
Error on Line 40 : Number of indices is less than the number of dimensions of the indexed array.
Error on Line 41 : Number of indices is less than the number of dimensions of the indexed array.

0 Likes
Message 6 of 8

perrysc
Enthusiast
Enthusiast

Wait, I'm an idiot. Try this now.

 

Sub Main()

' Get active document
Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.ActiveDocument

' Make sure the active document is a sheet metal document.
If oPartDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
MsgBox ("A sheet metal document must be open.")
Exit Sub
End If

 

' Get component definition of part
Dim oCompDef As SheetMetalComponentDefinition
Set oCompDef = oPartDoc.ComponentDefinition

 

' Get the referenced document feature collection
Dim oFlangesFeatures As PartFeatures
Set oFlangeFeatures = oCompDef.Features.FlangeFeatures

 

Dim oFlange As FlangeFeature
Dim oEdge As Edge
Dim oEdgeStart() As Double
Dim oEdgeEnd() As Double
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oEdgeStartPoint As Point = oTG.CreatePoint(0,0,0)
Dim oEdgeEndPoint As Point = oTG.CreatePoint(0,0,0)
Dim oEdgeWidth As Double

For Each oFlange In oFlangeFeatures

    oEdge = oFlange.Definition.Edges.Item(1) 'Assumes this is a singled-edged flange.
    oEdge.Evaluator.GetEndPoints(oEdgeStart,oEdgeEnd) 'Gets the two double arrays that contain the coordinates for the endpoints.
    oEdgeStartPoint.PutPointData(oEdgeStart) 'Sets a Point object at the relevant coordinates.
    oEdgeEndPoint.PutPointData(oEdgeEnd) 'Sets a Point object at the relevant coordinates
    oEdgeWidth = oEdgeStartPoint.DistanceTo(oEdgeEndPoint) 'Gets the distance between the two Points

Next

 

End Sub
0 Likes
Message 7 of 8

Anonymous
Not applicable

Hi @perrysc

 

I got this error:

Object reference not set to an instance of an object

 

Which was generated by this line:

oEdge = oFlange.Definition.Edges.Item(1)

 I figured out the issue though, no edges exist in the flange definition until you set the 'End of Folded' feature node before the flange using:

Call oFlange.SetEndOfPart(True)

 

That took care of the error as it now finds the flange edge, but then I received this error:

Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))

 

Which is generated by this line:

oEdge.Evaluator.GetEndPoints(oEdgeStart,oEdgeEnd)

 

I can't figure that one out Smiley Frustrated

0 Likes
Message 8 of 8

Anonymous
Not applicable

Got it! Had to initialize the values to an empty array, as below

 

Dim oEdgeStart() As Double = {}
Dim oEdgeEnd() As Double = {}

 Thanks for all your help!

0 Likes