AnsweredAssumed Answered

How to fix this basic API code to run and create cylinder

Question asked by Isaiah Chester on Nov 14, 2019
Latest reply on Nov 15, 2019 by Dan Eldred

Trying to get this code to work so I can quickly create cylinders just by having macro ask me for length and radius; please help.   I want to create the cylinder in both directions using the mid plane. I have supplied my base code in the attachments as well as here in txt form:


'11/12/19


Option Explicit
'(First comment) Must explicitly declare all variables after this line
Dim SWAPP As SldWorks.SldWorks
'Allows the macro access to the SOLIDWORKS program
Dim VARS As String
Dim Xc As String
Dim Yc As String
Dim Zc As String
Dim Length As String

'This sets the variable Vars as 'string' type
Dim MYFEATURE As SldWorks.Feature
'This defines the variable myFeature as a SOLIDWORKS feature
Dim PART As SldWorks.Mode2Doc3
'Gives the macro access to more functions such as rebuilding a document and adding configurations
Dim BOOLSTATUS As Boolean
'Creates a Boolean variable
Dim LONGSTATUS As Long, LONGWARNINGS As Long
'Declares lonstatus and longwarnings variables as 'long' type
Dim VSKLINES As Variant
'Create a variable called vSkLines that is a variant type of variable
Sub MAIN()
'Start of code section
Set SWAPP = Application.SldWorks
'Makes the initial connection to enable things like opening, closing, creating, and saving documents
Set PART = SWAPP.ActiveDoc
'Sets the Part variable to the active doc
Length = InputBox("Enter Length")
VARS = InputBox("Enter x then")
'Creates a box for user input
Xc = 0
Yc = 0
Zc = 0
If VARS > 0 Then

'Simple 'if' statement, runs the rest of the code if the outcome is true
BOOLSTATUS = PART.SelectByID("TOP PLANE", "PLANE", 0, 0, 0)
'Defines location for a sketch
PART.SketchManager.InsertSketch True
'Creates a sketch on the previously chosen plane and location
VSKLINES = PART.SketchManager.CreateCircleByRadius(Xc, Yc, Zc, VARS / 1000)
'Sets the Square variable as a rectangle defined by the user input
Set MYFEATURE = PART.FeatureManager.FeatureExtrusion2(False, False, False, 0, 0, Length / 1000 / 2, Length / 1000 / 2, False, False, False, False, 0, 0, False, False, False, False, True, True, True, 0, 0, False)
'Above line creates extrusion with given parameters
PART.SelectionManager.EnableContourSelection = False
'This statement needs to follow any extrusion, and allows the disabling of contour selection
End If
'Ends the if statement created in the above statement including Vars
Set SWAPP = Application.SldWorks
End Sub

Attachments

Outcomes