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

Automatic move pre-set block to a layer

17 REPLIES 17
SOLVED
Reply
Message 1 of 18
Anonymous
1156 Views, 17 Replies

Automatic move pre-set block to a layer

Hi, i wonder if there any lisp for the below sequence:-

 

1) select a few group of pre-set block name

2) change all these pre-set bloack name to a layer " Eye Bolt"

 

At moment, i have several kind of block such as example of "EB10", "TEB10","EB8","TEB8" and etc..anyone can help..

17 REPLIES 17
Message 2 of 18
pbejse
in reply to: Anonymous

(defun c:tolayer  (/ blklist _addsep ss i)
      (setq blklist '("EB10" "TEB10" "EB8" "TEB8")
            ln      "Eye Bolt")
      (setq _addsep (lambda (j) (strcat j ",")))
      (if (setq ss   (ssget "_x"
                            (list '(0 . "INSERT")
                                  (cons 2
                                        (apply 'strcat
                                               (mapcar '_addsep
                                                       blklist))))))
            (repeat (setq i (sslength ss))
                  (setq e (entget (ssname ss (setq i (1- i)))))
                  (entmod (subst (cons 8 ln) (assoc 8 e) e))))
      (princ)
      )

 

The code doenst account for Anonymous names. but if you want need it to be just holler 

 

HTH

 

Message 3 of 18
Anonymous
in reply to: pbejse

Thanks this is just what i need.

Message 4 of 18
pbejse
in reply to: Anonymous


@Anonymous wrote:

Thanks this is just what i need.


Great.

Alrighty then.. Holler if you need more help

 

Cheers


 

Message 5 of 18
Anonymous
in reply to: pbejse

Well suddenly got an idea come into my mind.. If let said within this lisp, i would like to make it beside search for certain block name to layer "Eye bolt", i want it to search another certain of specific block name to be layer "Return" or etc....Wonder if it is possible or not.

Message 6 of 18
pbejse
in reply to: Anonymous


@Anonymous wrote:

Well suddenly got an idea come into my mind.. If let said within this lisp, i would like to make it beside search for certain block name to layer "Eye bolt", i want it to search another certain of specific block name to be layer "Return" or etc....Wonder if it is possible or not.



We can do better than that , we could even select the blocks to build a list to search for and prompt for new layer name.

Will that work for you?

 

Message 7 of 18
Anonymous
in reply to: pbejse

Hmmm, sound like very good.Can i have a copy of it to do some testing and see how it looks..Thanks in advance..

Message 8 of 18
pbejse
in reply to: Anonymous


@Anonymous wrote:

Hmmm, sound like very good.Can i have a copy of it to do some testing and see how it looks..Thanks in advance..


You see, there are two ways to approach this

 

!. using a routine that accepts arguments and use those as filters

(Tolayer '("EB10" "TEB10" "EB8" "TEB8") "Eye Bolt")

where the 1st argument is the block names to search for and the next as the Layer name.. but you need to type that as the sample, changing of course the blocknames and/or the layer names

 

2. The other one is like hte one i suggested. prompting for Layer name and selecting blocks for creating the filter lis

 

(defun c:tolayer  (/ blklist _addsep ss i)
      (vl-load-com)
      (setq _addsep (lambda (j) (strcat j ",")))
      (setq _effname
                 (lambda (k)
                       (vla-get-Effectivename
                             (vlax-ename->vla-object k))))
      (if (and (setq blklist nil
                     ln      (getstring "\nEnter Layer name: "))
               (/= ln "")
               (setq Blknmes (ssget '((0 . "INSERT")))))
            (progn
                  (repeat (sslength Blknmes)
                        (if (not (member
                                       (setq bn   (_effname
                                                        (ssname
                                                              Blknmes
                                                              0)))
                                       blklist))
                              (setq blklist (cons bn blklist)))
                        (ssdel (ssname Blknmes 0) Blknmes)
                        )
                  (setq ss (ssget "_x" '((0 . "INSERT"))))
                  (repeat (setq i (sslength ss))
                        (if (member (_effname
                                          (setq en   (ssname
                                                           ss
                                                           (setq i    (1- i)))))
                                    blklist)
                              (progn (setq e (entget en))
                                     (entmod (subst (cons 8 ln)
                                                    (assoc 8 e)
                                                    e)))))
                  )
            )(princ)
      )

 

 I'm just asking these to make sure we got all bases covered.

 

EDIT: forgot to atatched the code 🙂 

 

 

 

Message 9 of 18
Anonymous
in reply to: Anonymous

Hi pbejse,

Thanks for the idea and i just try the lisp...sort like nothing much difference as what i am doin currently..At moment, i would need to pick and select a certain block and change to my desire layer at the toolbar menu..Maybe i prefer to your first given lisp..Just wonder that if inside the lisp, can i add  additional others block name to be change to a pre-set layer too..cause at moment, i only have just a few preset block name that i wish it would automatic change to a preset layer only..

Message 10 of 18
pbejse
in reply to: Anonymous


@Anonymous wrote:

Hi pbejse,

Thanks for the idea and i just try the lisp...sort like nothing much difference as what i am doin currently..At moment, i would need to pick and select a certain block and change to my desire layer at the toolbar menu..


 

The code is more than that Lai 😉 It creates the layer if it does not exist and you dont need to pick all blocks indiviually, process all blocks on every layout tab.

Anyhoo.


@Anonymous wrote:

Hi pbejse,

Just wonder that if inside the lisp, can i add  additional others block name to be change to a pre-set layer too..cause at moment, i only have just a few preset block name that i wish it would automatic change to a preset layer only..


inside the lisp

(defun c:tolayer  (/ blklist ln _addsep AdlNm  ss i Adln)
      (vl-load-com)
      (setq _addsep (lambda (j) (strcat j ",")))
      (setq _effname
                 (lambda (k)
                       (vla-get-Effectivename
                             (vlax-ename->vla-object k))))
      (setq blklist '("EB10" "TEB10" "EB8" "TEB8"))
      (princ "\Current Block names on list")
            (foreach nm blklist (print nm)(princ))  
      (while (and
             (setq AdlNm (strcase (getstring "\nAdditional Block name/Enter for none:  ")))
             (setq AdlNm  (if (eq  AdlNm "") nil AdlNm)))
             (setq blklist (cons AdlNm blklist)))
             
            
      (if (and
           (setq Adln (strcase (getstring "\nEnter Layer name:<Eye Bolt> ")))
           (setq ln   (if (eq  Adln "") "Eye Bolt" Adln))
           (setq ss   (ssget "_x"
                            (list '(0 . "INSERT")
                                  (cons 2 (strcat 
                                        (apply 'strcat
                                               (mapcar '_addsep
                                                       blklist))"`*U*"))))))
            (repeat (setq i (sslength ss))
                  (if (member (_effname
                                    (setq en (ssname
                                                   ss
                                                   (setq i (1- i)))))
                              blklist)
                        (progn (setq e (entget en))
                               (entmod (subst (cons 8 ln)
                                              (assoc 8 e)
                                              e)))))
            (princ "\nBlock/s Not Found")
            )
      (princ)
      )

 

Prompt for additional Block names while inside the lisp

 

Command: tolayer
Current Block names on list
"EB10"
"TEB10"
"EB8"
"TEB8"
Additional Block name/Enter for none:  Banana

Additional Block name/Enter for none: Apple

Additional Block name/Enter for none:

Enter Layer name:<Eye Bolt> Safety

 

 

for Toolbars / Macro

 

(defun tolayer  (blklist ln / _addsep ss i)
      (vl-load-com)
      (setq _addsep (lambda (j) (strcat j ",")))
      (setq _effname
                 (lambda (k)
                       (vla-get-Effectivename
                             (vlax-ename->vla-object k))))
      (if (setq ss   (ssget "_x"
                            (list '(0 . "INSERT")
                                  (cons 2 (strcat 
                                        (apply 'strcat
                                               (mapcar '_addsep
                                                       blklist))"`*U*")))))
            (repeat (setq i (sslength ss))
                  (if (member (_effname
                                    (setq en (ssname
                                                   ss
                                                   (setq i (1- i)))))
                              blklist)
                        (progn (setq e (entget en))
                               (entmod (subst (cons 8 ln)
                                              (assoc 8 e)
                                              e)))))
            (princ "\nBlock/s Not Found")
            )
      (princ)
      )

 

^C^C(Tolayer '("EB10" "TEB10" "EB8" "TEB8" "AdditionalBlockName")  "Eye Bolt")

^C^C (Tolayer '("Bloknme1" "Bloknme2" "Bloknme3""Ear Bolt")

 

(defun c:TL1 ()(Tolayer '("EB10" "TEB10" "EB8" "TEB8" "AdditionalBlockName")  "Eye Bolt"))

(defun c:TL1 ()(Tolayer '("Bloknme1" "Bloknme2" "Bloknme3""Ear Bolt"))

 

^C^CTL1

^C^CTL2

 

Hope this helps

 

 

Message 11 of 18
Anonymous
in reply to: Anonymous

Hi pbejse,

Thanks for the lisp..I just try it and somehow i got another idea come out..Below is my idea...

 

Once activate the lisp:-

 

1) At command prompt, "Enter Layer Name" (after enter a layer name)

2) At command prompt, " Select block" (block selection by selecting blocks by cursor)

3) (Suggest that it will made all objects in the block to be change to the new layer)

 

Somehow i think this will be better. You think possible or not..Thanks in advance.

Message 12 of 18
pbejse
in reply to: Anonymous


@Anonymous wrote:

Hi pbejse,

Thanks for the lisp..I just try it and somehow i got another idea come out..Below is my idea...

 

Once activate the lisp:-

 

1) At command prompt, "Enter Layer Name" (after enter a layer name)

2) At command prompt, " Select block" (block selection by selecting blocks by cursor)

3) (Suggest that it will made all objects in the block to be change to the new layer)

 

Somehow i think this will be better. You think possible or not..Thanks in advance.



Smiley Very Happy

 

Listen Lai.. the 2nd code i posted [post # 8] does exactly what you describe ,

I think we're going in circles here  Smiley Wink

 

Message 13 of 18
Anonymous
in reply to: pbejse

Dear pbejse,

Just try the lisp on message 8/12.....It works as i mention...ask me to enter layer name, select block and it will change to the layer..but i wish to modify it abit so that the block that i pick, all the entities inside the block also will change to the new layer i put...

 

Example...

 

1) Block inside got a few entities with different layer

2) In the end, all these block i select will change to new layer including all the entities inside the block will change to the new layer....

 

Hope my explanation is understand. Thanks.

Message 14 of 18
pbejse
in reply to: Anonymous


@Anonymous wrote:

Dear pbejse,

Just try the lisp on message 8/12.....It works as i mention...ask me to enter layer name, select block and it will change to the layer..but i wish to modify it abit so that the block that i pick, all the entities inside the block also will change to the new layer i put...

 

Example...

 

1) Block inside got a few entities with different layer

2) In the end, all these block i select will change to new layer including all the entities inside the block will change to the new layer....

 

Hope my explanation is understand. Thanks.



Question: are the entiteis on the block not on layer 0"?

If they are.. what ever the parent blocks layer the entities will inherit the same layer.

 

Us here by practice always use Layer "0" when creating the blocks.You can on yoiur part redefine the blocks to followwhat i suggested , (that is puttign all layers to "0")

 

We can however modify the lisp to do that, but which one do you want to use [post # 8]?

 

 

Message 15 of 18
Anonymous
in reply to: pbejse

Ok, i want to use post 8 and able to change all different layers entities in a block to be follow same new layer i create..

Sorry for all these while confusion..As for summary as below:-

 

1) Ask user to key in new layer name at command prompt

2) Ask user to pick/select their desire block

3) All the selected block + internal entities in the selected block will also change to new layer given

 

Hope it can prevent any confusion.

Message 16 of 18
pbejse
in reply to: Anonymous


@Anonymous wrote:

Ok, i want to use post 8 and able to change all different layers entities in a block to be follow same new layer i create..

Sorry for all these while confusion..As for summary as below:-

 

1) Ask user to key in new layer name at command prompt

2) Ask user to pick/select their desire block

3) All the selected block + internal entities in the selected block will also change to new layer given

 

Hope it can prevent any confusion.


This codewill not modify the color/linetype of entiteis inside the block and Layer names are without spaces [" "]

But you can use this

(getstring T "\nEnter Layer name: ")) to allow spaces  in layer name i.e. "Banana Cake"

 

HTH

Message 17 of 18
Anonymous
in reply to: pbejse

Hi pbejse, thanks alot for the lisp..Appreciate it... Btw, i notice that the new layer i create it's in color "0" by default..Wonder how should i make the lisp to be set it to color "253" by every new layer i create..all i need is the layer to be in color "0"..no need to make any color changes to the entities inside the block..

Message 18 of 18
pbejse
in reply to: Anonymous


@Anonymous wrote:

Hi pbejse, thanks alot for the lisp..Appreciate it... Btw, i notice that the new layer i create it's in color "0" by default..Wonder how should i make the lisp to be set it to color "253" by every new layer i create..all i need is the layer to be in color "0"..no need to make any color changes to the entities inside the block..


You are welcome Lai.
I think you meant color "7"  (default color for layer). Now you need target layers color to be 253?

 

add this after

 

......

(foreach itm blklist
                   (B2Laynmae itm ln aDoc))
                  (vla-put-color (vla-item (vla-get-layers aDoc) ln) 253)
                  )
            )
      (vla-regen aDoc acActiveViewport).....

 

HTH

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

Post to forums  

Autodesk Design & Make Report

”Boost