Hello, I am looking to make a flow sheet automatically from solidwokrs. So I started by retrieving the information of thickness, depth, length, cutting angle...
I just came across a thin extrusion, which is defined by referring to surfaces in an assembly. So there is no written call number in the play. Is there a way to recover this depth?
I also had another case where the fillet of a tube is created directly from the extrusion related sketch. So when I display the dimensions, I am not able to differentiate between the fillet dimension and the thickness dimension.
Here's my code
Sub GetExtrusionDimensions()
//Initialize SolidWorks application and get the active document
Dim swApp As SldWorks.SldWorks
Dim Part As ModelDoc2
Dim Feature As Feature
Dim ExtrudeFeat As ExtrudeFeatureData
Dim DisplayDim As DisplayDimension
Dim DimVal As Dimension
Dim MsgStr As String
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
// Check if the active document is a part file
If Part Is Nothing Or Part.GetType <> swDocPART Then
MsgBox "Veuillez ouvrir une pièce avant d'exécuter ce script.", vbCritical
Exit Sub
End If
//Start with the first feature in the part
Set Feature = Part.FirstFeature
MsgStr = "Dimensions des extrusions :" & vbNewLine & vbNewLine
//Loop through each feature in the feature tree
Do While Not Feature Is Nothing
//Check if the feature is an extrusion
If Feature.GetTypeName2 = "Extrusion" Then
//Access extrusion-specific data
Set ExtrudeFeat = Feature.GetDefinition
If Not ExtrudeFeat Is Nothing Then
MsgStr = MsgStr & "Fonction : " & Feature.Name & vbNewLine
//Access display dimensions
Set DisplayDim = Feature.GetFirstDisplayDimension
Do While Not DisplayDim Is Nothing
//Get the linked dimension object
Set DimVal = DisplayDim.GetDimension
Depth = ExtrudeFeat.GetDepth(True)
Debug.Print Depth
If Not DimVal Is Nothing Then
MsgStr = MsgStr & " Dimension : " & DimVal.FullName & " = " & DimVal.Value & " mm" & vbNewLine
End If
//Move to the next display dimension
Set DisplayDim = Feature.GetNextDisplayDimension(DisplayDim)
Loop
MsgStr = MsgStr & vbNewLine
End If
End If
//Move to the next feature in the tree
Set Feature = Feature.GetNextFeature
Loop
//Display the extracted information
MsgBox MsgStr, vbInformation, "Résultats"
End Sub