AutoDesk VBA

AutoDesk VBA

Anonymous
Not applicable
312 Views
1 Reply
Message 1 of 2

AutoDesk VBA

Anonymous
Not applicable

Hi everyone !

I need a solution to measure the diameter of a pipe in an assembly when I select it.

I use currently this code:

 

Dim K As Integer
    Dim CompenentOccurrence As ComponentOccurrence
    For K = 1 To ThisApplication.ActiveDocument.SelectSet.Count
    Set ComponentOccurrence = ThisApplication.ActiveDocument.SelectSet.Item(K)
    Dim Interpoint As Point2d
    TextBox1.Value = ComponentOccurrence.Name & " " & " Diameter : " & Round((((4 * Face.Evaluator.Area) / (3.14)) ^ 0.5) * 10, 0) & "mm"

 

But It calculate the area of the all surface of the pipe.

I would like to have automatically the diameter of the pipe, when I select it !

Could you help me ?

Kevin

 

 

0 Likes
313 Views
1 Reply
Reply (1)
Message 2 of 2

tdant
Collaborator
Collaborator

This should do the trick:

Sub GetPipeOD()
    Dim cylFace As Face
    Set cylFace = ThisApplication.CommandManager.Pick(kPartFaceCylindricalFilter, "Click a pipe face to display OD")
    
    On Error Resume Next
    MsgBox ("OD is " & Round(cylFace.Geometry.Radius * 20, 1) & " mm")
End Sub
0 Likes