Jump to content

Recommended Posts

Posted

We have a set of dwt we use to plot drawings on different formats. The dwt were set to print with a defined printer, but now we got a new printer and whenever we need to print old drawings, we have to select the new printer for each single layout.

I tried to build a program in VBA that would recognize the dwt which would be printed with the old printer and then change their nameconfiguration. The result is the dwt are being printed with the new printer but the layout size has changed!

 

I know I can update the printer for future use by simply changing the dwt, but we constantly need to refer to old drawings, and setting the printer for each single one is a time consuming task.

 

Any help?

Posted

Try this (for Active Layout):

 

;; DvcName  =  Name of Plot Device

(defun PutPlotDevice (DvcNme)
 (vl-load-com)
 ;; Lee Mac  ~  14.01.10
 
 (setq lay (vla-get-ActiveLayout
             (vla-get-ActiveDocument
               (vlax-get-acad-object))))
 
 (vla-RefreshPlotDeviceinfo lay)

 (if (vl-position (strcase DvcNme)
       (mapcar (function strcase)
         (vlax-safearray->list
           (vlax-variant-value
             (vla-getPlotDeviceNames lay)))))

   (not (vl-catch-all-error-p
          (vl-catch-all-apply
            (function vla-put-configname)
              (list lay DvcNme))))))

Posted

As rkmcswain said, I have created a toolbar that has buttons for different sizes of plot on any of four different plotters; this is all done with macros not lisp so that it can be used with LT. (One set of these buttons has to call scripts where the print driver is on the server but thats no great problem).

One click of a button sends the right size plot to the plotter I want no matter what the previous pagesetup says.

 

If you want I can post examples when Im back in work tomorrow.

Posted

Thank you guys, but what I am really looking for is a VBA routine that will change all layouts printer settings without activating each one of them. I have hundreds of drawings with 40- 50 layouts each and If I need to click on every single layout, I can as well just type in "plot", change the printer and click on "apply to layout".

Here I pasted a simplified version of the VBA program I made. It does change the printer device but it won't keep the original papersize.

 

 

Dim lcount As Integer

Dim i As Integer

Dim lay As AcadLayout

 

lcount = ThisDrawing.Layouts.Count

 

For i = 0 To (lcount - 1)

 

Set lay = ThisDrawing.Layouts(i)

 

If lay.ConfigName = "old printer" Then

lay.ConfigName = "new printer"

End If

 

Next i

Posted

I wouldn't necessarily use VBA, especially if you plan on using this in the future. VBA has been dead for some time now and if you move to 64-bit, the emulator (or whatever you want to call it) to make VBA work also comes with a severe performance penalty .

 

Start with Lee's lisp code and wrap that with a loop to work on all viewports, and then wrap that with a loop to work on all drawings (using ObjectDBX) - to allow you to modify an unlimited number of drawings with one command.

Posted

This should work for all layouts, its a little time consuming, as the RefreshPlotDeviceInfo method takes a while.

 

;; DvcNme  =  Name of Plot Device

(defun PutPlotDevice_AllLayouts (DvcNme)
 (vl-load-com)
 ;; Lee Mac  ~  15.01.10

 (vlax-for lay (vla-get-layouts
                 (vla-get-ActiveDocument (vlax-get-acad-object)))

   (vla-RefreshPlotDeviceInfo lay)

   (if (vl-position (strcase DvcNme)
         (mapcar (function strcase) (vlax-invoke lay 'GetPlotDeviceNames)))

     (vla-put-configname lay DvcNme)))

 (princ))

Posted
(using ObjectDBX)

 

ObjectDBX is great for its speed, but as there would be a (vla-save dbx_doc) involved in this, it is a hassle to implement the Arx code to keep the Thumbnail.. :geek:

Posted

Thank you rkmcswain,

but all I need is a temporary solution for a temporary problem. I am already working on 64-bit, I do have some problems sometimes using VBA but nothing really serious. A lisp code to work on all viewports? I don't know what you mean, as I said my problem is with the layout papersize not with viewports. I am not aquainted with lisp, but I would give a try to Lee Mac's lisp if it would allow me to do the job without activating every single layout. VBA dead? I don't think so, otherwise this forum would not mention it. I am studying about Visual Basic and opther applications but I don't know enough yet, that's why I think a simple VBA routine will solve my temporary problem.

Posted
Thank you rkmcswain,

but all I need is a temporary solution for a temporary problem. I am already working on 64-bit, I do have some problems sometimes using VBA but nothing really serious. A lisp code to work on all viewports? I don't know what you mean, as I said my problem is with the layout papersize not with viewports. I am not aquainted with lisp, but I would give a try to Lee Mac's lisp if it would allow me to do the job without activating every single layout. VBA dead? I don't think so, otherwise this forum would not mention it. I am studying about Visual Basic and opther applications but I don't know enough yet, that's why I think a simple VBA routine will solve my temporary problem.

 

Layouts are Viewports in LISP :)

 

VBA is definitely dead - or heading that way, 2010 no longer has it as standard and as RKMcSwain says, 64-bit has performance problems.

 

My code above will set the Plot Device for all layouts (without activating them) - you could use it in a script to iterate over drawings, or in ObjectDBX.

 

Lee

Posted

A lisp code to work on all viewports? I don't know what you mean, as I said my problem is with the layout papersize

My bad. I meant layouts.

 

VBA dead? I don't think so, otherwise this forum would not mention it.

From a support standpoint, yes you can still run VBA code in AutoCAD, but Microsoft killed it off back in 2007, so there is no reason to start writing VBA code today for a new project.

 

 

Layouts are Viewports in LISP :)

 

VBA is definitely dead - or heading that way, 2010 no longer has it as standard and as RKMcSwain says, 64-bit has performance problems.

Posted
ObjectDBX is great for its speed, but as there would be a (vla-save dbx_doc) involved in this, it is a hassle to implement the Arx code to keep the Thumbnail.. :geek:

 

True. You would have to weigh the loss of thumbnails vs. the ability to process hundreds or thousands of drawings very quickly. I couldn't care less about thumbnails myself. 8)

Posted
True. You would have to weigh the loss of thumbnails vs. the ability to process hundreds or thousands of drawings very quickly. I couldn't care less about thumbnails myself. 8)

 

Me neither - but you can't tell how some people will react.. o:)

Posted

Again, I work both with autocad 2010 and 64-bit, no problems so far with VBA.

I must confess I am a bit confused, you guys say VBA is dead but when I look for VBA tips I can always (or most of the times) find them here...

Perhaps VBA might be dead indeed but there are still plenty of people out there who still use it. I personally don't mind changes or learning new programs, but as my work requires more engineering than drawing, I am struggling to find enough time to keep up with Autocad new programming tools.

Anyway, I have not yet found any application which would allow me to use userforms (or windows), except for VBA. If you know any way, please let me know, I would certainly like to learn about it.

Thank you Lee Mac for the lisp code, though what I am trying to work out is a bit more complexed, as I have layouts printing on different printers to match the format. So I would like my program to find first the layouts printing on the old device and then change only those ones amongst the many others printing on different printers.

Posted

You can create dialogs with DCL to run with LISP, and many other languages also support dialog creation.

 

VBA is getting phased out of AutoCAD, as Microsoft is no longer supporting it but yes, there are those that still use it.

 

ex.png

Posted

I must confess I am a bit confused, you guys say VBA is dead but when I look for VBA tips I can always (or most of the times) find them here...

I'm not sure why that is confusing. VBA has been used with AutoCAD for the last decade, so of course there will be tips here and other places, but that has nothing to do with the current state or future of this technology.

 

Perhaps VBA might be dead indeed but there are still plenty of people out there who still use it.

Certainly, and people will probably keep using it for many more years, as long as you are using a version of AutoCAD that supports it, there is no problem. But expect many other users to move on over the years, which means less and less support out there in the world. My guess is that this spring, or maybe next spring (AutoCAD 2011 or 2012), VBA will be removed entirely from AutoCAD.

 

The program(s) you are using must not be very large if you can't see a speed difference when running them in 64-bit. My testing (along with others) shows it's about 10X slower which makes sense, since the code is being run though a emulator since there is no direct support for VBA in 64-bit systems.

 

Anyway, I have not yet found any application which would allow me to use userforms (or windows), except for VBA. If you know any way, please let me know, I would certainly like to learn about it.

I can't think of any language that does not support dialogs. Lisp, .NET, C++/ARx all support dialogs.
Posted

I managed to make my program working as I wanted. Actually it was quite simple, I just needed to use a macro to load the page setup together with the VBA, then assign the specific page setup to the layouts. It works great.

 

I didn't know about DCL, I will look into it.

Bedankt!

  • 4 years later...
Posted

Dear Lee,

 

I try using this code. But maybe something is wrong with my modified code.

 

Please help me to rectify.

 

(defun c:P2PDF (DWG To PDF.pc3)

(vl-load-com)

;; Lee Mac ~ 15.01.10

 

(vlax-for lay (vla-get-layouts

(vla-get-ActiveDocument (vlax-get-acad-object)))

 

(vla-RefreshPlotDeviceInfo lay)

 

(if (vl-position (strcase DWG To PDF.pc3)

(mapcar (function strcase) (vlax-invoke lay 'GetPlotDeviceNames)))

 

(vla-put-configname lay DWG To PDF.pc3)))

 

(princ))

[\code]

Posted

Dear,

 

I try but fail. I get this error " ; error: too few arguments"

 

(defun c:P2PDF ("DWG To PDF.pc3")
 (vl-load-com)
 ;; Lee Mac  ~  15.01.10

 (vlax-for lay (vla-get-layouts
                 (vla-get-ActiveDocument (vlax-get-acad-object)))

   (vla-RefreshPlotDeviceInfo lay)

   (if (vl-position (strcase "DWG To PDF.pc3")
         (mapcar (function strcase) (vlax-invoke lay 'GetPlotDeviceNames)))

     (vla-put-configname lay "DWG To PDF.pc3")))

 (princ))

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...