3 Replies Latest reply on Nov 19, 2012 2:55 AM by Artem Taturevych

    How to replace parts in drawing? Use API method.

    Yong Ning

      a0.jpg

      I hope use API method

      the a.sldprt replace b.sldprt in Drawing of a.slddrw

      a2.jpg

       

       

      In Drawing of a.slddrw, display b.sldprt.

      a1.jpg

       

      Record Macro,But don't repalce sldprt.

       

      ' ******************************************************************************
      ' C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\swx3712\Macro1.swb - macro recorded on 11/19/12 by Administrator
      ' ******************************************************************************
      Dim swApp As Object
      Dim Part As Object
      Dim SelMgr As Object
      Dim boolstatus As Boolean
      Dim longstatus As Long, longwarnings As Long
      Dim Feature As Object
      Sub main()

         Set swApp = Application.SldWorks

         Set Part = swApp.OpenDoc6("D:\Backup\我的文档\DrawingSld\a.SLDDRW", 3, 0, "", longstatus, longwarnings)
         Set Part = swApp.ActivateDoc2("a - 图纸1", False, longstatus)
      End Sub

        • Re: How to replace parts in drawing? Use API method.
          Artem Taturevych

          Use this method:

           

          http://help.solidworks.com/2012/English/api/sldworksapi/replace_referenced_document_example_vb.htm

           

          ______________________

          Regards,

          Artem Taturevych

          Application Engineer at Intercad

          http://intercad.com.au/

          Tel: +61 2 9454 4444

            • Re: How to replace parts in drawing? Use API method.
              Yong Ning

              Thank your like web.

               

              It's code

               

              Replace Referenced Document Example (VB)

              This example shows how to replace a referenced document with a different document

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

              '

              ' Preconditions:

              '           (1) c:\samples\whistles.sldasm, whistle.sldprt, and whistleLonger.sldprt

              '               exist.

              '           (2) c:\samples\whistles.sldasm is not open.

              '

              ' Postconditions: c:\samples\whistleLonger.sldprt replaced c:\samples\whistle.sldprt

              '               reference within c:\samples\whistles.sldasm.

              '

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

              Option Explicit

              Const sReferencingDoc       As String = "c:\samples\whistles.sldasm"

              Const sOldDoc               As String = "c:\samples\whistle.sldprt"

              Const sNewDoc               As String = "c:\samples\whistleLonger.sldprt"

              Sub main()

                  Dim swApp               As SldWorks.SldWorks

                  Dim bRet                As Boolean

                 

                  Set swApp = CreateObject("SldWorks.Application")

                 

                  bRet = swApp.ReplaceReferencedDocument(sReferencingDoc, sOldDoc, sNewDoc)

                  Debug.Assert bRet

              End Sub

               

              **********************************************

               

              Dim sReferencingDoc, sOldDoc, sNewDoc
              Sub main()
                  Dim swApp               As SldWorks.SldWorks
                  Dim bRet                As Boolean
                  Dim SwPart As SldWorks.ModelDoc2
                  Dim Str, Path
                  Set swApp = Application.SldWorks
                  Set SwPart = swApp.ActiveDoc
                  Str = SwPart.GetPathName
                  Path = Left(Str, InStrRev(Str, "\"))
                  'Debug.Print Path
                  Set swApp = CreateObject("SldWorks.Application")
                  sReferencingDoc = Path & "a.slddrw"
                  sOldDoc = Path & "a.sldprt"
                  sNewDoc = Path & "b.sldprt"
                  bRet = swApp.ReplaceReferencedDocument(sReferencingDoc, sOldDoc, sNewDoc)
                  'Debug.Assert bRet
              End Sub