Jump to content

Script for renaming Ordnnce Survey layers


Daid Keohane

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)
)

Link to comment
Share on other sites

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))
.......

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...