Alaskachick Posted January 2, 2010 Share Posted January 2, 2010 I am the noob at work and have been tasked with updating several hundred files. I know this can be automated and I have figured out a script for most the tasks (thanks to this forum), but I am hung up on modifying the existing page layout with a script. My tasks are: change a date in the TB, paste in a block, modify the page layout, zoom extents, purge all, qsave & close. I am going to do the TB manually, because each one is different. Here is the script I have so far: _pasteclip 0,0 -purge all * n zoom extents _qsave close The next step is to add modifying the page layout to the script. Is there are way to stop the page layout manager from opening a window? I need to learn the commandline prompts/answers for each part of the set up and can't stop the window from opening. I have changed FILEDIA to 0 to no avail. Here is the page layout setup I need: Plot style table: None Printer/plotter: None Paper Size: ANSI D (34.00 x 22.00 Inches) Plot Area: Extents Plot Offset: Center the plot Plot Scale: Fit to paper Drawing Orientation: Landscape I know LISP is probably a better way, but I can't wrap my head around it in a weekend, so I will stick with the simpler script option. Currently I am typing SCRIPT, then the file name and when I hit enter it works. I assume that is the best way, but please correct me if I can do it easier. Thanks! Quote Link to comment Share on other sites More sharing options...
lpseifert Posted January 2, 2010 Share Posted January 2, 2010 Maybe... Create a drawing with a pagesetup using the parameters you need with the same name as the one you want to overwrite. Then use the lisp found here to import the new pagesetup. The lisp can be incorporated to run in your script by adding lines something similar to these (load "Lispfilename")[color=Red][i] the name of the lisp file, be sure it's in your path[/i][/color] (AT:Pagesetups "DrawingFileName.dwg") [i][color=Red]the name of the dwg with the new pagesetup [/color][/i] If you use Scriptpro, you can run your script over multiple dwgs; you can find it here Quote Link to comment Share on other sites More sharing options...
Alaskachick Posted January 2, 2010 Author Share Posted January 2, 2010 A question: if I have to open every document to check if the date needs correcting would scriptpro really save me time b/c it has to open every file again right? Lisp scares me. I will try to get over it, but I have never programmed anything before and messing up these files kinda worries me. I need to be employed longer than 2 weeks before I REALLY mess something up. Quote Link to comment Share on other sites More sharing options...
lpseifert Posted January 2, 2010 Share Posted January 2, 2010 Don't be afraid... lisp is your friend- anyway someone else (alanjt) did the programming already. Quote Link to comment Share on other sites More sharing options...
Alaskachick Posted January 3, 2010 Author Share Posted January 3, 2010 Lisp is my friend. Lispismyfriend. lisp=friend. Got it. Ok, I think I set it up as I'm supposed to, and everything in the script works except the lisp. Here is the script: _pasteclip 0,0 (load "PageSetups.lsp") -purge all * n zoom extents _qsave Here is the Lisp which I have copied into a txt document, saved as Pagesetup.lsp in the same folder the .scr file is located: ;;; Insert all Page Setups into drawing (will overwrite if exists) ;;; #DrawingFile - name of DWG file from which to import ;;; Alan J. Thompson, 07.29.09 (defun AT:PageSetups (#layout1) (if (findfile #layout1) (progn (command "_.psetupin" (findfile #layout1) "*") (while (wcmatch (getvar "cmdnames") "*PSETUPIN*") (command "_yes") ) ;_ while T ) ;_ progn ) ;_ if ) ;_ defun I have a drawing file called layout1.dwg saved in the same folder and the only thing in it is a layout1 tab set up to the parameters I want. When I run the script the lisp section looks like this: Command: (load "PageSetups.lsp") AT:PAGESETUPS then it goes on to the next task and nothing changes with the page layout. What have I missed? Quote Link to comment Share on other sites More sharing options...
wizman Posted January 3, 2010 Share Posted January 3, 2010 Try if this work(untested), you missed running the lisp file. _pasteclip 0,0 (load "PageSetups.lsp") (AT:Pagesetups "layout1.dwg") -purge all * n zoom extents _qsave if above does not work because of lisp file called inside a script, try editing the lisp file shown below to automatically run once loaded then run your script in post #5: ;;; Insert all Page Setups into drawing (will overwrite if exists) ;;; #DrawingFile - name of DWG file from which to import ;;; Alan J. Thompson, 07.29.09 (defun AT:PageSetups (#layout1) (if (findfile #layout1) (progn (command "_.psetupin" (findfile #layout1) "*") (while (wcmatch (getvar "cmdnames") "*PSETUPIN*") (command "_yes") ) ;_ while T ) ;_ progn ) ;_ if ) ;_ defun [b](at:pagesetups "layout1.dwg") ;<-- add this[/b] Quote Link to comment Share on other sites More sharing options...
Alaskachick Posted January 3, 2010 Author Share Posted January 3, 2010 Wow, everything works except that the lisp doesn't make the changed layout the current layout. I still have to go into the page setup manager and select "set current" on the named layout1. Here is what shows up when I run the script and it gets to the lisp command Command: (load "PageSetups.lsp") _.psetupin Enter file name: C:\Documents and Settings\Teal Ehmann\my documents\autocad\layout1.dwg Enter user defined page setup(s) to import or [?]: * Command: T Command: (AT:Pagesetups "layout1.dwg") _.psetupin Enter file name: C:\Documents and Settings\Teal Ehmann\my documents\autocad\layout1.dwg Enter user defined page setup(s) to import or [?]: * Page setup "layout1" already exists. Redefine it? [Yes/No] : _yes Command: T then it goes back to the script and does everything else right. How do I set the correct named layout current? (the current page setup is ) Thank you for your patience & help! Quote Link to comment Share on other sites More sharing options...
Alaskachick Posted January 3, 2010 Author Share Posted January 3, 2010 Note: One programming shortcoming is a way to set a page setup as current. There does not seem to be a way in either VBA or AutoLISP/VisualLisp to perform this setting. The only way seems to be to invoke the command line version of the Plot command (either in a script or in LISP) and set the page setup there. AutoCAD Printing Made Easy, Part 2 Author: Steven LaKose, CAD & CompanyDate Published: June 11, 2009 I found this quote at au.university and his comment at the end about setting the page setup current seems to be the exact problem I have. But I don't want to plot. I just want to set the layout1 page setup current and save, close etc. Quote Link to comment Share on other sites More sharing options...
wizman Posted January 3, 2010 Share Posted January 3, 2010 add this to your script: (command "._plot" "_n" (GETVAR 'CTAB) "layout1" "" "" "_y" "_n") He's wrong see Lee's code below: Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 3, 2010 Share Posted January 3, 2010 Wiz, might this work? (defun SetPSAllLayouts (setup / doc) (if (not (vl-catch-all-error-p (setq setup (vl-catch-all-apply (function vla-item) (list (vla-get-PlotConfigurations (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))) setup))))) (vlax-map-collection (vla-get-layouts doc) (function (lambda (x) (if (eq :vlax-false (vla-get-Modeltype x)) (vla-CopyFrom x setup))))))) Or for single layout: (defun SetPS (lay setup / itemp) (defun itemp (collection item / result) (if (not (vl-catch-all-error-p (setq result (vl-catch-all-apply (function vla-item) (list collection item))))) result)) (setq *acad* (cond (*acad*) ((vlax-get-acad-object))) *doc* (cond (*doc* ) ((vla-get-ActiveDocument *acad*)))) (and (setq lay (itemp (vla-get-layouts *doc*) lay)) (setq setup (itemp (vla-get-PlotConfigurations *doc*) setup)) (not (vla-copyfrom lay setup)))) Quote Link to comment Share on other sites More sharing options...
wizman Posted January 3, 2010 Share Posted January 3, 2010 Yes lee, it works right, thanks...'-) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 3, 2010 Share Posted January 3, 2010 Yes lee, it works right, thanks...'-) Cool thanks dude Quote Link to comment Share on other sites More sharing options...
Alaskachick Posted January 3, 2010 Author Share Posted January 3, 2010 this may be a wimpy choice, but wimpy is ok with me. I put "pagesetup" in my script right before zoom extents and when I run the script the dialog box pops up, I click layout1, set current, close then the script finishes and I am done. I went from lots of clicks to 3 clicks. So, now my script looks like this: _pasteclip 0,0 (load "PageSetups.lsp") (AT:Pagesetups "layout1.dwg") -purge all * n pagesetup zoom extents _qsave I won't be able to use scriptpro, but I can't go all fancy on them too early. I am a little suprised none of the more experienced drafters can write scripts or lisp. Maybe this is a test for the new chick to see if she can come up with something useful and they are all sitting back laughing at me...let's hope not. Anyways, thanks for helping me look good. lol Quote Link to comment Share on other sites More sharing options...
Alaskachick Posted January 3, 2010 Author Share Posted January 3, 2010 Or for single layout: (defun SetPS (lay setup / itemp) (defun itemp (collection item / result) (if (not (vl-catch-all-error-p (setq result (vl-catch-all-apply (function vla-item) (list collection item))))) result)) (setq *acad* (cond (*acad*) ((vlax-get-acad-object))) *doc* (cond (*doc* ) ((vla-get-ActiveDocument *acad*)))) (and (setq lay (itemp (vla-get-layouts *doc*) lay)) (setq setup (itemp (vla-get-PlotConfigurations *doc*) setup)) (not (vla-copyfrom lay setup)))) If I did use this, where would I put it? In my script? or in the page setup lisp I am using? These docs are all going to be sent out to the client--none of this will link back to the original layout document will it? Quote Link to comment Share on other sites More sharing options...
wizman Posted January 3, 2010 Share Posted January 3, 2010 i recommend using scriptpro, you'll get to learn it easily. i don't use it now because i'm not in the mass production of drawings in this company but before it has been very useful. Good thing about it is dialog box prompt suppression, time out if an error occurs so it will continue to process the next drawing, monitor the progress of a script and a report at the end of which ones are succesfull and not. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 3, 2010 Share Posted January 3, 2010 These docs are all going to be sent out to the client--none of this will link back to the original layout document will it? No, the LISP is just providing an automation to what you would do manually. If I did use this, where would I put it? In my script? or in the page setup lisp I am using? You would need to know the name of the pagesetup that you want to set current, and whether you want it current in all layouts or just a few. Example: (load "SetPSAllLayouts.lsp") (SetPSAllLayouts "Setup Name") Or (load "SetPS.lsp") (SetPS "Layout1" "Setup Name") Assuming you are naming the LISP files in that way. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 3, 2010 Share Posted January 3, 2010 Why not do all the operations in one LISP, and call it from the Script? It will be more robust, quicker, and will save loading each individual LISP Something like this: (defun DoScriptOperations (/ *error* AT:PageSetups SetPSAllLayouts vl ov) (defun *error* (msg) (and ov (mapcar 'setvar vl ov)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ)) (setq *acad* (cond (*acad*) ((vlax-get-acad-object))) *doc* (cond (*doc) ((vla-get-ActiveDocument *acad*)))) ;;; Insert all Page Setups into drawing (will overwrite if exists) ;;; #DrawingFile - name of DWG file from which to import ;;; Alan J. Thompson, 07.29.09 (defun AT:PageSetups (#layout1) (if (findfile #layout1) (progn (command "_.psetupin" (findfile #layout1) "*") (while (wcmatch (getvar "cmdnames") "*PSETUPIN*") (command "_yes")) T))) (defun SetPSAllLayouts (setup / doc) (if (not (vl-catch-all-error-p (setq setup (vl-catch-all-apply (function vla-item) (list (vla-get-PlotConfigurations (setq *doc* (cond (*doc*) ((vla-get-ActiveDocument (vlax-get-acad-object)))))) setup))))) (vlax-map-collection (vla-get-layouts doc) (function (lambda (x) (if (eq :vlax-false (vla-get-Modeltype x)) (vla-CopyFrom x setup))))))) (setq vl '("CMDECHO" "OSMODE") ov (mapcar 'getvar vl)) (mapcar 'setvar vl '(0 0)) ;; ------------ Start Here ----------------------------- (vl-cmdf "_.pasteclip" "0,0") (AT:PageSetups "[color=Red]layout1.dwg[/color]") ;; Change this if necessary (repeat 3 (vla-purgeall *doc*)) (setPSAllLayouts "[color=Red]Setup Name[/color]") (vla-ZoomExtents *acad*) (if (eq "" (vla-get-FullName *doc*)) (vla-saveas *doc* (strcat (vla-get-Path *doc*) "\\" (vla-get-name *doc*))) (vla-save *doc*)) ;; ------------ End Here ----------------------------- (mapcar 'setvar vl ov) (princ)) Then in the script: open "C:\\....dwg" (load "DoScriptOperations.lsp") (DoScriptOperations) close Just a thought, Lee (PS> Change parts that are marked in red to what suits you). Quote Link to comment Share on other sites More sharing options...
Alaskachick Posted January 3, 2010 Author Share Posted January 3, 2010 You would need to know the name of the pagesetup that you want to set current, and whether you want it current in all layouts or just a few. (load "SetPS.lsp") (SetPS "Layout1" "Setup Name") I want to set pagesetup "layout1" current. I only have 1 paper space tab called "Layout1" that I want the pagesetup applied to. Holy cow! I go to eat breakfast and come back to a whole new plan! Which does sound good. Let me go try it. Quote Link to comment Share on other sites More sharing options...
Alaskachick Posted January 3, 2010 Author Share Posted January 3, 2010 sigh, I think I am remedial in this catagory. I haven't had this class in school yet! well, I keep getting an "Invalid File Name" error with the new lisp in my script. I switched my lsp & scr files to my thumb drive because that is what I will use at work and my home file path had spaces in it. So, now, the script reads: _pasteclip 0,0 open "F:\\LISP\LISPETC\layout1.dwg" (load "DoScriptOperations.lsp") (DoScriptOperations) close -purge all * n zoom extents _qsave and the lsp code looks like this: (defun DoScriptOperations (/ *error* AT:PageSetups SetPSAllLayouts vl ov) (defun *error* (msg) (and ov (mapcar 'setvar vl ov)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ)) (setq *acad* (cond (*acad*) ((vlax-get-acad-object))) *doc* (cond (*doc) ((vla-get-ActiveDocument *acad*)))) ;;; Insert all Page Setups into drawing (will overwrite if exists) ;;; #DrawingFile - name of DWG file from which to import ;;; Alan J. Thompson, 07.29.09 (defun AT:PageSetups (#layout1) (if (findfile #layout1) (progn (command "_.psetupin" (findfile #layout1) "*") (while (wcmatch (getvar "cmdnames") "*PSETUPIN*") (command "_yes")) T))) (defun SetPSAllLayouts (setup / doc) (if (not (vl-catch-all-error-p (setq setup (vl-catch-all-apply (function vla-item) (list (vla-get-PlotConfigurations (setq *doc* (cond (*doc*) ((vla-get-ActiveDocument (vlax-get-acad-object)))))) setup))))) (vlax-map-collection (vla-get-layouts doc) (function (lambda (x) (if (eq :vlax-false (vla-get-Modeltype x)) (vla-CopyFrom x setup))))))) (setq vl '("CMDECHO" "OSMODE") ov (mapcar 'getvar vl)) (mapcar 'setvar vl '(0 0)) ;; ------------ Start Here ----------------------------- (vl-cmdf "_.pasteclip" "0,0") (AT:PageSetups "layout1.dwg") ;; Change this if necessary (repeat 3 (vla-purgeall *doc*)) (setPSAllLayouts "layout1") (vla-ZoomExtents *acad*) (if (eq "" (vla-get-FullName *doc*)) (vla-saveas *doc* (strcat (vla-get-Path *doc*) "\\" (vla-get-name *doc*))) (vla-save *doc*)) ;; ------------ End Here ----------------------------- (mapcar 'setvar vl ov) (princ)) Unfortunetly, I am out of time today to keep working on this. I think I will go back to the script & lisp that succeeded in updating the pagesetup and I only had 3 clicks. Thank you for all your help! I learned more about all this in the last 3 days than I ever thought possible. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 3, 2010 Share Posted January 3, 2010 Your filename needs to use double backslashes: "F:\\LISP\\LISPETC\\layout1.dwg" EDIT: I may be wrong, in LISP you need double backslashes, for a script try forward slashes. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.