Here's what I have and what i have defined. Everything that I have as #not sure about this is what I don't understand. I want to learn the SolidWorks API code and I don't know what certain definitions and tasks are doing in this macro. The yellow highlighted part is the code. Thanks again for any help.
Option Explicit #Not sure yet
Dim swApp As SldWorks.SldWorks #This defines the application as Solidworks
Dim swModel As SldWorks.ModelDoc2 #This defines swModel as the Solidworks model document
Dim swSketchMgr As SldWorks.SketchManager #This defines swSketchMgr as the sketch manager for creating sketches in SolidWorks
Dim swExcel As Excel.Application #This defines swExcel as the Microsoft Excel application
Dim exSheet As Excel.Worksheet #This defines the excel spreadsheet as the document to use in the macro for exporting numbers for Solidworks to use
Dim i As Integer #This defines i as an integer to use for various tasks
Dim xpt As Double #Not sure about this part yet
Dim ypt As Double #Not sure about this part yet
Dim zpt As Double #Not sure about this part yet
Dim xpt1 As Double #Not sure about this part yet
Dim ypt1 As Double #Not sure about this part yet
Dim zpt1 As Double #Not sure about this part yet
Sub main() #sets apart the definitions from the actual applications procedures or commands
Set swApp = Application.SldWorks #Sets up the application
Set swModel = swApp.ActiveDoc #Prepares to use the active document for the entity to which the properties will act in
If swModel Is Nothing Then #Is a double check procedure to make sure an active document is open for editing
MsgBox "Please activate a part document before using this macro." #is a warning from the macro application to the user on why it will not function
Exit Sub #Exits the current set of commands in the macro and returns to an offline state until the user changes the error so the next run will execute the macro properly
End If #Ends the if command loop
If swModel.GetType <> 1 Then #Not sure
MsgBox "Please activate a part document before using this macro."
Exit Sub #Exits the current set of commands in the macro and returns to an offline state until the user changes the error so the next run will execute the macro properly
End If #Ends the If command loop
If Not swModel.GetActiveSketch2 Is Nothing Then #Not sure yet
MsgBox "Please exit the sketch before running this macro." #is a warning from the macro application to the user on why it will not function
Exit Sub #Exits the current set of commands in the macro and returns to an offline state until the user changes the error so the next run will execute the macro properly
End If #Ends the If command loop
#Code has passed the initial tests. Will start the next commands for the macro
Set swExcel = GetObject(, "Excel.Application") #Will open up the excel application for the macro
Set exSheet = swExcel.ActiveSheet #Takes the activesheet for importing data
Set swSketchMgr = swModel.SketchManager #Sets the sketch manager open in Solidworks
swModel.ClearSelection2 True #Clears any selection the mouse is clicked on
swModel.SketchManager.Insert3DSketch True #Is activating the 3D sketch for Solidworks
swModel.SetAddToDB True #Not sure yet
i = 1 #Defines the integer i as 1
Do While exSheet.Cells(i, 1).Value <> "" #Not sure yet
xpt = exSheet.Cells(i, 1).Value / 1000 #Takes the excel spreadsheet i-A and divides its value by 1000 for the x1-point
ypt = exSheet.Cells(i, 2).Value / 1000 #Takes the excel spreadsheet i-B and divides its value by 1000 for the y1-point
zpt = exSheet.Cells(i, 3).Value / 1000 #Takes the excel spreadsheet i-C and divides its value by 1000 for the z1-point
xpt1 = exSheet.Cells(i, 4).Value / 1000 #Takes the excel spreadsheet i-D and divides its value by 1000 for the x2-point
ypt1 = exSheet.Cells(i, 5).Value / 1000 #Takes the excel spreadsheet i-E and divides its value by 1000 for the y2-point
zpt1 = exSheet.Cells(i, 6).Value / 1000 #Takes the excel spreadsheet i-F and divides its value by 1000 for the z2-point
swModel.SketchManager.CreateLine xpt, ypt, zpt, xpt1, ypt1, zpt1 #Creates a line based on the values from the above commands
i = i + 1 #defines the next i value as i+1 so the next column will be selected as 2-A 2-B ect
Loop #defines the loop so the command starts again at i=current value at end of the loop when 1 is added from the previous step
swModel.ViewZoomtofit2 #Zooms the Solidwork application to fit the view of all the line segments drawn
swModel.SetAddToDB False #Not sure yet
swModel.ClearSelection #Clears the selection manager from the current operation
swModel.SketchManager.Insert3DSketch True #Not quite sure yet
swModel.ClearSelection2 True #Clears the selection manager
End Sub #Ends the macro
SolidworksApi macros