I want A macro to split all components(“line”, “arc”, “spline” into small equal pieces How can I do that or what are the possoible steps ?
SolidworksApi/macros
I want A macro to split all components(“line”, “arc”, “spline” into small equal pieces How can I do that or what are the possoible steps ?
SolidworksApi/macros
You will have to loop through all of the sketch segments in the active sketch.
Get All Sketch Segments Example
And then perform a split on them
Split Open Segment Example
Split Closed Segments
If you are splitting in even numbers, you can find the midpoint and split on that.
Find midpoint example
If you are splitting into an odd number of segments, that's much more complicated.
Can you pause the macro before that step and check that the sketch segment is selected. I suspect Skseg is null.
please what is the wrong here,
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.SelectByID2("Line25", "SKETCHSEGMENT", 2.19283381473937E-02, 1.47739408040298E-02, 0, False, 0, Nothing, 0)
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Line463", "SKETCHSEGMENT", 2.19283381473937E-02, 1.47739408040298E-02, 0, False, 1, Nothing, 0)
Dim SkSeg As Object
Set SkSeg = Part.SelectionManager.GetSelectedObject6(1, -1)
boolstatus = SkSeg.EqualSegment(swSketchSegmentType_e.swSketchSegmentType_sketchsegments, 99)
Part.ClearSelection2 True
' Zoom In/Out (MouseWheel)
Dim swModelView As Object
Set swModelView = Part.ActiveView
swModelView.Scale2 = 2.39953409774147
Dim swTranslation() As Double
ReDim swTranslation(0 To 2) As Double
swTranslation(0) = -3.15654978469425E-02
swTranslation(1) = -9.47284797698912E-03
swTranslation(2) = 0
Dim swTranslationVar As Variant
swTranslationVar = swTranslation
Dim swMathUtils As Object
Set swMathUtils = swApp.GetMathUtility()
Dim swTranslationVector As MathVector
Set swTranslationVector = swMathUtils.CreateVector((swTranslationVar))
swModelView.Translation3 = swTranslationVector
' Zoom In/Out (MouseWheel)
Set swModelView = Part.ActiveView
swModelView.Scale2 = 10.65374227865
ReDim swTranslation(0 To 2) As Double
swTranslation(0) = -0.212255924595223
swTranslation(1) = -9.95160392056128E-02
swTranslation(2) = 0
swTranslationVar = swTranslation
Set swMathUtils = swApp.GetMathUtility()
Set swTranslationVector = swMathUtils.CreateVector((swTranslationVar))
swModelView.Translation3 = swTranslationVector
boolstatus = Part.Extension.SelectByID2("Point1206", "SKETCHPOINT", 2.20430549145133E-02, 9.42613268376792E-03, 0, False, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Point1208", "SKETCHPOINT", 2.20430549145133E-02, 8.71087383974125E-03, 0, True, 0, Nothing, 0)
Dim myDisplayDim As Object
Set myDisplayDim = Part.AddDimension2(2.39574048735256E-02, 8.68420481052571E-03, 0)
Part.ClearSelection2 True
Dim myDimension As Object
Set myDimension = Part.Parameter("D1@Sketch1")
myDimension.SystemValue = 0.0001
End Sub
Thanks,I have tried to make asegment then I put adimensions I want but the macro debug