Function if, then, elseIf (Solidworks Macro)

Hi all

I don't have any training in APIs but I have to create a code allowing us, by entering the reference of an axis, to build it to the right dimensions etc

I have already finished this code but when the customer Ø is < 6.35 we have a shoulder of Ø6.35 by 0.5mm.

And if it is greater than or equal to 6.35, we have instead of the shoulder the customer Ø on the customer length

I've already tried this but it still gives me a shoulder now:

If O < 6.35 Then

Set sksegment = Part.SketchManager.CreateCircleByRadius(0, 0, 0, Diam / 2) 'Circle dimensions (Ø)+ position

Set sksegment = Part.FeatureManager.FeatureExtrusion2(True, False, False, 0, 0, 0.5 / 1000, 0.01, False, False, False, False, 0.01745329251994, 0.01745329251994, False, False, False, False, 1, 1, 1, 0, 0, False)

boolstatus = Part.Extension.SelectByID2("Plan4", "PLANE", 0, 0, 0, False, 0, Nothing, 0) 'Created a plan and then extruded from it
Part.CreatePlaneAtOffset3 0.5/1000, False, True 'Distances are defined by the 1st length
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Plan5", "PLANE", 0, 0, 0, False, 0, Nothing, 0)

Set sksegment = Part.SketchManager.CreateCircleByRadius(0, 0, 0, O / 2) 'Circle Dimensions (Ø)+ Position

Set sksegment = Part.FeatureManager.FeatureExtrusion2(True, False, False, 0, 0, M - 0.7 / 1000, 0.01, False, False, False, False, 0.01745329251994, 0.01745329251994, False, False, False, False, 1, 1, 1, 0, 0, False)

boolstatus = Part.Extension.SelectByID2("Plan5", "PLANE", 0, 0, 0, False, 0, Nothing, 0) 'Created a plan and then extruded from it
Part.CreatePlaneAtOffset3 M - 0.7/1000, False, True 'Distances are defined by the 1st length
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Plan6", "PLANE", 0, 0, 0, False, 0, Nothing, 0)


Set sksegment = Part.SketchManager.CreateCircleByRadius(0, 0, 0, O/2)
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Plan6", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
Part.SketchManager.InsertSketch True
boolstatus = Part.Extension.SelectByID2("Plan6", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
 

 

ElseIf O >= 6.35 Then

Set sksegment = Part.SketchManager.CreateCircleByRadius(0, 0, 0, O / 2) 'Circle Dimensions (Ø)+ Position

Set sksegment = Part.FeatureManager.FeatureExtrusion2(True, False, False, 0, 0, M - 0.7 / 1000, 0.01, False, False, False, False, 0.01745329251994, 0.01745329251994, False, False, False, False, 1, 1, 1, 0, 0, False)

boolstatus = Part.Extension.SelectByID2("Plan4", "PLANE", 0, 0, 0, False, 0, Nothing, 0) 'Created a plan and then extruded from it
Part.CreatePlaneAtOffset3 M - 0.7/1000, False, True 'Distances are defined by the 1st length
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Plan5", "PLANE", 0, 0, 0, False, 0, Nothing, 0)

Set sksegment = Part.SketchManager.CreateCircleByRadius(0, 0, 0, O/2)
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Plan5", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
Part.SketchManager.InsertSketch True
boolstatus = Part.Extension.SelectByID2("Plan5", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
 

 

End If

If anyone has a solution, I'm all ears.

Sincere greetings

Hello Did you roll out your macro step by step to check the behavior? If no one answers you today, I'll take a look tomorrow because at the mycdday so no pc available.
1 Like

When I do it step by step, he still goes over the line where there is the construction of the shoulder and does it to me

I succeeded as a result, but I still have a problem that involves this function.

I put in my code text a part that "multiplies" the scale by two because when it's on a 1:1 scale it's impossible to distinguish the dimensions.

I would like this piece of code to be activated only when the scale is in 1:1 and I don't know how to write it in VBA

Hello, for the scale of the drawing, you can review your topic some macros where I gave you the link to the help of the api on sheetscale