API to rename files and keep files linkage relation

Jun 01, 2007 2 Replies

Dear all,



Can anybody tell me how to rename solidworks files by API programming?



Just like using SolidWorks Explorer to rename the part file, and without broken the file inter-linkage.



Thank you very much.



Regards, Alan



Depends on how you want to do it. If the files are in memory at the time, there was a macro called Rename provided on the SolidWorks website. In case you don't have access to it, here's a copy of it:

formatting link
Matt
formatting link
of
formatting link

In article , snipped-for-privacy@gmail.com says...

Alan, The following is not a renaming but a copying routine, but maybe it is closely related enough to do what you want. I use windows functions to create the copies then reassign the references in the assembly and drawing files. (Note that I am not including the variable definitions

-plh

With obFSO Debug.Print RetVal strWholeFolderName = Me.txtFolder.Value & "\" & Me.txtCOP .CreateFolder (strWholeFolderName) If .fileexists(strWholeFolderName & "\" & strPartNum & strP) _ Or .fileexists(strWholeFolderName & "\" & strPartNum & strD) _ Or .fileexists(strWholeFolderName & "\" & strPartNum & strA) _ Then 'in case of overwrite make sure user wants to do that If MsgBox("File Exists! Want to Overwrite?", vbYesNo) 6 Then 'Me.txtFolder.Value = "" 'strpartnum = "" GoTo ExitSub Else Debug.Print strHomeFolder & strBP & strP .CopyFile strHomeFolder & strBP & strP, strWholeFolderName _ & "\" & strPartNum & strP 'copy the appropriate base part to the new folder Debug.Print strHomeFolder & strBA & strA .CopyFile strHomeFolder & strBA & strA, strWholeFolderName _ & "\" & strPartNum & strA 'copy the appropriate base assembly to the new folder Debug.Print strHomeFolder & strBD & strD .CopyFile strHomeFolder & strBD & strD, strWholeFolderName _ & "\" & strPartNum & strD 'copy the appropriate base drawing to the new folder End If Else Debug.Print strHomeFolder & strBP & strP .CopyFile strHomeFolder & strBP & strP, strWholeFolderName _ & "\" & strPartNum & strP 'copy the part to that folder Debug.Print strHomeFolder & strBA & strA .CopyFile strHomeFolder & strBA & strA, strWholeFolderName _ & "\" & strPartNum & strA 'copy the assembly to that folder Debug.Print strHomeFolder & strBD & strD .CopyFile strHomeFolder & strBD & strD, strWholeFolderName _ & "\" & strPartNum & strD 'copy the drawing to that folder End If End With Me.lblCylon1.Visible = True bolRetVal = False bolRetVal = swApp.SetCurrentWorkingDirectory(strWholeFolderName) 'change current folder for saving

strPartToReference = strWholeFolderName & "\" & strPartNum & strP strAssyToReference = strWholeFolderName & "\" & strPartNum & strA 'Me.txtFolder.Value & "\" & strpartnum & strP strDrawingToOpen = strWholeFolderName & "\" & strPartNum & strD bRet = False bRet = swApp.ReplaceReferencedDocument(strAssyToReference, strBP & strP, strPartToReference) 'replace ring in assembly bRet = False bRet = swApp.ReplaceReferencedDocument(strDrawingToOpen, strBP & strP, (strPartToReference)) 'replace individual ring in drawing bRet = False bRet = swApp.ReplaceReferencedDocument(strDrawingToOpen, strBA & strA, (strAssyToReference)) 'replace ring assembly in drawing

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required