[ Usenet FAQs | Web FAQs | Documents | RFC Index ]
Part1 - Part2 - Single Page
Top Document: comp.cad.autocad AutoLISP FAQ (part 2/2) - samples, code
Previous Document: [20] General helper functions
Next Document: [21.8] How to write XYZ data of selected objects to a file?
-
Search the FAQ Archives
Part1 - Part2 - Single Page
Top Document: comp.cad.autocad AutoLISP FAQ (part 2/2) - samples, code
Previous Document: [20] General helper functions
Next Document: [21.8] How to write XYZ data of selected objects to a file?
[21] Sample Lisp Programs:
[21.1] Globally change texts, polylines, layer utils, datestamp For globally changing text attributes use CHTEXT.LSP in your sample directory. For globally changing polyline attributes, freeze layers by pick and other similar tasks search for free lisp tools at any AutoLISP site. See "[1]" and some code at "[22]","[23]","[24]" For putting a datestamp and others onto your plots automatically first check out if your plotter supports HPGL/2. Then use the internal HPGL/2 driver and configure the datestamp in HPCONFIG. DATESTAMP.LSP: Change the plot header attributes by yourself as in [22.2]. A profi plotstamp routine is here: http://ourworld.compuserve.com/homepages/tonyt/plotstmp.htm ------------------------------ [21.2] Plot dialog from within Lisp. Using DDE or ActiveX or initdia (initdia)(command "_PLOT") Calling the PLOT dialogbox from AutoLISP *before R14* was possible only under Windows i.e. with LISPPLOT by Mike Dickason. This fed the keyboard buffer with keystrokes. http://www.cadalog.com/ files/lispd-l/lspplw.zip or also: ftp://ftp.mcwi.com/pub/mcwi/lisp/winplt.lsp Otherwise create a script and call this at the end of your lisp, but this will not show up the dialogbox. Xiang Zhu: You could have used "DDELISP" under Windows. [shortened] ;;; [fixed for all releases] (defun DDECMD (str / tmp acadver ddestr) (if (not (boundp 'initiate)) (cond ((= 14 (setq acadver (atoi (getvar "ACADVER")))) (setq ddestr "AutoCAD.R14.DDE") (arxload "ddelisp")) ((= 13 acadver) (setq ddestr "autocad.r13.dde") (xload "ddelisp")) ((= 12 acadver) (setq ddestr "autocad.dde") (xload "ddelisp")) (T (princ "DDE not supported")(exit)))) (if (not (zerop (setq tmp (initiate ddestr "system")))) (progn (execute tmp (strcat "[" str "]")) (terminate tmp) str))) (ddecmd "_plot ") ; return would be "^13" Beware that Acad accepts only DDE commands if the command line is active, that means no dialogbox must be open. With vlisp/ViLL ActiveX methods can be used to plot, but the dialog can not be called: ;;; vlisp syntax: (setq vlax:ActiveDocument (vla-get-ActiveDocument (vlax-get-Acad-Object))) (setq plt (vla-get-plot vlax:ActiveDocument)) ;=> plot object (vla-PlotWindow plt pt1 pt2) ;WCS pts (vla-PlotPreview plt 1) ;0; partial, 1: full (vla-PlotToDevice plt "Default System Printer") ;if it exists With R14 INITDIA was introduced, which can be applied to most but not all dialogs: (initdia)(command "_PLOT") With A2000 use OLE (VLA- methods) instead of DDE. DDE support is discontinued by Microsoft. OLE provides a better object-oriented interface. ------------------------------ [21.3] (entmod) and (entmake) Layers, without (command "_LAYER"...) ENTMOD a layer I try to change a layer property without calling COMMAND function inside a lisp routine. Since R13, using the following lisp (setq tbl_lst (entget (tblobjname "LAYER" "ANY_LAYER")) clr_grp (assoc 62 tbl_lst) ) (entmod (subst (cons 62 (- (cdr clr_grp))) clr_grp tbl_lst)) you can toggle "ANY_LAYER" On or Off, even it is the current layer. But AutoCAD doesn't know a table entry has been changed until you click the Layer Control on the toolbar or something similar. Besides, you can issue 'DDLMODES to see On/OFf property of "ANY_LAYER" changed. Doing the same way to freeze a layer, you will still see entities on that layer shown on screen, but you can not select them, until you do something related to layer settings, and AutoCAD will hide those entities. ENTMAKE a layer You must get your pattern with entget, using the table object name as argument. This table object name can be retrieved with the TBLOBJNAME function: (entget (tblobjname "LAYER" "Any Layer Name")) ; R2000 can have spaces! ;;; This routine will create a layer with any name you type: (defun C:MLAY () ; by Reinaldo Togores <rtogores@mundivia.es> (setq laynam (getstring "\nLayer name: ")) (entmake (list '(0 . "LAYER") '(5 . "28") '(100 . "AcDbSymbolTableRecord") '(100 . "AcDbLayerTableRecord") (cons 2 laynam) '(70 . 64) '(62 . 7) '(6 . "CONTINUOUS") ))) ------------------------------ [21.4] How to select multiple files in Lisp? (as in FILES - Unlock) [new] * DOSLIB v4.3 from McNeel contains dos_getfilem, http://www.mcneel.com/products.htm#Utilities * STDLIB contains std-getfilem http://xarch.tu-graz.ac.at/autocad/stdlib/GETFILEM.LSP * At http://xarch.tu-graz.ac.at/autocad/progs/MGETFILD.ZIP is another lisp helper routine to select multiple files with DCL. You will also need VLISP, DOSLIB or the STDLIB to access the directory functions. Another lisp version is at http://xarch.tu-graz.ac.at/autocad/stdlib/Reini_MFD.LSP ------------------------------ [21.5] Replace multiple blocks A search at the lisp archives yielded those hits: Cadalyst: http://www.cadonline.com/search.phtml => 97code.htm and a question for your username which can be obtained free and automatically or xarch: http://xarch.tu-graz.ac.at/autocad/code and search for "BLOCK;REPLACE" => http://xarch.tu-graz.ac.at/autocad/code/cadalyst/94-02/replace.lsp also at the Cadalog: http://www.cadalog.com/ OpenSource Freeware Keyword: "Block Replace" => replace.zip (this one is the best) ------------------------------ [21.6] (vports), VIEWPORT entity, pixel conversion VIEWPORT entity: The answer to "I can do an (entget) on a VIEWPORT and get its lower left (DXF group 10) and upper right (DXF group 11) corner. But it appears that these coordinates are in the paper space system. What I'm interested in finding out is what portion of the "real" drawing (the model space drawing) are currently shown in that viewport." is at http://xarch.tu-graz.ac.at/autocad/news/vports.lsp http://www.ez-sys.net/~coopfra/lisp.htm#view has also some tricks. How to change viewports in AutoLISP? with (setvar "CVPORT" vport-id) see http://xarch.tu-graz.ac.at/autocad/news/change_vports.html With the following functions you convert pixel<->drawing units: ;;; Conversion pixel to drawing units (defun PIX2UNITS (pix) (* pix (/ (getvar "VIEWSIZE") (cadr (getvar "SCREENSIZE"))))) ;;; Conversion drawing units to pixel (defun UNITS2PIX (units) (* units (/ (cadr (getvar "SCREENSIZE"))(getvar "VIEWSIZE")))) Note also the "Pixel Off by One" Errors in AutoCAD, written by Vibrant http://xarch.tu-graz.ac.at/autocad/news/pixel-off-by-one-error.txt ------------------------------ [21.7] Select all visible objects: zoom coordinates Beware that with (ssget) you will only get visible objects, because all interface functions (entsel,ssget,osnap) work with pixel, only (ssget "X") will select not visible objects. ;;; returns a list of the actual viewport corners in WCS (defun ZOOMPTS ( / ctr h screen ratio size size_2) (setq ctr (xy-of (getvar "VIEWCTR")) ;3D -> 2D h (getvar "VIEWSIZE") ;real screen (getvar "SCREENSIZE") ;2D: Pixel x,y ratio (/ (float (car screen)) ;aspect ratio (cadr screen)) size (list (* h ratio) h) ;screensize in coords size_2 (mapcar '/ size '(2.0 2.0))) (list (mapcar '- ctr size_2) (mapcar '+ ctr size_2))) (defun XY-OF (pt) (list (car pt)(cadr pt))) ;assure 2D coords Note: The points returned are in WCS but this is ok, because the "CP" "WP" and "P" options of ssget expect WCS points. "W" and "C" require UCS points - why the difference I don't know. ;;; one way to define this function (defun SSALL-VISIBLE (/ l) (ssget "C" (car (setq l (maptrans0-1 (zoompts)))) (cadr l))) ;;; or another (defun SSALL-VISIBLE-1 () ;combine "C" and (p1 p2) to one list (apply 'ssget (append '("C") (maptrans0-1 (zoompts))))) ;;; map some pts from WCS to UCS, easier with just one argument (defun MAPTRANS0-1 (pts) (mapcar '(lambda (pt)(trans pt 0 1)) pts))
Top Document: comp.cad.autocad AutoLISP FAQ (part 2/2) - samples, code
Previous Document: [20] General helper functions
Next Document: [21.8] How to write XYZ data of selected objects to a file?
Part1 - Part2 - Single Page
[ Usenet FAQs | Web FAQs | Documents | RFC Index ]
Send corrections/additions to the FAQ Maintainer:
rurban@xarch.tu-graz.ac.at (Reini Urban)
Last Update October 22 2009 @ 05:22 AM