I'm new to Solidworks API and VBA. I have created a text file which contains coordinates of vertices of many (like 200) polygons and I want to draw simple 3D objects from this data. I recorded this macro in Solidworks for a pentagon and I tried to put a for-loop in it to draw my 200 pentagon in a row.
I know I have to read a column of vertices from my text file and use it in the
Part.SketchManager.CreateLine(x1, y1, z1, x2, y2, z2)
commands. but it doesn't work. Many errors occurs which means there are many thing that I don't know to run this code as I expect.
if you think i have to tell more details, Please tell me to complete the question!!!
' ******************************************************************************
' C:\Users\Abbas\AppData\Local\Temp\swx7040\Macro1.swb - macro recorded on 02/11/20 by Abbas
' ******************************************************************************
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.NewDocument("C:\ProgramData\SolidWorks\SOLIDWORKS 2016\templates\Part.prtdot", 0, 0, 0)
swApp.ActivateDoc2 "Part4", False, longstatus
Set Part = swApp.ActiveDoc
Dim myModelView As Object
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
boolstatus = Part.Extension.SelectByID2("Top Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
Part.ClearSelection2 True
Dim skSegment As Object
Set skSegment = Part.SketchManager.CreateLine(0#, 0#, 0#, 0.043745, 0#, 0#)
Set skSegment = Part.SketchManager.CreateLine(0.043745, 0#, 0#, 0.06038, 0.030036, 0#)
Set skSegment = Part.SketchManager.CreateLine(0.06038, 0.030036, 0#, 0.031422, 0.064231, 0#)
Set skSegment = Part.SketchManager.CreateLine(0.031422, 0.064231, 0#, -0.016327, 0.049752, 0#)
Set skSegment = Part.SketchManager.CreateLine(-0.016327, 0.049752, 0#, 0#, 0#, 0#)
Part.ShowNamedView2 "*Trimetric", 8
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Line5", "SKETCHSEGMENT", 0, 0, 0, False, 0, Nothing, 0)
Dim myFeature As Object
Set myFeature = Part.FeatureManager.FeatureExtrusion2(True, False, False, 0, 0, 0.001, 0.001, False, False, False, False, 1.74532925199433E-02, 1.74532925199433E-02, False, False, False, False, True, True, True, 0, 0, False)
Part.SelectionManager.EnableContourSelection = False
longstatus = Part.SaveAs3("C:\Users\Abbas\Desktop\Part4.SLDPRT", 0, 2)
Part.ClearSelection2 True
Set Part = Nothing
swApp.CloseDoc "Part4.SLDPRT"
End Sub
I need to create sth like this in solidworks...