Save as DWG macro

  • Follow


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 


0
Reply Wayne 1/16/2008 2:40:27 PM

On Jan 16, 6:40=A0am, "Wayne Tiffany" <wayne.tiffanyRMVJ...@asi.com>
wrote:
> We have been using a macro to save a drawing as a PDF that was last enhanc=
ed
> by Matthew Lorono. =A0This works pretty well in that if the save fails, yo=
u
> get errors returned, such as the file was not writable, maybe because it w=
as
> read-only.
>
> So, I said, since this one is so handy, why not make another one-button pu=
sh
> to save out the DWG copy also. =A0Great - change the PDFs to DWGs. =A0Work=
s.
> Mostly. =A0It will save the file properly, but if the file already exists,=
 and
> it's read-only, then there still are no errors returned. =A0It's not that =
I am
> not seeing the returns, the code is telling me that the "MB =3D
> Model.SaveAs4(MyPathConf & "\" & NewName, swSaveAsCurrentVersion,
> swSaveAsOptions_Silent, Errs, Warnings)" returns true.
>
> Any thoughts as to why?
>
> =A0 WT
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
0
Reply fcsuper 1/16/2008 10:47:17 PM


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 


0
Reply Wayne 1/17/2008 1:26:14 AM

On Jan 16, 5:26=A0pm, "Wayne Tiffany" <wayne.tiffanyRMVJ...@asi.com>
wrote:
> 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 retur=
n
> errors, and the DWG save not return those same errors?
>
> =A0 WT

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
0
Reply fcsuper 1/17/2008 4:05:37 PM

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 


0
Reply Wayne 1/17/2008 9:43:55 PM

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
0
Reply Tin 1/18/2008 2:19:20 AM

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.

0
Reply Ronni 1/18/2008 8:18:14 AM

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 


0
Reply Wayne 1/18/2008 1:13:33 PM

On Jan 18, 5:13=A0am, "Wayne Tiffany" <wayne.tiffanyRMVJ...@asi.com>
wrote:
> 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. =A0If =
the
> file is read-only by the attribute, or if an app has it open, it will retu=
rn
> the proper errors. =A0The fact that there is a recognized bug about saving=
 to
> DXF probably means that same thing applies for DWG.
>
> =A0 WT

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
0
Reply fcsuper 1/18/2008 8:46:32 PM

8 Replies
582 Views

(page loaded in 2.278 seconds)

Similiar Articles:













7/23/2012 5:32:06 PM


Reply: