API: COPYDOCUMENT.

Discussion in 'SolidWorks' started by RICHARD MORGAN, Apr 7, 2004.

  1. I have a project where I am entering a few numbers into a dialog box
    which changes the lengths on three components, which then update 2 sub
    assemblies in a master assembly. I then open a master drawing up from
    the master assembly.

    I would like then to copy this drawing to a new folder, with a new
    file name, and all its referanced parts and sub assemblies being
    renamed and moved into the new folder.

    The reason is to have a master drawing which can be quickly changed
    and saved to a new project folder for that particular job. This allows
    me to create a drawing for a job in a couple of mins.

    The code works OK upto copying the new drawing and referanced parts to
    the new folder.
    The drawing is created in a new folder, but only three of the
    referanced parts are copied.

    Can any body see where I am going wrong:

    Thank you in advance
    Richard Morgan
    MorgDesign
    San Francisco

    Code follows:


    Sub OPENDWG()

    Dim bRet As Boolean

    Set Part = swApp.ActiveDoc

    swApp.LoadFile2 "F:\MORGAN W20 SETUP\FRAMES\ARCH WINDOW.slddrw",
    ""

    Set Part = swApp.ActiveDoc
    Set Part = swApp.OpenDoc6("F:\MORGAN W20 SETUP\FRAMES\ARCH
    WINDOW.SLDDRW", 3, 16, "", longstatus, longwarnings)
    swApp.ActiveDoc.ActiveView.FrameLeft = 0
    swApp.ActiveDoc.ActiveView.FrameTop = 0
    swApp.ActiveDoc.ActiveView.FrameState = 1
    swApp.ActiveDoc.ActiveView.FrameState = 1

    Set Part = swApp.ActivateDoc("ARCH WINDOW - Sheet1")
    Part.Rebuild (swForceRebuildAll)
    DWGTITLE = Part.GetTitle

    NEWFILE = "F:\MORGAN W20 SETUP\" + PRO_NAME + "\" + WIN_LOC + "\"
    + WIN_LOC + "_" + ".SLDDRW"

    Part.Save2 True


    'COPY DRAWING

    DWGCOPY

    'OPEN NEW DRAWING

    swApp.LoadFile2 NEWFILE, ""

    Set Part = swApp.ActiveDoc
    Set Part = swApp.OpenDoc6(NEWFILE, 3, 16, "", longstatus,
    longwarnings)
    swApp.ActiveDoc.ActiveView.FrameLeft = 0
    swApp.ActiveDoc.ActiveView.FrameTop = 0
    swApp.ActiveDoc.ActiveView.FrameState = 1
    swApp.ActiveDoc.ActiveView.FrameState = 1

    Set Part = swApp.ActivateDoc("NEWFILE - Sheet1")

    ' Part.Rebuild (swForceRebuildAll)
    'DWGTITLE = Part.GetTitle
    'Part.ClearSelection2 True

    'Part.Save2 True


    End Sub

    Sub FILEREFS()
    'ORIGINAL FILE NAMES INTO AN ARRY
    ORGFILENAME = Array("F:\MORGAN W20 SETUP\FRAMES\ARCH
    WINDOW.SLDASM", _
    "F:\MORGAN W20 SETUP\FRAMES\FRAME 1 -
    WX8.SLDASM", _
    "F:\MORGAN W20 SETUP\FRAMES\WX8 -
    BOTTOM.SLDPRT", _
    "F:\MORGAN W20 SETUP\FRAMES\WX8 -LEFT
    SIDE.SLDPRT", _
    "F:\MORGAN W20 SETUP\FRAMES\WX8 -RIGHT
    SIDE.SLDPRT", _
    "F:\MORGAN W20 SETUP\FRAMES\WX8 - CURVE
    TOP.SLDPRT", _
    "F:\MORGAN W20 SETUP\FRAMES\FRAME 2 -
    WH6.SLDASM", _
    "F:\MORGAN W20 SETUP\FRAMES\WH6 -
    BOTTOM.SLDPRT", _
    "F:\MORGAN W20 SETUP\FRAMES\WH6 - LEFT
    SIDE.SLDPRT", _
    "F:\MORGAN W20 SETUP\FRAMES\WH6 - RIGHT
    SIDE.SLDPRT", _
    "F:\MORGAN W20 SETUP\FRAMES\WH6 -
    CURVE.SLDPRT", _
    "F:\MORGAN W20 SETUP\FRAMES\GLASS.SLDPRT", _
    "F:\MORGAN W20 SETUP\FRAMES\WINDOW -
    ARCH.SLDPRT")

    NEWFILENAME = Array(NEWARCHWINASM, _
    NEW_F1, _
    NEW_WX8_BTM, _
    NEW_WX8_LFT, _
    NEW_WX8_RGT, _
    NEW_WX8_CUR, _
    NEW_F2, _
    NEW_WH6_BTM, _
    NEW_WH6_LFT, _
    NEW_WH6_RGT, _
    NEW_WH6_CUR, _
    NEW_GLASS, _
    NEW_ARCHWIN) 'NEW_F1 = "F:\MORGAN W20
    SETUP\" + PRO_NAME + "\" + WIN_LOC + "\" + WIN_LOC + "_FRAME 1 -
    WX8.SLDASM"

    End Sub

    Sub DWGCOPY()

    FILEREFS

    Dim retVal As Long

    swApp.CloseDoc ASSYTITLE
    swApp.CloseDoc DWGTITLE

    Set swApp = Application.SldWorks


    retVal = swApp.CopyDocument("F:\MORGAN W20 SETUP\FRAMES\ARCH
    WINDOW.SLDDRW", NEWFILE, ORGFILENAME, NEWFILENAME,
    swMoveCopyOptionsCreateNewFolder)


    End Sub
     
    RICHARD MORGAN, Apr 7, 2004
    #1
  2. RICHARD MORGAN

    Jim Sculley Guest

    For what it is worth, I have had similar problems with a much simpler
    example using both VB and C++. Copying without children works fine.
    Copying with children typically results in the assy and 1 child being
    copied.


    Jim S.
     
    Jim Sculley, Apr 8, 2004
    #2
  3. Have you thought about trying to manually copy the files (i.e., resolve the
    references manually, then use the file system to copy the files to the
    target directory?

    Evan
     
    Evan T. Basalik, Apr 9, 2004
    #3
  4. I could do it that way, but the project is for a customer who would like to
    create the drawings quickly without having to mess around copying and saving
    drawings.
    The best way to do it is through the Solidworks Explorer, but there are no
    API calls that I can see.

    My be this METHOD statement in API does not work correctly, needs fixing.
    I sent the problem into Solidworks API support this morning but I have not
    received a reply yet

    Richard
     
    RICHARD MORGAN, Apr 10, 2004
    #4
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.