Discussion:
API to rename files and keep files linkage relation
(too old to reply)
i***@gmail.com
2007-06-01 11:45:09 UTC
Permalink
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
fcsuper
2007-06-01 15:31:06 UTC
Permalink
Post by i***@gmail.com
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:
http://sw.fcsuper.com/index.php?name=UpDownload&req=viewdownloaddetails&lid=8

Matt
http://sw.fcsuper.com
Co-moderator of http://groups.yahoo.com/group/solidworks/
plh
2007-06-01 16:27:01 UTC
Permalink
Post by i***@gmail.com
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
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
--
Where are we going and why am I in this HAND BASKET??
Loading...