I would like to get the lengths (and ideally mass properties if possible) of mutiple parts (that are pipes) in an assembly, and then export them to excel. The current macro that I'm trying to alter gets the length of the sketch that is currently selected and exports it to excel. Is there a way to get the length and mass properties for all of the parts in an assembly by creating a loop or something instead of just what's currently selected?
Code I have so far:
SolidworksApi macrosOption Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFeat As SldWorks.Feature
Dim swSketch As SldWorks.Sketch
Public xlApp As Excel.Application
Public xlWorkBooks As Excel.Workbooks
Public xlBook As Excel.Workbook
Public xlsheet As Excel.Worksheet
Public OutputPath As String
Public OutputFN As String
Public xlCurRow As Integer
Sub main()
Set xlApp = Excel.Application
xlApp.Visible = True
Set xlWorkBooks = Excel.Workbooks
Set xlBook = xlWorkBooks.Add()
Set xlsheet = xlBook.Worksheets("Sheet1")
xlsheet.Range("A1").Value = "Path Name"
xlsheet.Range("B1").Value = "Length (in)"
xlsheet.Range("A2").Value = ""
xlsheet.Range("B2").Value = SketchLength()
End Sub
Function SketchLength() As String
Dim i As Long
Dim bRet As Boolean
Dim vSketchSeg As Variant
Dim swSketchSeg As SldWorks.SketchSegment
Dim nLength As Double
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swFeat = swSelMgr.GetSelectedObject6(1, -1)
Set swSketch = swFeat.GetSpecificFeature2
vSketchSeg = swSketch.GetSketchSegments
For i = 0 To UBound(vSketchSeg)
Set swSketchSeg = vSketchSeg(i)
' Ignore construction lines
If swSketchSeg.ConstructionGeometry = False Then
' ignore text
If swSketchTEXT <> swSketchSeg.GetType Then
nLength = nLength + swSketchSeg.GetLength
End If
End If
Next i
SketchLength = nLength * 39.3701
End Function