Daid Keohane Posted February 2, 2016 Share Posted February 2, 2016 Hi All, my first post here so I will try and not show myself up! When we buy digital Ordnance SUrvey mapping, the layer names come through like this.. G8010001 G8010004 G8010007 G8010008 G8010009 However, these are the Ordnance Survey's internal layer names and each number corresponds to a particular description which can be found online, for example... se below... I wondered if anyone had ever written a lisp routine that will automatically rename all the layers so that they read like this... G8010001 - Building Outline G8010004 - Building Outline (Overhead) G8010007 - Civil Parish or community boundary G8010008 - District, London borough or unitary authority boundary G8010009 - County boundary etc etc etc Layer nameDescriptionLine type or text fontLine weightEntityColourBlock nameG8010001Building outlineCONTINUOUS2POLYLINERED G8010004Building outline (overhead)DASHED2POLYLINERED G8010007Civil parish or community boundaryCONTINUOUS2POLYLINEMAGENTA G8010008District, London borough or unitary authority boundaryCONTINUOUS2POLYLINEMAGENTA G8010009County boundaryCONTINUOUS2POLYLINEMAGENTA Quote Link to comment Share on other sites More sharing options...
Daid Keohane Posted February 2, 2016 Author Share Posted February 2, 2016 I forgot to mention, this is in Full AutoCAD Quote Link to comment Share on other sites More sharing options...
SLW210 Posted February 2, 2016 Share Posted February 2, 2016 Since you seem to be looking for a LISP, I moved your thread to the AutoLISP, Visual LISP & DCL Forum. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted February 2, 2016 Share Posted February 2, 2016 Welcome to CADTutor. Sounds like a job for the LAYTRANS Command. Cheers Quote Link to comment Share on other sites More sharing options...
YZ Posted February 4, 2016 Share Posted February 4, 2016 You can use the RENAME command in a script (or a macro) -Rename;LAyer;G8010001;G8010001 - Building Outline; and so on. Are they the same every time? Does every dwg have every layer? You might first need to add the layers, or else the rename command will error out if that layer does not exist (as opposed to layer command causes no error when trying to create a layer that already exists) -Layer;New;G8010001;New;G8010002;; and so on. Then write the script to rename every original to every final. The script option will struggle if any of the final layer names already exist in the drawing. Quote Link to comment Share on other sites More sharing options...
satishrajdev Posted February 4, 2016 Share Posted February 4, 2016 Have a look here :- (defun c:test () (command "-linetype" "_Load" "Dashed" "acad.lin" "" "") (vlax-for item (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) (vl-some '(lambda (x) (if (eq (car x) (vla-get-name item)) (progn (vla-put-name item (strcat (car x) " - " (cadr x))) (vla-put-description item (cadr x)) (vla-put-linetype item (caddr x)) (vla-put-lineweight item (cadddr x)) (vla-put-color item (last x)) ) ) ) '(("G8010001" "Building outline" "CONTINUOUS" "200" 1) ("G8010004" "Building outline (overhead)" "DASHED" "200" 1) ("G8010007" "Civil parish or community boundary" "CONTINUOUS" "200" 6) ("G8010008" "District London borough or unitary authority undary" "CONTINUOUS" "200" 6) ("G8010009" "County boundary" "CONTINUOUS" "200" 6)) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted February 4, 2016 Share Posted February 4, 2016 I would go like satishrajdev but I would read a CSV or text file file much easier to add to rather than the code lsp. this is space delimited data text file 0 7 Continuous ABUTMENT 1 Continuous ALUMINIUM PLUG 1 Continuous ARROW 1 Continuous (while (setq layercode (read-line fname)) (setq J (strlen layercode)) (setq ans "") (setq Lname (substr layercode 1 22)) (setq Laycol (substr layercode 23 1)) ; color is only 1 character (setq Laylt (substr layercode 25 J)) ....... Quote Link to comment Share on other sites More sharing options...
BlackBox Posted February 4, 2016 Share Posted February 4, 2016 If importing layers from CSV, this may be of use.... http://www.cadtutor.net/forum/showthread.php?57570-Layer-Creater-Lisp-Routine-Issue&p=390543&viewfull=1#post390543 (vl-load-com) (defun BB:CSV->Layers (path / f *error* _extract _trim acDoc l layerTable layerName layerItem layerDescription layerColor layerLinetype layerLineweight layerPlottable layerFreeze ) ;; Exampe: (BB:CSV->Layers "Z:\\my_layers_folder\\my_layers.csv") (if (and (findfile path) (setq f (open path "r")) ) (progn ;; Error handler (defun *error* (msg) (vla-endundomark acDoc) (cond ((not msg)) ; Normal exit ((member msg '("Function cancelled" "quit / exit abort"))) ; <esc> or (quit) ((princ (strcat "\n** Error: " msg " ** "))) ; Fatal error, display it ) (if f (close f) ) (princ) ) ;; Line _extraction sub-function (defun _extract (l /) (substr l 1 (vl-string-search "," l)) ) ;; Line _trim sub-function (defun _trim (v /) (vl-string-subst "" (strcat v ",") l) ) ;; Main code (vla-startundomark (setq acDoc (vla-get-activedocument (vlax-get-acad-object))) ) (read-line f) ; <- Skip first line (headers) (setq layerTable (vla-get-layers acDoc)) ;; Linetype check ;; <- Add linetype import code here, to avoid errors (while (/= nil (setq l (read-line f))) (progn ;; Layer check (setq layerItem (vla-add layerTable (setq layerName (_extract l))) ) ;; Layer settings (setq l (_trim layerName)) (vla-put-description layerItem (setq layerDescription (_extract l)) ) (setq l (_trim layerDescription)) (if (/= 7 (setq layerColor (_extract l))) (vla-put-color layerItem layerColor) ) (setq l (_trim layerColor)) (vla-put-linetype layerItem (setq layerLinetype (_extract l))) (setq l (_trim layerLinetype)) (if (= "BYLAYER" (strcase (setq layerLineweight (_extract l)))) (vla-put-lineweight layerItem aclnwtbylayer) ) (setq l (_trim layerLineweight)) (if (/= "YES" (strcase (setq layerPlottable (_extract l)))) (vla-put-plottable layerItem :vlax-false) ) (setq l (_trim layerPlottable)) (if (/= "NO " (strcase (setq layerFreeze (_extract l)))) (vla-put-freeze layerItem :vlax-true) ) ) ) (setq f (close f)) (*error* nil) ) ) ) Cheers 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.