I want to open a room and its plan from an Excel file, save this room under a new name 'save as' and for the plan to be up to date in terms of reference before saving it in turn.
I can open my files simultaneously, and save them under a new name. But the shot always points to the other room.
However, in manual it works. It looks like the record is not saving Under, but rather saving a copy.
I open with this method:
Set swModel = swApp.OpenDoc6("link to my plan", 3, 0, "", myError, myWarning)
And I record with this:
swModel.SaveAs2 "new link", 0, True, False
PS: And by the way, if someone has a trick to change the Part Designation property at the same time, it would help me a lot.
It's all in the sbadenis macro (so +1 for it), especially the ReplaceReferencedDocument function. For example:
Option Explicit
Const sReferencingDoc As String = "C:\Users\XXX\Desktop\Temp\Pièce5.SLDDRW"
Const sOldDoc As String = "C:\Users\XXX\Desktop\Temp\Pièce5.sldprt"
Const sNewDoc As String = "C:\Users\XXX\Desktop\Temp\Pièce1.sldprt"
Sub main()
Dim swApp As SldWorks.SldWorks
Dim bRet As Boolean
Set swApp = CreateObject("SldWorks.Application")
bRet = swApp.ReplaceReferencedDocument(sReferencingDoc, sOldDoc, sNewDoc)
End Sub
To be used without opening any of the documents in Solidworks!!
In your line "swModel.SaveAs2 "new link", 0, True, False", the "True" means "SaveAsCopy" = yes ... but you don't need this line anymore if you use the ReplaceReferenceDocument function...
Thank you for your answers, in fact replacing the True with False was enough to meet my need.
FYI I code from Excel and I have the impression that some things don't work the same. Like the lines with bRet, I've already seen some with the change of ownership, but it doesn't work on Excel, while on Solid yes.
I have an assembly "A" that contains an assembly "B"
"A" and "B" contain a "C" part.
If I replace part C with a part D in assembly A, the part in assembly B will also be replaced (that's the goal).
I finish by saving my assembly A. But I note that at the same time, assembly B was registered.
But I don't want to do that. However I put 0 as a backup option, But I notice that we should theoretically indicate to save the referents with swSaveAsOptions_SaveReferenced, but how to force it not to save them?
I don't really see the point of replacing your part C with a part D in your assembly B if you don't want to save this assembly B, you might as well replace part C with your part D only in your assembly A and keep your assembly B with your part C ...
The SaveAs2 function meets your needs but you shouldn't put 0 in the save options, it's not a valid option, you have to add up the choices made, for example:
1 + 2 for swSaveAsOptions_Silent and swSaveAsOptions_Copy
1 + 512 for swSaveAsOptions_Silent and swSaveAsOptions_CopyAndOpen