-
Re: How to Replace model reference in view on drawing
roberto gennari Apr 20, 2016 12:41 AM (in response to Yong Ning)Hi Yong,
I used this Api in for your problem
2012 SOLIDWORKS API Help - Replace Referenced Document Example (VBA)
Thanks
Roberto
-
Re: How to Replace model reference in view on drawing
Yong Ning Sep 6, 2016 7:52 PM (in response to roberto gennari)Thank you tip
'-----------------------------------------
'
' 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*****************************************************
Private Sub del20()
Dim Xls As Excel.Application, Rng As Range
Set Xls = GetObject(, "Excel.Application")
Set Rng = Xls.Selection
Dim sReferencingDoc, sOldDoc, sNewDoc
sOldDoc = Rng(1, 3)
sNewDoc = Rng(1, 4)
Dim SwApp As SldWorks.SldWorks
Set SwApp = Application.SldWorks
Dim DrawRng As Range, FileName
Set DrawRng = Xls.Range(Rng(1, 1).Formula)
Debug.Print DrawRng.Address
For ii = 1 To DrawRng.Rows.Count
FileName = Rng(1, 2) & DrawRng(ii, 1)
tmp = SwApp.ReplaceReferencedDocument(FileName, sOldDoc, sNewDoc)
Debug.Print DrawRng(ii, 1), tmp
Next ii
End Sub
-
Re: How to Replace model reference in view on drawing
Anton Miller Apr 21, 2016 11:04 AM (in response to roberto gennari)Is there a way to do like a get current reference file name, then use that instead of specifying a file name each time?
-
Re: How to Replace model reference in view on drawing
Deepak Gupta Apr 21, 2016 11:10 AM (in response to Anton Miller)You can get the file name/path, etc. from the view
Set swModel = swView.ReferencedDocument
-
-