Hi,
I am a new user of Solidworks and the API and have run into a few problems.
In particular, I am trying to draw a wire by sweeping a circle along a 3D
path. However, CreateCircleByRadius seems to fail if the radius is too
small. ie: The Visual Basic code below fails to draw the circle. However, if I change
the radius from 0.000709825 to 0.001709825 it works fine.
Does anyone know if this is a bug or if there are some options that I need
to set to allow smaller dimensions to work?
On a different note, when this macro is saved to a file (ie: test.swb) it works
fine if I run it, by selecting "Run Macro" from the Macro toolbar.
However, if I select "Edit Macro" and then try to run it from the Macro editor
I get the message "Compile error: Variable not defined" for the reference to
SwConst.swUserPreferenceIntegerValue_e.swUnitSystem.
Am I doing something wrong?
Many thanks in advance for any help!
Here is the code that I am using:
Option Explicit
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
Dim skSegment As Object
Dim myRefPlane As Object
Dim myFeature As Object
' Set units to meters
boolstatus = Part.Extension.SetUserPreferenceInteger(SwConst.swUserPreferenceIntegerValue_e.swUnitSystem, 0, SwConst.swUnitSystem_e.swUnitSystem_MKS)
' Draw a 3D line to serve as a path for the wire
Part.SketchManager.Insert3DSketch True
Set skSegment = Part.SketchManager.CreateLine(0.0290811, 0, 0, 0.0290811, 0, 0.0311709)
Part.ClearSelection2 True
' Draw a reference plane perpendicular and at the first point of the path
Part.SketchManager.InsertSketch True
boolstatus = Part.Extension.SelectByID2("Line1@3DSketch1", "EXTSKETCHSEGMENT",0.0290811, 0, 0, True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Point1@3DSketch1", "EXTSKETCHPOINT",0.0290811, 0, 0, True, 1, Nothing, 0)
Set myRefPlane = Part.FeatureManager.InsertRefPlane(514, 0, 4, 0, 0, 0)
Part.ClearSelection2 True
'Draw a circle on the reference plane at the start of the path
Part.SketchManager.InsertSketch True
boolstatus = Part.Extension.SelectByID2("Plane1", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
Set skSegment = Part.SketchManager.CreateCircleByRadius(0, 0, 0#, 0.000709825)
Part.ClearSelection2 True
'Sweep the circle along the path
Part.SketchManager.InsertSketch True
boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, False, 1, Nothing, 0)
boolstatus = Part.Extension.SelectByID2 ("3DSketch1", "SKETCH",0.0290811, 0, 0, True, 4, Nothing, 0)
Set myFeature = Part.FeatureManager.InsertProtrusionSwept3(False, False, 0, False, False, 0, 0, False, 0, 0, 0, 0, True, True, True, 0, True)
'Fit the part into the view
Part.ViewZoomtofit2
End Sub