AnsweredAssumed Answered

Error with digis decimal precision in macro solidworks

Question asked by Tuan Hoang on Jan 19, 2016
Latest reply on Jan 19, 2016 by Tuan Hoang

Hello, I'm new with vba in solidworks, I tried with the following code and it run well. Unfortunately, when I change the red number from 1 to 0.1 or 0.001 for example, it doesn't work anymore.

So, anyone can help me to treat thi problem ?

Thank you.

 

 

Dim swApp As Object

Dim Part As Object

Dim boolstatus As Boolean

 

Sub main()

Set swApp = _

Application.SldWorks

 

Set Part = swApp.ActiveDoc

boolstatus = Part.Extension.SelectByID2("Plan de face", "PLANE", 0, 0, 0, False, 0, Nothing, 0)

Part.ClearSelection2 True

Dim vSkLines As Variant

vSkLines = Part.SketchManager.CreateCornerRectangle(-20, -20, -20, 20, 20, 20)

Part.ShowNamedView2 "*Trimétrique", 8

Part.ClearSelection2 True

boolstatus = Part.Extension.SelectByID2("Line2", "SKETCHSEGMENT", 0, 0, 0, False, 0, Nothing, 0)

boolstatus = Part.Extension.SelectByID2("Line1", "SKETCHSEGMENT", 0, 0, 0, True, 0, Nothing, 0)

boolstatus = Part.Extension.SelectByID2("Line4", "SKETCHSEGMENT", 0, 0, 0, True, 0, Nothing, 0)

boolstatus = Part.Extension.SelectByID2("Line3", "SKETCHSEGMENT", 0, 0, 0, True, 0, Nothing, 0)

Dim myFeature As Object

Set myFeature = Part.FeatureManager.FeatureExtrusion2(False, False, False, 0, 0, 20, 20, False, False, False, False, 1.74532925199433E-02, 1.74532925199433E-02, False, False, False, False, True, True, True, 0, 0, False)

Part.SelectionManager.EnableContourSelection = False

Part.SketchManager.Insert3DSketch True

Dim skSegment1a As Object

Set skSegment1a = Part.SketchManager.CreateLine(-51.2793, -61.6772, -38.2916, 55.7814, 38.1473, 26.3077)

Part.SetPickMode

Part.ClearSelection2 True

Part.SketchManager.Insert3DSketch True

boolstatus = Part.Extension.SelectByID2("Line1@Esquisse3D1", "EXTSKETCHSEGMENT", 55.7814, 38.1473, 26.3077, True, 0, Nothing, 0)

boolstatus = Part.Extension.SelectByID2("Point1@Esquisse3D1", "EXTSKETCHPOINT", -51.2793, -61.6772, -38.2916, True, 1, Nothing, 0)

Dim myRefPlane1 As Object

Set myRefPlane1 = Part.FeatureManager.InsertRefPlane(2, 0.002, 4, 0, 0, 0)

boolstatus = Part.Extension.SelectByID2("Plan1", "PLANE", -4.80394589232693E-02, 2.05838674226015E-02, 3.00484425104059E-02, False, 0, Nothing, 0)

Dim skSegment1b As Object

Set skSegment1b = Part.SketchManager.CreateCircle(0, 0, 0, 1, 0, 0)

Set myFeature = Part.FeatureManager.FeatureCut3(True, False, True, 1, 0, 50, 50, False, False, False, False, 1.74532925199433E-02, 1.74532925199433E-02, False, False, False, False, False, True, True, True, True, False, 0, 0, False)

boolstatus = Part.Extension.SelectByID2("Plan1", "PLANE", -4.80394589232693E-02, 2.05838674226015E-02, 3.00484425104059E-02, False, 0, Nothing, 0)

Part.BlankRefGeom

boolstatus = Part.Extension.SelectByID2("Line1@Esquisse3D1", "EXTSKETCHSEGMENT", -4.96918629056041E-02, 2.31034739947416E-02, 3.96719923841123E-03, False, 0, Nothing, 0)

Part.BlankSketch

End Sub

Outcomes