Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Layer States - Save and Restore

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
363 Views, 2 Replies

Layer States - Save and Restore

Hello, I have written a small command to Save and Restore layer states using Lisp. I am using the native AutoCAD Layer command driven by (command...) to perform the save and restore. My question is - how do I control the various options in the layer state dialog which appear in the dialog box? Secondly, when I restore a previously saved layer state, the current layer is not correctly updated. Any help is appreciated. Regards Rakesh -- AutoCAD customization for Engineering/Mapping/GIS Get GeoTools @ http://www.4d-technologies.com/geotools Build MyGeoTools @ http://www.4d-technologies.com/geotools/my_geotools.htm FREE downloads : http://www.4d-technologies.com/techcenter
2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: Anonymous

Hi Rakesh, This should help you. I hope all functions are present as I grabbed them from a larger application. Thanks to Tony Tanzillo for one of the functions as noted. Don Butler ;| Donald E. Butler donaldebutler@netzero.net REQUIREMENTS: AutoCAD ver 2000+ OBJECT: Save and Restore Layer States compatible with AutoCAD's Layer Manager. SUBR's: (lsave name bit) (lrestore name) (ldelete name) --------------------------------------------------------- Layer Bit Settings Bit Value All layer properties================== 65535 Color================================= 32 Frozen or thawed====================== 2 Linetype============================== 64 Lineweight============================ 128 Locked or unlocked==================== 4 New viewport layers frozen or thawed== 16 None================================== 0 On or off============================= 1 Plotting on or off==================== 8 Plot style============================ 256 --------------------------------------------------------- |; (vl-load-com) ;;;Author: Tony Tanzillo (defun LayerGetObject (ProgId / Result) ;; First try using explicit version-dependent progid: (setq result (vla-getinterfaceobject (vlax-get-acad-object) (strcat ProgId "." (substr (getvar "acadver") 1 2)) ) ) ;; Else try the version-independent progid: (if (not result) (setq result (vla-getinterfaceobject (vlax-get-acad-object) progid ) ) ) result ) (setq *lsman* (LayerGetObject "autocad.acadlayerstatemanager")) (vla-setdatabase *lsman* (vla-get-database (vla-get-activedocument (vlax-get-acad-object)))) (defun lsave (nam bit) (setq nam (strcase nam)) (if (member nam (getstatenames)) (vl-catch-all-apply 'vla-delete (list *lsman* nam)) ) (vl-catch-all-apply 'vla-save (list *lsman* nam bit)) (prompt (strcat "\n" nam " Saved")) (princ) ) (defun lrestore (nam) (if (member (setq nam (strcase nam)) (getstatenames)) (progn (vl-catch-all-apply 'vla-restore (list *lsman* nam)) (vl-cmdf "_.regenall") (prompt (strcat "\n" nam " Restored")) ) ) (princ) ) (defun ldelete (nam) (if (member (setq nam (strcase nam)) (getstatenames)) (progn (vl-catch-all-apply 'vla-delete (list *lsman* nam)) (prompt (strcat "\n" nam " Deleted")) ) ) (princ) ) ;;;Utility Return Saved States (defun getstatenames (/ nams dict obj) (setq dict (vla-getextensiondictionary (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)) ) ) ) (if (not (vl-catch-all-error-p (setq obj (vl-catch-all-apply (function (lambda () (vla-item dict "ACAD_LAYERSTATES"))) ) ) ) ) (vlax-for n obj (setq nams (cons (strcase (vla-get-name n)) nams)) ) ) (if nams (acad_strlsort nams) ) ) "Rakesh Rao" wrote in message news:4051B924.4060606@4d-technologies.com... > > Hello, > > I have written a small command to Save and Restore layer states using > Lisp. I am using the native AutoCAD Layer command driven by (command...) > to perform the save and restore. My question is - how do I control the > various options in the layer state dialog which appear in the dialog > box? Secondly, when I restore a previously saved layer state, the > current layer is not correctly updated. Any help is appreciated. > > Regards > Rakesh > -- > > AutoCAD customization for Engineering/Mapping/GIS > Get GeoTools @ http://www.4d-technologies.com/geotools > Build MyGeoTools @ http://www.4d-technologies.com/geotools/my_geotools.htm > FREE downloads : http://www.4d-technologies.com/techcenter > > --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.591 / Virus Database: 374 - Release Date: 2/17/2004
Message 3 of 3
Anonymous
in reply to: Anonymous

Thank you very much for this code. This saved me a lot of time. For some reason the bit value of 65535 did not work. I had to use the bit value of 1023 to select all the settings. You can also use the bit value of 512 to control current viewports. "Don Butler" wrote in message news:4052236d_2@newsprd01... > Hi Rakesh, > > This should help you. I hope all functions are present as I grabbed them > from a larger application. > > Thanks to Tony Tanzillo for one of the functions as noted. > > Don Butler > > ;| > > Donald E. Butler > donaldebutler@netzero.net > > REQUIREMENTS: AutoCAD ver 2000+ > > OBJECT: Save and Restore Layer States compatible with AutoCAD's Layer > Manager. > > SUBR's: (lsave name bit) > (lrestore name) > (ldelete name) > > --------------------------------------------------------- > Layer Bit Settings Bit Value > > All layer properties================== 65535 > Color================================= 32 > Frozen or thawed====================== 2 > Linetype============================== 64 > Lineweight============================ 128 > Locked or unlocked==================== 4 > New viewport layers frozen or thawed== 16 > None================================== 0 > On or off============================= 1 > Plotting on or off==================== 8 > Plot style============================ 256 > --------------------------------------------------------- > > |; > > (vl-load-com) > > ;;;Author: Tony Tanzillo > (defun LayerGetObject (ProgId / Result) > ;; First try using explicit version-dependent progid: > (setq result > (vla-getinterfaceobject > (vlax-get-acad-object) > (strcat ProgId "." (substr (getvar "acadver") 1 2)) > ) > ) > ;; Else try the version-independent progid: > (if (not result) > (setq result > (vla-getinterfaceobject > (vlax-get-acad-object) > progid > ) > ) > ) > result > ) > > (setq *lsman* (LayerGetObject "autocad.acadlayerstatemanager")) > (vla-setdatabase *lsman* (vla-get-database (vla-get-activedocument > (vlax-get-acad-object)))) > > (defun lsave (nam bit) > (setq nam (strcase nam)) > (if (member nam (getstatenames)) > (vl-catch-all-apply 'vla-delete (list *lsman* nam)) > ) > (vl-catch-all-apply 'vla-save (list *lsman* nam bit)) > (prompt (strcat "\n" nam " Saved")) > (princ) > ) > > (defun lrestore (nam) > (if (member (setq nam (strcase nam)) (getstatenames)) > (progn (vl-catch-all-apply 'vla-restore (list *lsman* nam)) > (vl-cmdf "_.regenall") > (prompt (strcat "\n" nam " Restored")) > ) > ) > (princ) > ) > > (defun ldelete (nam) > (if (member (setq nam (strcase nam)) (getstatenames)) > (progn (vl-catch-all-apply 'vla-delete (list *lsman* nam)) > (prompt (strcat "\n" nam " Deleted")) > ) > ) > (princ) > ) > > ;;;Utility Return Saved States > (defun getstatenames (/ nams dict obj) > (setq dict (vla-getextensiondictionary > (vla-get-layers > (vla-get-activedocument (vlax-get-acad-object)) > ) > ) > ) > (if (not > (vl-catch-all-error-p > (setq obj (vl-catch-all-apply > (function (lambda () (vla-item dict "ACAD_LAYERSTATES"))) > ) > ) > ) > ) > (vlax-for n obj > (setq nams (cons (strcase (vla-get-name n)) nams)) > ) > ) > (if nams > (acad_strlsort nams) > ) > ) > > "Rakesh Rao" wrote in message > news:4051B924.4060606@4d-technologies.com... > > > > Hello, > > > > I have written a small command to Save and Restore layer states using > > Lisp. I am using the native AutoCAD Layer command driven by (command...) > > to perform the save and restore. My question is - how do I control the > > various options in the layer state dialog which appear in the dialog > > box? Secondly, when I restore a previously saved layer state, the > > current layer is not correctly updated. Any help is appreciated. > > > > Regards > > Rakesh > > -- > > > > AutoCAD customization for Engineering/Mapping/GIS > > Get GeoTools @ http://www.4d-technologies.com/geotools > > Build MyGeoTools @ http://www.4d-technologies.com/geotools/my_geotools.htm > > FREE downloads : http://www.4d-technologies.com/techcenter > > > > > > > --- > Outgoing mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.591 / Virus Database: 374 - Release Date: 2/17/2004 > >

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost