TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: baglover on August 05, 2019, 02:08:19 PM

Title: Page Setup problems
Post by: baglover on August 05, 2019, 02:08:19 PM
Hopefully the LISP geniuses here can help me.

After a new server was installed, all of our AutoCAD Page Setups stopped working.  The reason... our printer and plotters drivers were on the old server. Each device associated to a page setup, was linked to the old plotter.

The simple solution would be to have a LISP routine to change the location of where the printer/plotters get their drivers. After spending days reading and testing, this doesn't seem to be a feasible solution.

I've been able to delete all of the old page setups, and to load new updated page setups (with the same names and pointing to the new server) but the Current page setup, retains the name and still points to the old server.

What I think I need is a routine that will take the name of the existing page setup, set it as a variable. 

Then after loading the new page setups from a template, set the page setup to NONE.

And then set the page setup back to the name saved as a variable. Which hopefully reads the updated page setup info.

My understanding of basic LISP is limited, but I could not find a way to accomplish this. 

Any help would be appreciated.

-Brian-
Title: Re: Page Setup problems
Post by: ronjonp on August 05, 2019, 03:00:55 PM
Welcome to TheSwamp! See if this helps any:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ r)
  2.     ;; Store a list of ((configname . vlalayout))
  3.     (setq r (cons (cons (vla-get-configname x) x) r))
  4.     ;; Set to none
  5.     (vla-put-configname x "None")
  6.   )
  7.   ;; Import your page setups now
  8.   ;;
  9.   ;; Set name back to previous config <-not sure if this works
  10.   (foreach x r (vla-put-configname (cdr x) (car x)))
  11.   (princ)
  12. )
Title: Re: Page Setup problems
Post by: baglover on August 05, 2019, 04:43:58 PM
Thanks for the quick response.

I think it worked as I described, but unfortunately, it set the previous Page Setup name back into the Current Page Setup, but it did not update it with the new server location for the drivers.

Title: Re: Page Setup problems
Post by: 57gmc on August 06, 2019, 10:16:44 AM
Have you updated your pc3 files? They are what store the printer location. If your new pc3 files have the same name, you shouldn't need to update the page setups.
Title: Re: Page Setup problems
Post by: baglover on August 06, 2019, 01:03:59 PM
Yes, the .PC3's are updated.  What isn't updating is the Current Page Setup. 

It is keeping the page setup name it previously had, as well as the old plotter source.  In this case the replaced server.

I moved the ;; Import your pages setups now to above the defining the function "Foo" because it was not importing the page setups.

Does it need to be part of the "Foo" function?
Title: Re: Page Setup problems
Post by: ronjonp on August 06, 2019, 01:55:50 PM
Use something like so:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ r)
  2.     (vla-delete ps)
  3.   )
  4.     ;; Store a list of ((configname . vlalayout))
  5.     (setq r (cons (cons (vla-get-configname x) x) r))
  6.     ;; Set to none mot sure if this is doing anything .. might be causing problems?
  7.     (vla-put-configname x "Blank")
  8.   )
  9.   (vl-cmdf "-psetupin" "Server3.dwt" "*")
  10.   ;;
  11.   ;; Set name back to previous config <-not sure if this works
  12.   (foreach x r (vla-put-configname (cdr x) (car x)))
  13.   (princ)
  14. )

Although as mentioned, if you updated your pc3 files on the server AND they are in the same location AND have the same names as the old ones you should not have to do this?
Title: Re: Page Setup problems
Post by: 57gmc on August 06, 2019, 01:58:13 PM
In the pic below, the pc3 file is specified. Are you using new plotters with new names? As long as the plotter pc3 file has the same name as the one specified in the page setup, it should just work. If you changed plotters and the pc3 has a different name, I would recommend changing the page setups in your templates and then importing those page setups into your working file from the template.
Title: Re: Page Setup problems
Post by: baglover on August 06, 2019, 02:34:57 PM
I have updated ALL of the .PC3s on the new server.

All of them point to the proper location.

When I load the updated Page Setups, all of the .PC3s are pointing to the new server, except the "Current Page Setup" which points to the old location.

Now if this were for a few hundred files, I'd tell everyone, just re-select the Page Setup on the list that matches the Current Page Setup.

However, I have over 9,500 active drawing files right now, and I am trying to globally update them so I'm not taking a production hit for weeks.
Title: Re: Page Setup problems
Post by: ronjonp on August 06, 2019, 02:43:38 PM
Paste this code into your command line on one of your drawings that has an issue and post the results printed:
Code - Auto/Visual Lisp: [Select]
Title: Re: Page Setup problems
Post by: dgorsman on August 06, 2019, 03:08:39 PM
Look into the settings for DWGCONVERT.  There's some for dealing with named page set ups.
Title: Re: Page Setup problems
Post by: ronjonp on August 06, 2019, 03:13:19 PM
You could also try this .. in my mind the concept is sound but you'll have to test. Comments in the code so you know what's happening.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ d ps r)
  2.   ;; RJP » 2019-08-06
  3.   ;; Delete existing plot configs
  4.     (vla-delete x)
  5.   )
  6.   ;; Import new plot settings
  7.   (vl-cmdf "-psetupin" "Server3.dwt" "*")
  8.   ;; Get these new plot settings
  9.     (or (= 0 (vlax-get x 'modeltype)) (setq r (cons (cons (vla-get-configname x) x) r)))
  10.   )
  11.   ;; Go to modelspace
  12.   (setvar 'ctab "Model")
  13.   ;; Foreach layout
  14.     ;; Check if a tab has the same pageetup name in the list of new settings
  15.     (cond ((setq ps (cdr (assoc (vla-get-configname x) r)))
  16.            ;; Copy the new settings to the tab
  17.            (vl-catch-all-apply 'vla-copyfrom (list x ps))
  18.            ;; Refresh plot info
  19.            (vlax-invoke x 'refreshplotdeviceinfo)
  20.           )
  21.     )
  22.   )
  23.   (princ)
  24. )
Title: Re: Page Setup problems
Post by: baglover on August 06, 2019, 03:17:06 PM
Ronjonp - thanks again for all of the assistance.

Here are the results.

"\\\\rrj-s1\\OceTDS450"
"\\\\rrj-sbs2011\\CAD Copier BW KM C364" "\\\\rrj-sbs2011\\CAD Copier BW KM C364"


The first response I don't understand, as the Oce Plotter is not a page setup for the drawing I used.

Also, I do not have an RRJ-S1 server, so I have no idea where that info is coming from.



Title: Re: Page Setup problems
Post by: baglover on August 06, 2019, 03:20:15 PM
DGORSMAN,

I started with the DWGCONVERT command, but I could not get it to update the "CURRENT PAGE SETUP".

If I don't update that, then my batch update solution only half works.

Thanks for the suggestion.
Title: Re: Page Setup problems
Post by: baglover on August 06, 2019, 03:48:11 PM
ronjonp,

The last version of FOO that you posted crashes in Model Space with the following error:

-psetupin Enter file name: Server3.dwt Enter user defined page setup(s) to import or [?]: *
Command: Regenerating model - caching viewports.
; error: Too many actual parameters

Title: Re: Page Setup problems
Post by: ronjonp on August 06, 2019, 04:00:50 PM
Ronjonp - thanks again for all of the assistance.

Here are the results.

"\\\\rrj-s1\\OceTDS450"
"\\\\rrj-sbs2011\\CAD Copier BW KM C364" "\\\\rrj-sbs2011\\CAD Copier BW KM C364"


The first response I don't understand, as the Oce Plotter is not a page setup for the drawing I used.

Also, I do not have an RRJ-S1 server, so I have no idea where that info is coming from.
Just a guess but if your server name is hardcoded into the config name then it might be as easy as stripping the path and appending the name of the new server like so ( untested ).
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ i srv str)
  2.   ;; RJP » 2019-08-06
  3.   (if (setq srv (getenv "logonserver"))
  4.       ;; Name does not already have the new server in it
  5.       (cond ((and (not (vl-string-search srv (setq str (vla-get-configname x))))
  6.                   ;; AND it has a path
  7.                   (setq i (vl-string-position (ascii "\\") str 0 t))
  8.              )
  9.              ;; Strip the path and append the new server name
  10.              (vla-put-configname x (strcat srv (substr str (1+ i))))
  11.             )
  12.       )
  13.     )
  14.     (print "Logon Server name not defined!")
  15.   )
  16.   (princ)
  17. )
Title: Re: Page Setup problems
Post by: ronjonp on August 06, 2019, 04:03:27 PM
ronjonp,

The last version of FOO that you posted crashes in Model Space with the following error:

-psetupin Enter file name: Server3.dwt Enter user defined page setup(s) to import or [?]: *
Command: Regenerating model - caching viewports.
; error: Too many actual parameters
Ooops .. had a typo. Revised code in original post.
Title: Re: Page Setup problems
Post by: baglover on August 06, 2019, 04:27:27 PM
ronjonp,

Reassigning, or stripping, the server info out and replacing it was my first thought, but I wasn't able to figure out how to do it.

Unfortunately your routine returned an error:

; error: Automation Error. Invalid input

Title: Re: Page Setup problems
Post by: ronjonp on August 06, 2019, 04:35:45 PM
Can you post a sample drawing so I have something to test on? Just been coding blind :)

From the help file:
Quote
Remarks
This property does not take a fully qualified path, only the file name for the configuration file. Use the PrinterConfigPath property to specify the path for printer configuration files.

Use the RefreshPlotDeviceInfo method before trying to change the ConfigName property.

Do not assign the ConfigName property a value of "None." Attempting to do so results in unexpected behavior.

That being said just try refreshing the plot device info:

Code - Auto/Visual Lisp: [Select]

*face meet palm*

Title: Re: Page Setup problems
Post by: baglover on August 06, 2019, 05:33:15 PM
ronjonp

Attached is a sample 8 1/2" x 11" Portrait drawing and the Server3 template file where the updated page setups are stored.

Thanks again for looking at this.

Title: Re: Page Setup problems
Post by: 57gmc on August 06, 2019, 06:07:35 PM
That being said just try refreshing the plot device info:

Hey Ron, if you used the CopyFrom method on the ActiveLayout, it should fix the problem, setting it to a named page setup.
Title: Re: Page Setup problems
Post by: ronjonp on August 06, 2019, 06:21:44 PM
ronjonp

Attached is a sample 8 1/2" x 11" Portrait drawing and the Server3 template file where the updated page setups are stored.

Thanks again for looking at this.
Your printer names are NOT the same:
Old server: "\\rrj-sbs2011\CAD Copier BW KM C364"
New server: "\\rrj-s3\Willowbrook CAD Copier Color KM C364"

Title: Re: Page Setup problems
Post by: baglover on August 07, 2019, 09:53:11 AM
I understand that the printers were renamed (something I recommended against) but the names of the Page Setups are the same.

I guess this isn't as simple as substituting "Old Current Page Setup Name" with "New Page Setup Name".

At this point I am able to globally delete the old page setups and import the new page setups. 

If what I need is a LISP routine that will need to update both the "Device Name" as well as "Where" it pulls the driver from, then this goes beyond asking for assistance.

Thanks everyone for your suggestions and your effort.
Title: Re: Page Setup problems
Post by: ronjonp on August 07, 2019, 12:19:55 PM
The issue is finding what pagesetup name is tied to what tab. I could not find a way to do that.
If that part of the problem gets solved, then the copyfrom method should work as mentioned.
Title: Re: Page Setup problems
Post by: baglover on August 07, 2019, 12:48:09 PM
ronjonp

I appreciate all you have done so far.

The only way that I know of to get the page setup name for each tab is the Field PageSetupName (%<\AcVar PageSetupName>%) but I've not been able to work that back into the routine.

Title: Re: Page Setup problems
Post by: 57gmc on August 07, 2019, 01:13:58 PM
The layout doesn't store the name of the page setup used to set the current settings. The CopyFrom method doesn't copy the name of the page setup to the Layout. It only copies the settings to the layout. You just have to choose a page setup to make current. If you are going to batch the files, choosing a page setup for all the files shouldn't be a problem.
Title: Re: Page Setup problems
Post by: ronjonp on August 07, 2019, 02:05:29 PM
The layout doesn't store the name of the page setup used to set the current settings. The CopyFrom method doesn't copy the name of the page setup to the Layout. It only copies the settings to the layout. You just have to choose a page setup to make current. If you are going to batch the files, choosing a page setup for all the files shouldn't be a problem.
Ageed. The idea was to see what was used last and match it. Picking a default would be much easier :)
I guess I could compare a list of properties using vl-every for the tabs and the imported pagesetups to get a 'match'.
Title: Re: Page Setup problems
Post by: 57gmc on August 07, 2019, 02:56:12 PM
The layout doesn't store the name of the page setup used to set the current settings. The CopyFrom method doesn't copy the name of the page setup to the Layout. It only copies the settings to the layout. You just have to choose a page setup to make current. If you are going to batch the files, choosing a page setup for all the files shouldn't be a problem.
Ageed. The idea was to see what was used last and match it. Picking a default would be much easier :)
I guess I could compare a list of properties using vl-every for the tabs and the imported pagesetups to get a 'match'.
That could work. However, I was responding more to the OP. If you can get him to agree, your job would be simpler. Personally, in my office, I don't worry about updating existing dwgs. I have a routine that performs the update to a standard via one click. So its not a loss of productivity to have users do the update as needed.
Title: Re: Page Setup problems
Post by: baglover on August 07, 2019, 03:17:45 PM
Resetting the Current Page Setup to one "Default" page setup would work. 

That was the thinking behind creating the BLANK page setup in the template file. 

Its not as efficient as updating the Current Page Setup to the proper setting, but most of these drawings are legacy drawings which will never be opened/plotted again.  I just can't tell you which ones those are. 

So I can update the drawings right now, because I can delete the old page setups, and import the new update ones.  Though I'll probably wait and do it over the weekend just to be sure I'm not trying to update a drawing someone is using.

I was just thinking if the final hurtle could be cleared, my users wouldn't have to do anything when they plot an older drawing.