1 Reply Latest reply on Jul 14, 2015 12:10 PM by Simon Turner

    Import step assembly, save as single part

    Damon Frashure

      I have received a slew of step files from a client and would like a little help with importing the assemblies into parts.  I know i can put them all in subfolders and use the Task Scheduler to import all of them (many use "part 1" as file names so they have to be isolated).  Is there a setting I can use to save the assembly as a part?  Alternatively, Would it be possible to add a statement like swModel.SaveAs(Left(OpenDoc.GetTitle, (Len(OpenDoc.GetTitle) - 7)) + ".sldprt") to code such as this?

       

      '----------------------------------------

      ' Precondition: C:\Test\Part1_203.STEP exists.

      ' Postconditions: C:\Test\Part1_203.STEP is imported into SolidWorks.

      '----------------------------------------

       

      Option Explicit

      Sub main()

      Dim swApp As SldWorks.SldWorks

      Dim Part As SldWorks.ModelDoc2

      Dim boolstatus As Boolean

      Dim longstatus As Long, longwarnings As Long

      Set swApp = Application.SldWorks

      Dim importData As SldWorks.ImportStepData

      Set importData = swApp.GetImportFileData("C:\Test\Part1_203.STEP")

      ' If ImportStepFile::MapConfigurationData is not set, then default to

      ' the environment setting swImportStepConfigData; otherwise, override

      ' swImportStepConfigData with ImportStepFile::MapConfigurationData

      ImportData.MapConfigurationData = True

      Set Part = swApp.LoadFile4("C:\Test\Part1_203.STEP", "r", importData, longstatus)

      swModel.SaveAs(Left(OpenDoc.GetTitle, (Len(OpenDoc.GetTitle) - 7)) + ".sldprt")

      End Sub

        • Re: Import step assembly, save as single part
          Simon Turner

          2 things:

           

          1. The file name is probably best taken from the step file. E.g. Replace(aFilename, ".step", ".sldprt")    'Where aFilename is the name of the Step file.

          2. Use this code to save an assembly document as a part:

          swApp.SetUserPreferenceIntegerValue swSaveAssemblyAsPartOptions, swSaveAsmAsPart_AllComponents

          Part.Extension.SaveAs Replace(aFilename, ".step", ".sldprt"), swSaveAsCurrentVersion, swSaveAsOptions_Silent, Nothing, nErrors, nWarnings

           

          Make sure you have Option Compare Text at the top of the file so that it is case insensitive.