TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: TJAM51 on June 23, 2005, 10:11:08 AM

Title: Changing numerous blocks (40 or so) to another layer at once
Post by: TJAM51 on June 23, 2005, 10:11:08 AM
We receive drawings from out client. These blocks are on the same layer. There are approximately 40 or so blocks total. Now each block has to be on a separate layer for out company to use in our MEP drawings. I am seeking a method of selecting all these blocks (remember theyall have separate names and each one needs to be on it's own layer) and placing them on their own specific layers. This needs to be done in one step or one run of a routine. Routines like "Get" as described in other discussions on this forum do not work due to the operator picking each block name separately. Any suggestions or ideas...thanks
Title: Changing numerous blocks (40 or so) to another layer at once
Post by: David Hall on June 23, 2005, 10:19:15 AM
what does the layer name have to be?  could the layername be the same as the block name?  if so, that would be very easy
Title: Changing numerous blocks (40 or so) to another layer at once
Post by: TJAM51 on June 23, 2005, 10:31:02 AM
The system seems to be kicking me out.......the layer names cannot match the block name. This is a decision made by higher ups. If someone could show me how to start the routine......show me next how to select the block and then place it on it's specified layer I could type in the rest.


Thanks
Title: Changing numerous blocks (40 or so) to another layer at once
Post by: daron on June 23, 2005, 10:53:11 AM
(setq ss (ssget "x" '((0 . "INSERT"))))

that'll start you. If you want to name specific blocks use '((2 . "blocknamehere"))
Title: Changing numerous blocks (40 or so) to another layer at once
Post by: TJAM51 on June 23, 2005, 12:35:33 PM
If I wanted to change the actual block to another layer how would that be stated?
Title: Changing numerous blocks (40 or so) to another layer at once
Post by: Jeff_M on June 23, 2005, 01:30:59 PM
This doesn't do the actual layer decision making, but it shows how you'd modify the block's layer.
Code: [Select]

(if (setq ss (ssget "x" '((0 . "INSERT"))))
  (progn
    (setq idx -1)
    (while (< (setq idx (1+ idx))(sslength ss))
      (setq ent (entget (ssname ss idx))
   bname (cdr (assoc 2 ent))
   ent (subst (cons 8 "whatever the layer should be here") (assoc 8 ent) ent)
   )
      (entmod ent)
      )
    )
  )
Title: Changing numerous blocks (40 or so) to another layer at once
Post by: daron on June 23, 2005, 02:23:54 PM
Quote from: TJAM51
If I wanted to change the actual block to another layer how would that be stated?

Like that^. :lol: Good work Jeff.
Title: Changing numerous blocks (40 or so) to another layer at once
Post by: TJAM51 on June 24, 2005, 11:38:22 AM
ANOTHER APPROACH..........I have created a menu button with the following script...........

-LAYER;M;E-LITA;C;30;;;^C^CSSX;;BLOCK;TYPE_300;;^C^CCHANGE;PREVIOUS;;P;LA;E-LITA;;


This button only deals with converting one block to one layer. I need to include numerous more blocks for this layer. How can this be written to include 17 more blocks?
Title: Changing numerous blocks (40 or so) to another layer at once
Post by: daron on June 24, 2005, 11:46:46 AM
Use Jeff's.
Change this line:
Code: [Select]
(if (setq ss (ssget "x" '((0 . "INSERT"))))
to
Code: [Select]
(if (setq ss (ssget "x" '(((-4 . "<OR") (2 . "blockname") (2 . "nextblockname_etc") (-4 . "OR>"))))
Title: Changing numerous blocks (40 or so) to another layer at once
Post by: TJAM51 on June 24, 2005, 11:53:38 AM
Ok...ltes see if I am heading in the right direction.....


(DEFUN C:GENERAL)
  (command "LAYER" "M" "E-LITG" "C" "30" "" ""
           "LAYER" "M" "E-LITA" "C" "30" "" "")
(if (setq ss (ssget "x" '(((-4 . "<OR") (2 . "TYPE_110")
(2 . "TYPE_122") (2. "type_120") (-4 . "OR>"))))
(PRINC)

I would continue to add the remaining block names as shown above, right? I receive the error messagen "SYNTAX ERROR".
Title: Changing numerous blocks (40 or so) to another layer at once
Post by: Mark on June 24, 2005, 12:29:47 PM
try this one;

Code: [Select]

(DEFUN C:GENERAL (/ ss)

  (command "LAYER" "M" "E-LITG" "C" "30" "" "")
  (command "LAYER" "M" "E-LITA" "C" "30" "" "")

  (if
    (setq ss
  (ssget "x"
 '(
   (-4 . "<OR")
   (2 . "TYPE_110")
   (2 . "TYPE_122")
   (2 . "type_120")
   (-4 . "OR>")
  )
  )
    )
     (princ (strcat "\nFound " (itoa (sslength ss)) " blocks"))
  )

  (PRINC)
)
Title: Changing numerous blocks (40 or so) to another layer at once
Post by: TJAM51 on June 24, 2005, 12:43:53 PM
Here is the final routine for the layer E-LITG.....

(DEFUN C:litg (/ ss)
  (command "LAYER" "M" "E-LITG" "C" "30" "" "")
  (if
    (setq ss
      (ssget "x"
        '(
          (-4 . "<OR")
          (2 . "TYPE_110")
          (2 . "TYPE_122")
          (2 . "type_120")
          (2 . "TYPE_125")
          (2 . "TYPE_112")
          (2 . "type_130-4")
          (2 . "type_130-8")
          (2 . "type_131-4")
          (2 . "type_131-8")
          (2 . "type_163")
          (2 . "type_180-8")
          (2 . "type_184")
          (2 . "type_128")
          (2 . "type_366")
          (2 . "type_495")
          (2 . "type_393")
          (2 . "type_498")
          (2 . "type_498e")
          (-4 . "OR>")
         )
      )
    )
     (princ (strcat "\nFound " (itoa (sslength ss)) " blocks"))
  )

  (PRINC)
)


The only problem is that it will not affect any blocks from TYPE_120 on down. They remain on the same layer and color.....did I type something wrong?

Thanks
Title: Changing numerous blocks (40 or so) to another layer at once
Post by: Mark on June 24, 2005, 12:58:20 PM
What you have looks right but you're not doing anything to the blocks in the selection set (ss). Now you have to iterate through the selection set and modify the blocks.

BTW have you tried "Quick Select"

http://www.theswamp.org/screens/mark/screen_shots/quick_select_blkname.png
Title: Changing numerous blocks (40 or so) to another layer at once
Post by: TJAM51 on June 24, 2005, 01:01:27 PM
Yes I have but attempting to eliminate as many steps as possible....
Title: Changing numerous blocks (40 or so) to another layer at once
Post by: Jeff_M on June 24, 2005, 01:20:07 PM
Here's another way of doing the same thing:
Code: [Select]

(DEFUN C:litg (/ ss)
  (command "LAYER" "M" "E-LITG" "C" "30" "" "")
  (if
    (setq ss
  (ssget "x"
 '((2 . "TYPE_110,TYPE_122,type_120,TYPE_125,TYPE_112,type_130-4,type_130-8,type_131-4,type_131-8,type_163,type_180-8,type_184,type_128,type_366,type_495,type_393,type_498,type_498e"))
  )
    )
    (progn
     (princ (strcat "\nFound " (itoa (sslength ss)) " blocks"))
     (command ".chprop" ss "" "la" "E-LITG" "")
     )
  )

  (PRINC)
)
Title: Changing numerous blocks (40 or so) to another layer at once
Post by: TJAM51 on June 24, 2005, 01:24:13 PM
That is strange...this routine you added works great.....who can figure.....thanks
Title: Changing numerous blocks (40 or so) to another layer at once
Post by: Mark on June 24, 2005, 01:36:54 PM
Code: [Select]
(DEFUN C:GENERAL (/ ss)

  (command "LAYER" "M" "E-LITG" "C" "30" "" "")
  (command "LAYER" "M" "E-LITA" "C" "30" "" "")

  (if
    (setq ss
  (ssget "x"
 '(
   (-4 . "<OR")
   (2 . "TYPE_110")
   (2 . "TYPE_122")
   (2 . "type_120")
   (-4 . "OR>")
  )
  )
    )
     (progn
       (setq cntr 0)
       (while (setq ent (ssname ss cntr))

(setq entlst (entget ent))
(setq entlst
(subst
 (cons 8 "0") ; change layer name here
 (assoc 8 entlst)
 entlst
)
)
(entmod entlst)

(setq cntr (1+ cntr))
       )
     )
  )

  (PRINC)
)