PDA

View Full Version : Creating a DWF automatically on save



barnesd
2005-01-10, 04:23 PM
Hello

Is there a way in VBA that when the user saves his AutoCAD work I can automatically also save a DWF file in the background?

Thanks in Advance

Daniel

RobertB
2005-01-10, 05:43 PM
Have you considered the performance issues? I save every few minutes. I would hate this.

barnesd
2005-01-11, 09:00 AM
I suppose I could do it when the user closes the autoCAD.

I first check that they have saved and then create a dwf.

Do you no if it is actually possible to do in VBA code?

warren.medernach
2005-01-11, 02:33 PM
Hello barnesd.

Seeing how a DWF is created through a simple plot procedure, yes, you can generate a DWF from VBA...

Instead of firing this when AutoCAD closes or on a Save event... you might want to try firing it when the DWG closes...

Hope this helps
Warren M

mtuersley
2005-01-11, 05:05 PM
Unless he wants a multipage DWF, then he'd need to use SendCommand and access the -Publish command. For doing that, read my online column this month @ cadalyst.com

barnesd
2005-01-12, 10:37 AM
Hello Could you please send me the link to this article.

I cant seem to find it on the website.

waynes03
2005-01-12, 09:10 PM
Create a 'new' save button for this purpose. You could do this with a toolbar button and a couple of simple lines of AutoLISP.

Start by adding a page set-up in your template drawing called your.dwf, using a .dwf plot configuration.
Next, make a button. the dwf portion could look something like this-

(command "-plot" "N" "" "your.dwf" "" "" "" "")

I'm sure there's plenty of other ways. . Simple to sophisticated.

mtuersley
2005-01-18, 05:06 AM
Hello Could you please send me the link to this article.

I cant seem to find it on the website.


My bad! Wasn't posted til Saturday: http://tinyurl.com/4cxx9

mtuersley
2005-01-18, 05:24 AM
Create a 'new' save button for this purpose. You could do this with a toolbar button and a couple of simple lines of AutoLISP.

Start by adding a page set-up in your template drawing called your.dwf, using a .dwf plot configuration.
Next, make a button. the dwf portion could look something like this-

(command "-plot" "N" "" "your.dwf" "" "" "" "")

I'm sure there's plenty of other ways. . Simple to sophisticated.





While not entirely inaccurate, how does that help answer Daniel's question - AUTOMATICALLY creating a DWF? If you're going to post an answer, at least make it complete:

(command "-plot" "n" "whatever_layout" "" "DWF6 ePlot" "whatever.dwf" "n" "y"
"_qsave")

Here there is no need to do anything in the template and it saves when done, which was part of the original question. There are 2 problems with this solution though:

1. Daniel never states whether this is for him or others
2. Nor does he state if the layout name is consistant

If its for him, its up to him to click the button. If he needs others to do it, he's way better of trapping an event. If he has different layouts in each drawing, there's no way to automate it unless you do a bit more code.

barnesd
2005-01-18, 09:50 AM
This bit of code is not for me, It is something we wish to install on other machines as well. And the name will be different everytime, So we somehow need to grab the dwg name and create a dwf with this name.

I wish to do this code in VBA within AutoCAD. Do you think this will be possible?

Daniel

mtuersley
2005-01-18, 03:52 PM
Sure. You can read my articles on CADalyst for basic info on single and/or multi=page dwf output.

From there, you need to decide when this should occur. I'd use the Close event instead of when saving. Just add code to fire for that event and you'll have it.

Post back if you run into problems.

Good Luck!

barnesd
2005-01-27, 01:17 PM
Thanks for your help

I have got this code working to a certain extent but it displays the Publish Drawing Sheets form which I don;t really want it to do, I just want it to publish the DWF in the background and close.

I am using the following line, which I thought would turn off forms

.SetVariable "FILEDIA", 0

Thanks

Daniel

mtuersley
2005-01-27, 03:20 PM
You'd need to post more code to determine exactly. Here are some thoughts though:

1. Are you publish a multi-page dwf? If not, don't use Publish, use Print and a DWF driver
2. Might need to turn of CMDDIA [CMDDIA = 0]
3. You need to access the publish command using "-PUBLISH"
4. Make sure background processing is turned off [BACKGROUNDPLOT = 0]

barnesd
2005-01-27, 03:25 PM
I will sometimes be doing a multi-page DWF. Shall I do a check and see if its going to be a multi-page DWF use publish, but if not just use the print command.

Heres some of the code

Dim sTxt As String

'grab the drawing variables we need
dwgName = ThisDrawing.FullName
'check to make sure we have layouts
If cLayOuts.Count > 0 Then
'build the DSD file name
dsdFile = Replace(dwgName, ".dwg", ".dsd")
'build the DWF file name
d wfFile = Replace(dwgName, ".dwg", ".dwf")
' create the DSD file
If CreateDSDFile(cLayOuts, dsdFile, dwgName) = True Then
'publish our multipage DWF file
With ThisDrawing
sTxt = Replace(dsdFile, "\", "/")
'turn FILEDIA *OFF* to avoid dialog boxes
.SetVariable "FILEDIA", 0
.SetVariable "EXPERT", 0

.Regen acActiveViewport
'Publish layouts

sCommand = "(command " & Chr(34) & _
"QSAVE" & Chr(34) _
& ")" & vbCr

.SendCommand (sCommand)

sCommand = "(command " & Chr(34) & _
"_PUBLISH" & Chr(34) & _
" " & Chr(34) & sTxt & _
Chr(34) & " " & Chr(34) & " " & Chr(34) & ")" & vbCr

.SendCommand (sCommand)
End With
Else

mtuersley
2005-01-27, 07:10 PM
Okay. Replace "_PUBLISH" with "-PUBLISH" and add .SetVariable "BACKGROUNDPLOT", 0. Unless you are specifcally testing for the SAVE command, remove the QSAVE and just use .Save [NEVER use SendCommand unless you absolutely have to, which you don't here].

As for a single sheet, you can still use the publish command. I just wouldn't use it if you're always going to be kicking out single-page DWFs.

barnesd
2005-01-28, 11:10 AM
When setting the BACKGOUNDPLOT. I get an error saying. Error setting system variable.

Is there another setting i need to set before setting this.

Thanks very much for your help, I really do appretiate it. I am pretty new to CAD Development.

Daniel

Mike.Perry
2005-01-28, 11:16 AM
When setting the BACKGOUNDPLOT. I get an error saying. Error setting system variable.Hi

I don't know VBA, but I notice you missed an "R" in the above ie

BACKGOUNDPLOT should be BACKGROUNDPLOT

Could that be the problem (or was the above just a typo)?

Have a good one, Mike

barnesd
2005-01-28, 11:24 AM
Unfortunetly this was just a typo on the message board, But thanks for point it out.

mtuersley
2005-01-31, 02:46 PM
I don't believe so... post the portion of your code where you set it and whatever you do before that. Here's what I normally set:

With m_cadApp.ActiveDocument
.SetVariable("FILEDIA", 0)
.SetVariable("CMDDIA", 0)
.SetVariable("ATTREQ", 0)
.SetVariable("BACKGROUNDPLOT", 0)
End With

san_k4
2005-02-01, 04:43 AM
just check if this will help u...

To get your drg name u can try this code..
Filename=ThisDrawing.FullName

Also create a pc3 file for your dwf.
Then try this code to get a plot for pc3
result = ThisDrawing.Plot.PlotToFile(plotFileName, "c:\folder\pc3filename.pc3")

santhosh

mtuersley
2005-02-01, 06:26 AM
How does that help? He's having issues with setting a variable and pc3s have nothing to do with Publish

barnesd
2005-02-02, 11:33 AM
I got it working in 2005 using .SetVariable("BACKGROUNDPLOT", 0)

It still doesn't seem to work in 2004. It causes an error on the above .SetVariable line.

We have decided to just go with the 2005 version, So thanks very much for your help it has been very much appreaited.

Daniel.

warren.medernach
2005-02-02, 02:44 PM
HI Daniel.

You'll get an error on that line in 2004, because in 2004, there was no back ground plotting, hence no BACKGROUNDPLOT variable.

Hope this helps

Warren M