Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Valued Contributor
pixelarch
Posts: 74
Registered: ‎05-07-2013
Message 1 of 14 (3,602 Views)
Accepted Solution

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

3602 Views, 13 Replies
09-03-2013 08:52 PM

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

*Expert Elite*
Lee_Mac
Posts: 1,109
Registered: ‎12-29-2009
Message 2 of 14 (3,561 Views)

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

09-04-2013 03:29 AM 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.

Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)
Expert Elite
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Valued Contributor
pixelarch
Posts: 74
Registered: ‎05-07-2013
Message 3 of 14 (3,531 Views)

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

09-04-2013 09:11 PM 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.

 

 

 

 

*Expert Elite*
Lee_Mac
Posts: 1,109
Registered: ‎12-29-2009
Message 4 of 14 (3,508 Views)

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

09-05-2013 02:26 AM 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.

Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)
Expert Elite
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Valued Contributor
pixelarch
Posts: 74
Registered: ‎05-07-2013
Message 5 of 14 (3,465 Views)

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

09-08-2013 11:18 PM 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.

*Expert Elite*
Lee_Mac
Posts: 1,109
Registered: ‎12-29-2009
Message 6 of 14 (3,454 Views)

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

09-09-2013 03:08 AM in reply to: pixelarch

No problem :smileyhappy:

 

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)
Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)
Expert Elite
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Valued Contributor
pixelarch
Posts: 74
Registered: ‎05-07-2013
Message 7 of 14 (3,417 Views)

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

09-10-2013 03:41 AM in reply to: Lee_Mac

It works perfectly. Much appreciate!

*Expert Elite*
Lee_Mac
Posts: 1,109
Registered: ‎12-29-2009
Message 8 of 14 (3,410 Views)

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

09-10-2013 04:04 AM in reply to: pixelarch

You're welcome! :smileyhappy:

Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)
Expert Elite
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Valued Contributor
pixelarch
Posts: 74
Registered: ‎05-07-2013
Message 9 of 14 (3,338 Views)

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

09-17-2013 08:00 PM 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.

*Expert Elite*
Lee_Mac
Posts: 1,109
Registered: ‎12-29-2009
Message 10 of 14 (3,222 Views)

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

10-01-2013 08:28 AM 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)

 

Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)
Expert Elite
With Mathematics there is the possibility of perfect rigour, so why settle for less?

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community