14 Replies Latest reply on Feb 8, 2016 5:05 AM by Deepak Gupta

    STP To SLDPRT

    Luke Langdon

      I see many macros floating around for SLDPRT to STP but our customers love to send us STP files. Problem is I get tons of them per package. I'm trying to batch Open all STP in folder and output as .SLDPRT withing the same directory. Short Term Goal

       

      Long term goal would be:

       

      Open STP

      Save as SLDPRT

      CLOSE

      Open new SLDPRT

      Run Import Diagnostics

      Save

      CLOSE

       

      Any help would be greatly appreciated

        • Re: STP To SLDPRT
          Deepak Gupta

          It could be made like this.

           

          Open STP

          Run Import Diagnostics

          Save as SLDPRT

          Save

          CLOSE

          You can use SOLIDWORKS Task Scheduler to do the job.

           

           

          With option to repair import error

          • Re: STP To SLDPRT
            Luke Langdon

            Saved out as SLDASM for me for some reason

              • Re: STP To SLDPRT
                Luke Langdon

                Looking for help on a simple macro to save out as SLDPRT I'm using Batch Process addon to import the project. Which saved the task manager question.

                BP allows you to run macros as well. So it will import all the files one by one in selsected folder and then run the specified macro on each file. My goal is to have a macro that simply saves the step file as the original file name as SLDPRT and I'm struggling!!

                 

                 

                1. )    Select all files for project in BP
                2. )    Create a job to run a macro in BP
                3. )    Macro would run diagnostics on step

                               'Run diagnostics on the STEP file and repair the bad faces or this could be later after STEP is PART

                         status = swModelDocExt.SelectByID2("Imported1", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)

                          swModel.ClearSelection2 True

                          errors = swPart.ImportDiagnosis(True, False, True, 0)

                         swModel.ClearSelection2 True

                 

                            'Then save out as SLDPRT in "C:\Users\luke\Downloads\Step3”

                          Set Part = swApp.ActiveDoc

                          longstatus = Part.SaveAs3("C:\Users\luke\Downloads\Step3\FILENAME.sldprt", 0, 0)

                 

                 

              • Re: STP To SLDPRT
                Luke Langdon

                Ok back it! Ive edited the macro to:

                 

                   sFileName = Dir(Path & "*.STP") ' Change file extension here

                    Do Until sFileName = ""

                    Set swModel = swApp.LoadFile4(Path & sFileName, "r", swImportData, Err)

                    Set swModel = swApp.ActiveDoc

                    swConfigMgr = swModel.ConfigurationManager ' Working

                    swConfigMgr.LinkDisplayStatesToConfigurations = True ' Working

                    Set activeModelView = swModel.ActiveView 'Working

                    activeModelView.DisplayMode = swViewDisplayMode_e.swViewDisplayMode_ShadedWithEdges 'Working shaded with edges

                    boolstatus = swModel.Extension.SelectByID2("swModel", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0) ' setting up for clear all part appereance

                    swModel.ClearSelection2 True 'Working Clear all apperance

                    sModelName = swModel.GetTitle

                    sModelName = Path & sModelName

                    swModel.ViewZoomtofit2

                    swModel.SaveAs sModelName & "__" & "(" & Format(Date, "mm-dd-yyyy") & ")" & ".SLDPRT" '' Append todays date

                    swApp.CloseDoc swModel.GetTitle

                 

                 

                 

                Im having issues with

                 

                Set SH = New Shell32.Shell

                Set F = SH.BrowseForFolder(0&, Caption, BIF_RETURNONLYFSDIRS, CurDir("X"))  ''''HELP!!!!

                 

                 

                My goal is to have the macro when Browse folder is opened that i will jump to specific network drive and folder.

                  • Re: STP To SLDPRT
                    Luke Langdon

                    One more question here.

                     

                    boolstatus = swModel.Extension.SelectByID2("swModel", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0) ' setting up for clear all part appereance swmodel.gettitle better?

                     

                    Not sure a great way to handle Clear part appearance. but it seems to be working as is

                    • Re: STP To SLDPRT
                      Deepak Gupta

                      Luke Langdon wrote:

                       

                      Set SH = New Shell32.Shell

                      Set F = SH.BrowseForFolder(0&, Caption, BIF_RETURNONLYFSDIRS, CurDir("X"))  ''''HELP!!!!

                       

                      My goal is to have the macro when Browse folder is opened that i will jump to specific network drive and folder.

                      What drive/folder you need?

                       

                      And for removing all appearances from the model, there are different codes to be used.

                        • Re: STP To SLDPRT
                          Luke Langdon

                          Going to try this

                           

                              Set swApp = Application.SldWorks

                              Set modelDoc = swApp.ActiveDoc

                              Set partDoc = modelDoc

                              boolstatus = partDoc.RemoveAllDisplayStates

                              partDoc.ForceRebuild

                           

                          Rather then an EXE admin around here always hate exe

                            • Re: STP To SLDPRT
                              Luke Langdon

                              Anyone know how to get this to loop until no more part or assemblie files are avalable and SWAPP = Null?

                               

                              Sub main()

                              Do Until ModelDoc2 Is Nothing

                                Set swApp = CreateObject("SldWorks.Application")

                                Set ModelDoc2 = swApp.ActiveDoc      ' Grab currently active document

                                If ModelDoc2 Is Nothing Then         ' Check to see if a document

                                  MsgBox "No document loaded.  A SolidWorks " + Chr$(10) + Chr$(13) _

                                       + "part model must be loaded."

                                Else

                                  FileTyp = ModelDoc2.GetType

                                  If FileTyp = swDocPART Then

                                    ' Document is a SolidWorks part. Show form

                                    FormModelColor.Show

                                  Else

                                    MsgBox "Document is not a SolidWorks part. A SolidWorks part model must be loaded."

                                  End If          ' document type

                                End If            ' document loaded

                                    Loop

                                 '      Set ModelDoc2 = Nothing

                              End Sub

                              • Re: STP To SLDPRT
                                Deepak Gupta

                                This should work fine too.