API to rename files and keep files linkage relation

Discussion in 'SolidWorks' started by info.lowyeah, Jun 1, 2007.

  1. info.lowyeah

    info.lowyeah Guest

    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
     
    info.lowyeah, Jun 1, 2007
    #1
  2. info.lowyeah

    fcsuper Guest

    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/
     
    fcsuper, Jun 1, 2007
    #2
  3. info.lowyeah

    plh Guest

    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
     
    plh, Jun 1, 2007
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.