Save as DWG macro

Discussion in 'SolidWorks' started by Wayne Tiffany, Jan 16, 2008.

  1. We have been using a macro to save a drawing as a PDF that was last enhanced
    by Matthew Lorono. This works pretty well in that if the save fails, you
    get errors returned, such as the file was not writable, maybe because it was
    read-only.

    So, I said, since this one is so handy, why not make another one-button push
    to save out the DWG copy also. Great - change the PDFs to DWGs. Works.
    Mostly. It will save the file properly, but if the file already exists, and
    it's read-only, then there still are no errors returned. It's not that I am
    not seeing the returns, the code is telling me that the "MB =
    Model.SaveAs4(MyPathConf & "\" & NewName, swSaveAsCurrentVersion,
    swSaveAsOptions_Silent, Errs, Warnings)" returns true.

    Any thoughts as to why?

    WT
     
    Wayne Tiffany, Jan 16, 2008
    #1
  2. Wayne Tiffany

    fcsuper Guest

    WT,

    Have the code do a search for the file's existence before executing
    the save code. This will allow you to not rely on errors to take
    action, but to allow the code to take the appropriate action before
    errors are caused.

    Matt Lorono
    http://sw.fcsuper.com
     
    fcsuper, Jan 16, 2008
    #2
  3. That makes some sense, so how do I query it to determine if it's open by
    something else, read-only, etc.?

    But, still on the original question, why would the PDF save properly return
    errors, and the DWG save not return those same errors?

    WT
     
    Wayne Tiffany, Jan 17, 2008
    #3
  4. Wayne Tiffany

    fcsuper Guest

    WT,

    It may actually be a bug. Have you tried the operation manually to
    see if you get the same results? If so, bug. If not, then maybe it's
    something to do with how the code handles the errors. If it is a bug,
    you'll still need a work-around, but it should be reported to S/W
    through your VAR.

    As far as having the code check to see if the file exists, try
    checking out MS API help first to see if there is an example already
    in there for this kind of action.

    Matt Lorono
    http://sw.fcsuper.com
     
    fcsuper, Jan 17, 2008
    #4
  5. Manually works properly. If the file is read-only it comes back with the
    proper notification. With the API SaveAs4, nothing comes back as a problem.

    WT
     
    Wayne Tiffany, Jan 17, 2008
    #5
  6. Wayne Tiffany

    Tin Man Guest

    Wayne,

    Running SW2007 sp0.0 here.

    I experimented with both SaveAs PDF and SaveAs DWG, and neither one
    prompted an error message for me...no matter what the new file was
    saved.

    I'm guessing the value at the "swSaveAsOptions_Silent" position is
    supposed to take care of this. Looking at the SW API Help for SaveAs4,
    I found this disclaimer on the bottom of the swSaveAsOptions_e page:
    "These options only apply to saving to native SolidWorks file
    formats."

    To answer your question posted above...here you go:

    If (Dir(MyPathConf & "\" & NewName) = "") Then 'Check if File Doesn't
    Already Exist.
    MB = Model.SaveAs4(strAcadName, swSaveAsCurrentVersion, 0, Errs,
    Warnings)
    If (MB) Then
    'Nothing. Do it this way because looking for "(Not(MB))" is
    unreliable.
    Else
    MsgBox "File was not Created.", vbCritical, "SaveAsDWG"
    End If
    Else
    MsgBox "File Already Exists.", vbCritical, "SaveAsDWG"
    End If

    Later,
    Ken
     
    Tin Man, Jan 18, 2008
    #6
  7. Wayne Tiffany

    Ronni Guest

    Also keep in mind that if someone else has the file open you wont be
    able to overwrite it, even when the file property wont way its read
    only. We have a similar problem with our PDF saving system.

    Also our VAR claims that there are some API errors concerning save as
    dxf, making it not save each time, sometimes it just skips it for
    whatever reason.
     
    Ronni, Jan 18, 2008
    #7
  8. We are on 2007 SP5 and I had seen the message about the options only
    applying to SW natives, but the PDF save does work properly for me. If the
    file is read-only by the attribute, or if an app has it open, it will return
    the proper errors. The fact that there is a recognized bug about saving to
    DXF probably means that same thing applies for DWG.

    WT
     
    Wayne Tiffany, Jan 18, 2008
    #8
  9. Wayne Tiffany

    fcsuper Guest

    WT and Ken,

    If you have a working version of your new macro with the addition of
    the file name check, I'd be interested in hosting on my site, with new
    edit credits going to you and Ken (Tin Man). Let me know.

    Matt Lorono
    http://sw.fcsuper.com
     
    fcsuper, Jan 18, 2008
    #9
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.