2 Replies Latest reply on Sep 18, 2014 2:32 PM by Ted Wayne

    Macro to make stl and igs parts of model starting from drawing file

    Ted Wayne

      At work we have been having problems with keeping our revisions in line with all of our files. Our drawing templates are set up so the most recent revision in the revision box on the title block links back to the custom properties. I have managed to find macros online and modify them to help with our problem. right now i have one that takes the revision off the drawing file, adds it to the end of the model file name, and saves it as a .STEP file. I want to do this with .igs and .stl files also but i cannot seem to get it to work. This is what i have for step files.

       

      *I am fairly new to Macros, but i have a decent understanding of programing

       

       

      Dim swApp           As SldWorks.SldWorks

      Dim swModel         As SldWorks.ModelDoc2

      Dim swDraw          As SldWorks.DrawingDoc

      Dim swCustProp      As CustomPropertyManager

      Dim valOut          As String

      Dim resolvedValOut  As String

      Dim Filepath        As String

      Dim FileName        As String

      Dim retVal          As Boolean

      Dim errors          As Long, warnings As Long

       

      Sub main()

       

      Set swApp = Application.SldWorks

      Set swDraw = swApp.ActiveDoc

       

      ' Check to see if a drawing is loaded.

       

      If (swDraw Is Nothing) Or (swDraw.GetType <> swDocDRAWING) Then

       

      1. swApp.SendMsgToUser ("To be used for drawings only, Open a drawing first and then TRY!")

      ' If no model currently loaded, then exitExit Sub End If Set swView = swDraw.GetFirstViewSet swView = swView.GetNextViewSet swModel = swView.ReferencedDocumentSet Sheet = swApp.ActiveDoc.GetCurrentSheet  Set swCustProp = swDraw.Extension.CustomPropertyManager("")

      1. swCustProp.Get2 "Revision", valOut, resolvedValOut 'Change the custom property name here

       

      Filepath = Left(swDraw.GetPathName, InStrRev(swDraw.GetPathName, "\"))

       

      FileName = Left(swModel.GetTitle, Len(swModel.GetTitle) - 7)

       

      'change the step file options

      retVal = swApp.SetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swStepAP, 214)

      'save

      retVal = swModel.Extension.SaveAs(Filepath & FileName & "REV" & resolvedValOut & ".step", swSaveAsVersion_e.swSaveAsCurrentVersion, swSaveAsOptions_e.swSaveAsOptions_Silent, Nothing, errors, warnings)

        

      End Sub