Macro to Revolve A Curve
I want a Macro that will import points as a curve from a TXT file saved at a particular location. Then I want to convert that line to sketch using "Convert Entities" and then draw a line, starting from the beginning of the curve to the end of the curve. Exit the sketch and then revolve the curve. And finally save it as a .STL file.
I have a code but I want to make the whole process go without any human interaction.
' ****************************************************************************** ' C:\Users\Prasanna Naik\AppData\Local\Temp\swx13908\Macro1.swb - macro recorded on 04/29/21 by Prasanna Naik ' ****************************************************************************** Dim swApp As Object Option Explicit Dim Filter As String Dim fileName As Variant Dim fileConfig As String Dim fileDispName As String Dim fileOptions As Long Dim i As Long Dim boolResult As Boolean Dim boolstatus As Boolean Dim lErrors As Long Dim lWarnings As Long Dim swSketchManager As SldWorks.SketchManager Dim swSketchPt(8) As SldWorks.SketchPoint Dim swSketchSeg(12) As SldWorks.SketchSegment Dim swCurve As String Dim commandID As Long Dim pmpTitle As String Dim defaultTemplate As String Dim swModel As SldWorks.ModelDoc2 Dim swModelDocExt As SldWorks.ModelDocExtension Dim instance As IFeatureManager Dim value As Feature Dim bodyArr As Object Dim X_max As Double Dim X_min As Double Dim Y_max As Double Dim Y_min As Double Dim Z_max As Double Dim Z_min As Double Dim myModelView As Object Dim myFeature As Object Dim Part As Object
Sub main() 'Opens SolidWorks(R) and creates a new swmodel: Set swApp = CreateObject("SldWorks.Application") swApp.Visible = True swApp.NewPart swApp.FrameState = 1
'Defines "swmodel" as ActiveDoc, from which different commands are available to the user: Set swModel = swApp.ActiveDoc
Set swApp = Application.SldWorks
' Filter = "Data Point file (.txt)|.txt|"
' fileName = swApp.GetOpenFileName("Select File", "C:\Users\MAHE\Documents\MATLAB\MATLAB Drive\Project", Filter, fileOptions, fileConfig, fileDispName)
fileName = "C:\Users\MAHE\Documents\MATLAB\MATLAB Drive\Project\SolidWorks_Data_Import_MATLAB2(TXT_Import).txt"
boolResult = swModel.InsertCurveFile(fileName)
' Creating Variable for Solidworks Sketch segment Dim mySketchSegment As SketchSegment
' Selecting Front Plane boolstatus = swModel.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, False, 0, Nothing, swSelectOption_e.swSelectOptionDefault)
' Setting Sketch manager for our sketch Set swSketchManager = swModel.SketchManager
' Inserting a sketch into selected plane swSketchManager.InsertSketch True
swApp.RunCommand swCommands_ConvertEntities, ""
Do
commandID = "0"
pmpTitle = "0"
swApp.GetRunningCommandInfo commandID, pmpTitle, boolstatus
DoEvents
Loop While boolstatus = True
Set Part = swApp.ActiveDoc Part.SketchManager.InsertSketch True boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, False, 0, Nothing, 0) Part.SketchManager.InsertSketch True Dim skSegment As Object Set skSegment = Part.SketchManager.CreateLine(0.001, 0.000001, 0#, 0#, 0#, 0#) Part.ClearSelection2 True Part.SketchManager.InsertSketch True
Set Part = swApp.ActiveDoc boolstatus = Part.Extension.SelectByID2("Line1@Sketch1", "EXTSKETCHSEGMENT", 1.56212632184793E-04, 1.31218611035226E-07, 0, False, 0, Nothing, 0) boolstatus = Part.Extension.SelectByID2("Line1@Sketch1", "EXTSKETCHSEGMENT", -8.68326174619297E-04, 4.89633219419543E-04, 0, True, 0, Nothing, 0)
' Named View Part.ShowNamedView2 "*Trimetric", 8 Part.ViewZoomtofit2 Part.ClearSelection2 True boolstatus = Part.Extension.SelectByID2("Line1@Sketch1", "EXTSKETCHSEGMENT", -9.10362560773592E-04, 1.42376660335231E-04, 0, False, 16, Nothing, 0) Dim myFeature As Object Set myFeature = Part.FeatureManager.FeatureRevolve2(True, True, False, False, False, False, 0, 0, 6.2831853071796, 0, False, False, 0.01, 0.01, 0, 0, 0, True, True, True) Part.SelectionManager.EnableContourSelection = False
End Sub