1 Reply Latest reply on Apr 22, 2015 10:44 PM by Shaodun Lin

    DWG to SLDPRT Macro

    Mike Swagger

      Does anyone know of a macro that can open DWGs extrude them and save them?

        • Re: DWG to SLDPRT Macro
          Shaodun Lin

          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 2015\templates\Part.prtdot", 0, 0, 0)

            swApp.ActivateDoc2 "Part1", 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)

            Dim myFeature As Object

            Set myFeature = Part.FeatureManager.InsertDwgOrDxfFile("C:\CAD Data\Part1.DWG")

            Part.ShowNamedView2 "*Trimetric", 8

            Part.ClearSelection2 True

            Set myFeature = Part.FeatureManager.FeatureExtrusion2(True, False, False, 0, 0, 0.01, 0.01, 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:\CAD Data\Part1.SLDPRT", 0, 2)

            Part.ClearSelection2 True

            Set Part = Nothing

            swApp.CloseDoc "Part1.SLDPRT"

          End Sub