3 Replies Latest reply on Nov 22, 2013 10:25 AM by Todd Bennett

    How to export at Coordinate System1?

    Todd Bennett

      I have a simple export tool that Deepak Gupta wrote.  It saves a part file as an iges.  However, I want it to use a custom coordinate system.

      I always leave the coordinate system named the default (Coordinate System1).

       

      Any help is appreciated.

       

      Here's the relevant snip:

       

      sPath = Left(swModel.GetPathName, InStrRev(swModel.GetPathName, "\"))

       

      sModelName = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "\") + 1)

      sModelName = Left(sModelName, InStrRev(sModelName, ".") - 1)

       

      swModel.SaveAs (sPath & sModelName & ".igs")

        • Re: How to export at Coordinate System1?
          Artem Taturevych

          Try this:

          swModel.Extension.SetUserPreferenceString swUserPreferenceString_e.swFileSaveAsCoordinateSystem, swUserPreferenceOption_e.swDetailingNoOptionSpecified, "Coordinate System1"


           

          swModel.SaveAs (sPath & sModelName & ".igs")

          ____________________________________________________

          Regards,

          Artem Taturevych, Application Engineer at Intercad (Australia)

           

          translationXpert – add-in to translate SolidWorks models

          myIntercad an integrated tool for SolidWorks Professionals

          LinkedIn SolidWorks API Education Group

            • Re: How to export at Coordinate System1?
              Todd Bennett

              You have a little typo: swUserPreferenceString_e.sw... should be swUserPreferenceStringValue_e.sw...

               

              Thank you, it worked great once I figured this out.

              • Re: How to export at Coordinate System1?
                Todd Bennett

                Here's the modified code (below).

                ---------------------------------------------------------------

                 

                Option Explicit

                 

                    Dim swApp                   As SldWorks.SldWorks

                    Dim swModel                 As SldWorks.ModelDoc2

                    Dim sPath                   As String

                    Dim sModelName              As String

                    Dim bRebuild                As Boolean

                   

                Sub Main()

                 

                    Set swApp = CreateObject("SldWorks.Application")

                    Set swModel = swApp.ActiveDoc

                   

                    'Check a file is Open

                    If swModel Is Nothing Then

                    swApp.SendMsgToUser2 "Please open a PART file!", swMbWarning, swMbOk

                    Exit Sub

                    End If

                  

                   'Check that active file is a Part file

                    If swModel.GetType <> swDocPART Then

                    swApp.SendMsgToUser2 "Not a Part File, please open a PART file!", swMbWarning, swMbOk

                    Exit Sub

                    End If

                 

                    'Force Rebuild

                    bRebuild = swModel.ForceRebuild3(False)

                 

                    'Get file path

                    sPath = Left(swModel.GetPathName, InStrRev(swModel.GetPathName, "\"))

                 

                    'Get File Name Without extension

                    sModelName = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "\") + 1)

                    sModelName = Left(sModelName, InStrRev(sModelName, ".") - 1)

                   

                    'Set Save path

                    sPath = sPath '& sModelName & "\"

                   

                    'Use the custom coordinate system

                    swModel.Extension.SetUserPreferenceString _

                    swUserPreferenceStringValue_e.swFileSaveAsCoordinateSystem, _

                    swUserPreferenceOption_e.swDetailingNoOptionSpecified, "Coordinate System1"

                   

                    'Save file as IGES

                    swModel.SaveAs (sPath & sModelName & ".igs")

                 

                End Sub