Clean survey drawings

Clean survey drawings

Automohan
Advocate Advocate
1,330 Views
19 Replies
Message 1 of 20

Clean survey drawings

Automohan
Advocate
Advocate

A lisp that will do .....

Select all of the blocks name "BOXP" then change all the block Geometry Scale X = 250 Scale Y = 250 Scale Y = 1 & change to layer "WADI" (I can edit the block & the layer names as per my requirement)
Select all of the blocks name "CIRP" then change all the block Geometry Scale X = 250 Scale Y = 250 Scale Y = 1 & change to layer "ROAD EDGE" (I can edit the block & the layer names as per my requirement)
Select all of the blocks name "SNG" then change all the block Geometry Scale X = 250 Scale Y = 250 Scale Y = 1 & change to layer "ROAD SIGNS" (I can edit the block & the layer names as per my requirement)
Select all of the blocks name "LTE" then change all the block Geometry Scale X = 250 Scale Y = 250 Scale Y = 1 & change to layer "STREET LIGHTS" (I can edit the block & the layer names as per my requirement)
" " " "
still need to add more block names I will do it

then layers clean (command "_.-PURGE" "LA" "*" "N")

all the blocks are in layer 0 should changed to their original layer names


thanks

 

"Save Energy"
Did you find this reply helpful? If so please use the Accept as Solution
0 Likes
1,331 Views
19 Replies
Replies (19)
Message 2 of 20

Sea-Haven
Mentor
Mentor

The simplest way would be a csv file Blkname,250,250,1,newlayer then read the file and carry out the changes. Then do purge etc.

 

Post a sample dwg and make the csv file.

2nd question does new layer exist ? Extra step if not. Blkname,250,250,1,newlayer,Col,Lt

0 Likes
Message 3 of 20

CodeDing
Advisor
Advisor

@Automohan ,

 

Assuming your scales will be the same for each block, here's my approach. There's multiple ways to go about this.

Hope this helps!

(defun c:CBP ( / ss scaleX scaleY scaleZ blkLyrList lyrNotFound cnt e bName)
;Change Block Properties
;get all blocks
(if (not (setq ss (ssget "_X" '((0 . "INSERT")))))
  (progn (prompt "\n...No blocks found.") (exit))
);if
;initial variable prep
(setq scaleX 250.0 scaleY 250.0 scaleZ 1.0 total 0)
(setq blkLyrList '(
  ("BOXP" "WADI") ("CIRP" "ROAD EDGE") ("SNG" "ROAD SIGNS") ("LTE" "STREET LIGHTS")
));list/setq
;you can either check for layers or make them
;|check
(mapcar
  '(lambda (x)
    (if (not (tblobjname "LAYER" (cadr x)))
      (setq lyrNotFound t x (prompt (strcat "\nLayer not found: " (cadr x))))))
  blkLyrList
);mapcar
(if lyrNotFound (exit))
|;
;make
(mapcar
  '(lambda (x)
    (if (not (tblobjname "LAYER" (cadr x)))
      (entmakex (list '(0 . "LAYER") '(100 . "AcDbSymbolTableRecord") '(100 . "AcDbLayerTableRecord")
		      (cons 2 (cadr x)) '(70 . 0) '(62 . 7))))) ;62 is layer color
  blkLyrList
);mapcar
;update block properties
(repeat (setq cnt (sslength ss))
  (setq e (ssname ss (setq cnt (1- cnt)))
	bName (strcase (getpropertyvalue e "BlockTableRecord/Name")))
  (foreach i blkLyrList
    (if (eq bName (strcase (car i)))
      (progn
	(setpropertyvalue e "LayerId" (tblobjname "LAYER" (cadr i)))
	(setpropertyvalue e "ScaleFactors/X" scaleX)
	(setpropertyvalue e "ScaleFactors/Y" scaleY)
	(setpropertyvalue e "ScaleFactors/Z" scaleZ)
	(setq total (1+ total))
      );progn
    );if
  );foreach
);repeat
;finish up
(command "_.-PURGE" "LA" "*" "N")
(prompt (strcat "\nCBP Complete, " (itoa total) " blocks updated."))
(princ)
);defun

Best,

~DD

0 Likes
Message 4 of 20

Automohan
Advocate
Advocate

Survey cad file are doing by the surveys but there is no standards items,

 

1.) Importing data from cvs files are survey's responsibility?

2.) One item with many layer names, mostly this happens if more survey's working with one file? (They don't have standard layers

Only block names there are having standard, because each file they can't create new new blocks

Engineers will get confused

"Save Energy"
Did you find this reply helpful? If so please use the Accept as Solution
0 Likes
Message 5 of 20

Automohan
Advocate
Advocate

Thanks a lot.... but only one thing is missing

The blocks are in layer 0 should be by layer (color by layer)

 

I am attaching the cad file.

"Save Energy"
Did you find this reply helpful? If so please use the Accept as Solution
0 Likes
Message 6 of 20

cadffm
Consultant
Consultant

Why do you want this unneeded limitation? (ByLayer instead ByBlock)

Sebastian

0 Likes
Message 7 of 20

Automohan
Advocate
Advocate

These all drawings will be use as External Reference files, layers should be by layer...

"Save Energy"
Did you find this reply helpful? If so please use the Accept as Solution
0 Likes
Message 8 of 20

Sea-Haven
Mentor
Mentor

The reason I said use a csv was in the example 

(setq blkLyrList '(
  ("BOXP" "WADI") ("CIRP" "ROAD EDGE") ("SNG" "ROAD SIGNS") ("LTE" "STREET LIGHTS")
))

You have only 4 blocks then do a list as per the code supplied my old survey template had around 120 blocks thats a lot of typing. If you need to add or change or remove easier to do so in a csv file using excel. Same with scale etc.

 

Its very easy to make blkLyrlist from a csv.

 

For CIV3d wrote a make point style so could fix this problem at the 1st step so have different styles depending on data collector style. Objects with desc BOXP go on layer WADI 

 

Maybe you should be looking at how your download data collector is set up so correct layers are used.

0 Likes
Message 9 of 20

CodeDing
Advisor
Advisor

Thanks a lot.... but only one thing is missing

The blocks are in layer 0 should be by layer (color by layer)


@Automohan ,

 

I do not understand enough of what you are saying to help with this.

Are you saying

- All blocks found on layer "0" BEFORE implementing the new layers, should be updated to "color by layer"?

or

- All blocks found on layer "0" AFTER implementing the new layers, should be updated to "color by layer"?

or

- Only blocks named in list found on layer "0" BEFORE implementing the new layers, should be updated to "color by layer"?

 

Best,

~DD

0 Likes
Message 10 of 20

Automohan
Advocate
Advocate

All blocks found on layer "0" BEFORE implementing the new layers, should be updated to "color by layer"?

(in Block editor you can see blocks are with layer 0)

"Save Energy"
Did you find this reply helpful? If so please use the Accept as Solution
0 Likes
Message 11 of 20

CodeDing
Advisor
Advisor

Ok, Thank you. Here is that updated section:

;update block properties
(repeat (setq cnt (sslength ss))
  (setq e (ssname ss (setq cnt (1- cnt)))
	bName (strcase (getpropertyvalue e "BlockTableRecord/Name")))
  (if (eq "0" (cdr (assoc 8 (entget e)))) (setpropertyvalue e "Color" 256))
  (foreach i blkLyrList
    (if (eq bName (strcase (car i)))
      (progn
	(setpropertyvalue e "LayerId" (tblobjname "LAYER" (cadr i)))
	(setpropertyvalue e "ScaleFactors/X" scaleX)
	(setpropertyvalue e "ScaleFactors/Y" scaleY)
	(setpropertyvalue e "ScaleFactors/Z" scaleZ)
	(setq total (1+ total))
      );progn
    );if
  );foreach
);repeat
;finish up

Best,

~DD

0 Likes
Message 12 of 20

Automohan
Advocate
Advocate

Sorry guys (Attached video)

The blocks are not by layer

 

 

 

"Save Energy"
Did you find this reply helpful? If so please use the Accept as Solution
0 Likes
Message 13 of 20

Automohan
Advocate
Advocate

Video

 

"Save Energy"
Did you find this reply helpful? If so please use the Accept as Solution
0 Likes
Message 14 of 20

CodeDing
Advisor
Advisor

@Automohan ,

 

Your video does not show what layer your blocks were on BEFORE running the command. Were your blocks (NOT the objects inside your blocks) ever on layer "0"? If the blocks were not on layer "0" before running the command then their Color will not be changed to "ByLayer".

 

Best,

~DD

0 Likes
Message 15 of 20

Automohan
Advocate
Advocate

All blocks are in layer 0 in blockediter (before & after running the lisp)

"Save Energy"
Did you find this reply helpful? If so please use the Accept as Solution
0 Likes
Message 16 of 20

CodeDing
Advisor
Advisor

@Automohan ,

 

We were clearly understanding this 2 different ways. I believe this is what you are looking for?

(defun c:CBP ( / ss scaleX scaleY scaleZ blkLyrList lyrNotFound cnt e bName)
;Change Block Properties
;get all blocks
(if (not (setq ss (ssget "_X" '((0 . "INSERT")))))
  (progn (prompt "\n...No blocks found.") (exit))
);if
;initial variable prep
(setq scaleX 250.0 scaleY 250.0 scaleZ 1.0 total 0)
(setq blkLyrList '(
  ("BOXP" "WADI") ("CIRP" "ROAD EDGE") ("SNG" "ROAD SIGNS") ("LTE" "STREET LIGHTS")
));list/setq
;you can either check for layers or make them
;|check
(mapcar
  '(lambda (x)
    (if (not (tblobjname "LAYER" (cadr x)))
      (setq lyrNotFound t x (prompt (strcat "\nLayer not found: " (cadr x))))))
  blkLyrList
);mapcar
(if lyrNotFound (exit))
|;
;make
(mapcar
  '(lambda (x)
    (if (not (tblobjname "LAYER" (cadr x)))
      (entmakex (list '(0 . "LAYER") '(100 . "AcDbSymbolTableRecord") '(100 . "AcDbLayerTableRecord")
		      (cons 2 (cadr x)) '(70 . 0) '(62 . 7))))) ;62 is layer color
  blkLyrList
);mapcar
;update block properties
(command "_.SETBYLAYER" ss "" "y" "y") (repeat (setq cnt (sslength ss)) (setq e (ssname ss (setq cnt (1- cnt))) bName (strcase (getpropertyvalue e "BlockTableRecord/Name"))) (foreach i blkLyrList (if (eq bName (strcase (car i))) (progn (setpropertyvalue e "LayerId" (tblobjname "LAYER" (cadr i))) (setpropertyvalue e "ScaleFactors/X" scaleX) (setpropertyvalue e "ScaleFactors/Y" scaleY) (setpropertyvalue e "ScaleFactors/Z" scaleZ) (setq total (1+ total)) );progn );if );foreach );repeat ;finish up (command "_.-PURGE" "LA" "*" "N") (prompt (strcat "\nCBP Complete, " (itoa total) " blocks updated.")) (princ) );defun

Best,

~DD

0 Likes
Message 17 of 20

john.uhden
Mentor
Mentor

Why not

(if lyrNotFound (createlyr))

John F. Uhden

0 Likes
Message 18 of 20

Automohan
Advocate
Advocate

Found at https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/change-block-or-nested-block-color-t... 

 

;;  BELTB.lsp
;;  = change all Block Entities of definitions of a selected block and all
;;    nested block definitions within it to the Layer of the Top-level Block
;;  Kent Cooper, 18 November 2014

(vl-load-com)
(defun C:BELTB (/ *error* doc nametolist blkss inc blk lay blknames ent edata)

  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg))
    ); if
    (vla-endundomark doc)
    (princ)
  ); defun - *error*

  (defun nametolist (blk / blkobj blkname); get Block name and put it into list of names
    (if (= (logand (cdr (assoc 70 (entget blk))) 4) 0) ; not an Xref
      (progn
        (setq
          blkobj (vlax-ename->vla-object blk)
          blkname
            (vlax-get-property blkobj
              (if (vlax-property-available-p blkobj 'EffectiveName) 'EffectiveName 'Name)
                ; to work with older versions that don't have dynamic Blocks
            ); ...get-property & blkname
        ); setq
        (if
          (not (member blkname blknames)); name not already in list
          (setq blknames (append blknames (list blkname))); then -- add to end of list
        ); if
      ); progn
    ); if
  ); defun -- nametolist

  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (vla-startundomark doc); = Undo Begin

  (if (setq blkss (ssget "_+.:S" '((0 . "INSERT")))); User selection of a Block/Minsert/Xref
    (progn ; then
      (setq
        blk (ssname blkss 0); top-level Block insertion
        lay (cdr (assoc 8 (entget blk))); Layer it's inserted on
      ); setq
      (nametolist blk); put it in blknames list
      (while (setq blk (car blknames)); as long as there's another Block name in list
        ;; done this way instead of via (repeat) or (foreach), so it can add nested Blocks' names to list
        (setq ent (tblobjname "block" blk)); Block definition as entity
        (while (setq ent (entnext ent)); then -- proceed through sub-entities in definition
          (setq edata (entget ent)); entity data list
          (if (member '(0 . "INSERT") edata) (nametolist ent)); if nested Block, add name to end of list
          (entmod (subst (cons 8 lay) (assoc 8 edata) edata)); change to top-level Block's Layer
        ); while -- sub-entities
        (setq blknames (cdr blknames)); take first one off
      ); while
      (command "_.regen")
    ); progn
    (prompt "\nNo Block(s) selected.")
  ); if [user selection]

  (vla-endundomark doc); = Undo End
  (princ)
); defun

BELTB Lisp.jpg

Update the above lisp to select all blocks at a time.......

"Save Energy"
Did you find this reply helpful? If so please use the Accept as Solution
0 Likes
Message 19 of 20

CodeDing
Advisor
Advisor

@Automohan ,

 

I no longer understand your desired result. Perhaps someone else following can give me insight? Otherwise, you will need to explain in great detail what you are expecting for me to help any further.

 

Best,

~DD

0 Likes
Message 20 of 20

Automohan
Advocate
Advocate

Ok, when you explode all blocks they all are in layer 0, need to change layers.....

"Save Energy"
Did you find this reply helpful? If so please use the Accept as Solution
0 Likes