i'm trying to make 2/1 hanging pulley system rope design and made a 3d sketch for this
i want to make a macro to calculate total lenght of the sketch how can i done it
Look at Find Total Length of Sketch Segments in Sketch Example (VBA) in SOLIDWORKS API Help documentation
You can right click, select chain, and that will measure the length of all the segments.
Or if you create your pulleys as sketch blocks, you can insert a belt/chain that will calculate the length for you and update when you change a pulley size/location or the belt thickness. But I don't think I've ever tried to use sketch blocks in a 3D sketch??? If the problem is too complicated to make planar I would just use the first method.
i've 4 pulleys, 3 of these are same plane but one pulley is perpendicular to other 3 pulleys i try to record measure tool for macro but i cant managed it
Is there any program like this in C#?
Check this: Get the total length of segments in selected sketch using SOLIDWORKS API
Option ExplicitPublic Enum swSketchSegments_e swSketchLINE = 0 swSketchARC = 1 swSketchELLIPSE = 2 swSketchSPLINE = 3 swSketchTEXT = 4 swSketchPARABOLA = 5End EnumSub main() 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 Dim i As Long Dim bRet As Boolean Dim vSketchSeg As Variant Dim swSketchSeg As SldWorks.SketchSegment Dim nLength As Double
Set swApp = CreateObject("SldWorks.Application") Set swModel = swApp.ActiveDoc Set swSelMgr = swModel.SelectionManager Set swFeat = swSelMgr.GetSelectedObject5(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 Debug.Print "File = " & swModel.GetPathName Debug.Print " Sketch = " & swFeat.Name Debug.Print " Total length = " & nLength * 1000# & " mm"
i found this in api help but when i run didnt get any respond
This code assumes you have pre-selected a sketch in the FeatureManager.
yes i have to select the sketch before run the macro
how can i change that to auto select the same sketch
The results are output into VBA immediate window. Replace Debug.Print with MsgBox and results will be displayed in the popup message.
Retrieving data ...