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

Change all block element to Layer 0 without changing color, linetype

25 REPLIES 25
SOLVED
Reply
Message 1 of 26
pixelarch
30921 Views, 25 Replies

Change all block element to Layer 0 without changing color, linetype

Dear All,

 

Please find the attached. I have too many blocks with specific layers inside.

 

Could you help me to develope lisp can change all to layer 0 but keep color and linetype as it is.

 

I will use this as a part of script to change multiple block.

 

Thanks

25 REPLIES 25
Message 2 of 26
Lee_Mac
in reply to: pixelarch

See my generalised 'Apply to Block Objects' function - that page also contains an example program demonstrating how to utilise the function to move all objects in a block to layer "0", as you require.

Message 3 of 26
pixelarch
in reply to: Lee_Mac

Thanks Lee,

 

I dont need only change all block elements to 0. I also need change continuos line to bylayer, keep other linetype as it is or change them all to hidden line.

 

Does this help?

 

Until now the attached lisp can help me but still need customize a little bit to change all linetype (except continuos line) to hidden line, lts = 1

 

Thanks again.

 

 

 

 

Message 4 of 26
Lee_Mac
in reply to: pixelarch

First ensure that my Apply to Block Objects function is loaded, then the following program will move all objects within the definition of a selected block to Layer "0", will set objects with Continuous linetype to ByLayer linetype, and will set objects with any linetype except Continuous to use the Hidden linetype:

 

(defun c:test ( / s )
    (princ "\nSelect Block: ")
    (if (setq s (ssget "_+.:E:S" '((0 . "INSERT"))))
        (LM:ApplytoBlockObjects
            (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
            (vla-get-effectivename (vlax-ename->vla-object (ssname s 0)))
           '(lambda ( obj )
                (vla-put-layer obj "0")
                (if (= "CONTINUOUS" (strcase (vla-get-linetype obj)))
                    (vla-put-linetype obj "BYLAYER")
                    (vla-put-linetype obj "HIDDEN")
                )
            )
        )
    )
    (princ)
)
(vl-load-com) (princ)

 

Please note: the linetype "HIDDEN" must be loaded in the drawing.

Message 5 of 26
pixelarch
in reply to: Lee_Mac

Thanks a milliion.

 

It works well but change all linetype BYLAYER to HIDDEN. If linetype bylayer i want to keep as it is.

 

Is it posible if i want linetype scale of HIIDDEN is 1?

 

Thanks.

Message 6 of 26
Lee_Mac
in reply to: pixelarch

No problem Smiley Happy

 

Please try the following code:

 

(defun c:test ( / s )
    (princ "\nSelect Block: ")
    (if (setq s (ssget "_+.:E:S" '((0 . "INSERT"))))
        (LM:ApplytoBlockObjects
            (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
            (vla-get-effectivename (vlax-ename->vla-object (ssname s 0)))
           '(lambda ( obj / lin )
                (vla-put-layer obj "0")
                (setq lin (strcase (vla-get-linetype obj)))
                (cond
                    (   (= "BYLAYER" lin))
                    (   (= "CONTINUOUS" lin)
                        (vla-put-linetype obj "BYLAYER")
                    )
                    (   t
                        (vla-put-linetype obj "HIDDEN")
                        (vla-put-linetypescale obj 1.0)
                    )
                )
            )
        )
    )
    (princ)
)
(vl-load-com) (princ)
Message 7 of 26
pixelarch
in reply to: Lee_Mac

It works perfectly. Much appreciate!

Message 8 of 26
Lee_Mac
in reply to: pixelarch

Message 9 of 26
pixelarch
in reply to: Lee_Mac

Dear Lee,

 

Could you revise a little bit to ingnore defpoints layer? It means keep all in defpoints as it is.

 

Thanks.

Message 10 of 26
Lee_Mac
in reply to: pixelarch


@pixelarch wrote:

Dear Lee,

 

Could you revise a little bit to ingnore defpoints layer? It means keep all in defpoints as it is.

 

Thanks.


 

The following code will not modify objects residing on the defpoints layer:

 

(defun c:test ( / s )
    (princ "\nSelect Block: ")
    (if (setq s (ssget "_+.:E:S" '((0 . "INSERT"))))
        (LM:ApplytoBlockObjects
            (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
            (vla-get-effectivename (vlax-ename->vla-object (ssname s 0)))
           '(lambda ( obj / lin )
                (if (/= "DEFPOINTS" (strcase (vla-get-layer obj)))
                    (progn
                        (vla-put-layer obj "0")
                        (setq lin (strcase (vla-get-linetype obj)))
                        (cond
                            (   (= "BYLAYER" lin))
                            (   (= "CONTINUOUS" lin)
                                (vla-put-linetype obj "BYLAYER")
                            )
                            (   t
                                (vla-put-linetype obj "HIDDEN")
                                (vla-put-linetypescale obj 1.0)
                            )
                        )
                    )
                )
            )
        )
    )
    (princ)
)
(vl-load-com) (princ)

 

Message 11 of 26
Kent1Cooper
in reply to: pixelarch


@pixelarch wrote:

.... 

Could you revise a little bit to ingnore defpoints layer? It means keep all in defpoints as it is.

....


For one that allows selection of more than one Block, and processing of all Block definitions among the selection, don't miss my reply on the other thread about this, here [one of the drawbacks of having more than one thread on the same topic...].

Kent Cooper, AIA
Message 12 of 26
Lee_Mac
in reply to: Kent1Cooper

There's more than one way to skin a cat Kent Smiley Wink

Message 13 of 26
Anonymous
in reply to: Lee_Mac

Hi all,

 

Lee, I have another request and hope you will not find it tedious as enough time passed since you modified your script 🙂 

 

I have been, unsuccessfully, trying to make an option where instead applying lintype you leave linetypes but change line colour to ie. 251 (we print that super thin). So any object that was not by layer to become gray. 

Also, is it possible to apply it to nested blocks? 

 

Thanks!

Janko

Message 14 of 26
Anonymous
in reply to: Lee_Mac

Great routine - now if we could modify to build a list of multiple blocks and step through them - I have a drawing with literally hundreds of blocks that were incorrectly formed (exported from Vectorworks). Vectorworks also assigns all entities a specific color, so we need to change all colors to bylayer, too. I would like to use the filter command to select all blocks, then apply your routine to the "previous" selection set - modifying them all in place in one fell swoop.

BTW, your website is very helpful - I will return and donate!

Any help greatly appreciated!

Message 15 of 26
Anonymous
in reply to: Lee_Mac

Hi Lee Mac !

 

Your program is just great but it only works one by one block. Is there a way to do a multiple selection and run the program to all ?

 

It would be perfect!

 

Thank you very much for your help !

Message 16 of 26
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

.... 

Your program is just great but it only works one by one block. Is there a way to do a multiple selection and run the program to all ?

...

 

@Anonymous wrote:

Great routine - now if we could modify to build a list of multiple blocks and step through them....


Welcome to the Forums, snaboxx!  Try out the link in my earlier Reply on this thread.

Kent Cooper, AIA
Message 17 of 26
Anonymous
in reply to: Kent1Cooper

Wouah thank you Kent it´s perfect!!

 

I wish you the best!

Message 18 of 26
Anonymous
in reply to: Lee_Mac

This script is to make all objects within a block to be on layer "0" ... correct?

 

I keep attempting to run this (this is my first script show) and nothing happens to any of the blocks?

 

Ideas?

 

This is very important to my firm!

Message 19 of 26
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

This script is to make all objects within a block to be on layer "0" ... correct?

 

I keep attempting to run this (this is my first script show) and nothing happens to any of the blocks?

....


When you say "nothing happens," do you mean nothing is visibly any different?  If so, that's exactly what the routines on this thread are meant to do -- see the end of the Subject line.  They change everything to be on Layer 0, but they assign override color(s) and linetype(s) from the original Layer(s) of the Block's components, so the result shouldn't be apparent visibly.

 

To test whether the routine, whichever one you're talking about [and it's not a "Script," by the way -- that has a specific meaning in AutoCAD, different from what these AutoLisp routines are] did what it's supposed to do, run it on some Block(s), then Explode one.  The objects resulting should all be on Layer 0, but with various different color and linetype overrides if they were originally on different Layers when the Block was defined.  If they're not all on Layer 0, it would help if you can post a drawing file with some before-and-after conditions.

 

If you want everything forced to Layer 0 and ByLayer in color and linetype [and presumably with default values in other properties], there are certainly routines available to do that [and the routines on this thread could easily be adjusted to work that way], but this thread was for a different purpose.

Kent Cooper, AIA
Message 20 of 26
Anonymous
in reply to: Lee_Mac

How do you use this text? Put into a script file?

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report