Change Object's Layer keeping LineType property.

Change Object's Layer keeping LineType property.

GeryKnee
Advocate Advocate
1,058 Views
8 Replies
Message 1 of 9

Change Object's Layer keeping LineType property.

GeryKnee
Advocate
Advocate

 

I need folowing Lisp code: 

If current (active) selection exists,

for every item of selection,

Let ItemLayer=Item.layer

About Item properties:

Set  Item.layer = ActiveLayer

Set  Item.Color = AcBylayer

LineType:

If Item.LineType="Bylayer" -> Set LineType to ItemLayer.LineType

.......

 

 

0 Likes
Accepted solutions (1)
1,059 Views
8 Replies
Replies (8)
Message 2 of 9

Kent1Cooper
Consultant
Consultant

@GeryKnee wrote:

 

I need folowing Lisp code: 

If current (active) selection exists,

for every item of selection,

Let ItemLayer=Item.layer

About Item properties:

Set  Item.layer = ActiveLayer

Set  Item.Color = AcBylayer

LineType:

If Item.LineType="Bylayer" -> Set LineType to ItemLayer.LineType

.......


I'm not familiar with that code language, but if I'm interpreting it correctly, try this [untested]:

 

(if (setq ss (ssget "_I")); there's a selection

  (repeat (setq n (sslength ss)); then

    (setq

      ent (ssname ss (setq n (1- n)))

      edata (entget ent)

    ); setq

    (entmod

      (append

        edata

        (list (assoc 6 (tblsearch "layer" (cdr (assoc 8 edata))))); linetype of its Layer

        '((62 . 256)); color ByLayer

      ); append

    ); entmod

  ); repeat

); if

Kent Cooper, AIA
0 Likes
Message 3 of 9

GeryKnee
Advocate
Advocate

Hello Kent,

Unfortunatelly, the code is not doing the work must do.

As you say, the syntax is not familiar to you.

Let Current layer be "0"

An Item  (member of current selection) wich

Lays On Lay1 and has Color property ByLayer and LineType ByLayer 

         Layer Lay1  has Color property Red and LineType ByLayer AcadIso02W100

After Routine

Item Lays on "0" with Color Bylayer as any other item selected; (color maybe changes)

But the Line type hat to remain same. So Line type will be  the Line type of Lay1.

Regards,

Gery.

0 Likes
Message 4 of 9

GeryKnee
Advocate
Advocate

Hello Kent,

Unfortunatelly, the code is not doing the work must do.

As you say, my syntax is not familiar to you.

an example

Let Current layer be "0" coloured blue

An Item  (member of current selection) wich

Lays On Lay1 and has Color property ByLayer and LineType ByLayer 

         , the Layer Lay1  has Color property Red and LineType AcadIso02W100

After Routine

Item Lays on "0" with Color Bylayer (now i see it blue) as any other item selected;

                         (color maybe changes)

But the Line type hat to remain same (to be viewed as before) .

     So Line type will be  the Line type of Lay1 .New Line Type is not ByLayer but AcadIso02W100

Regards,

Gery.

0 Likes
Message 5 of 9

Kent1Cooper
Consultant
Consultant
Accepted solution

(if (setq ss (ssget "_I")); there's a selection

  (repeat (setq n (sslength ss)); then

    (setq

      ent (ssname ss (setq n (1- n)))

      edata (entget ent)

    ); setq

    (entmod

      (append

        edata

        (list (assoc 6 (tblsearch "layer" (cdr (assoc 8 edata))))); linetype of its Layer

        '((62 . 256)); color ByLayer

        (list (cons 8 (getvar 'clayer))); put on current Layer

      ); append

    ); entmod

  ); repeat

); if

Kent Cooper, AIA
Message 6 of 9

GeryKnee
Advocate
Advocate

Yes Kent,

Exactly this

Thenk you very muxh

Regards,

Gery.

0 Likes
Message 7 of 9

carlos_delaTorreQ8DF9
Explorer
Explorer

HI,

 

I'm very new with this topic, I know now how to use this LISP, but i really need this. can you explain me a bit more how to make it run. thanks very much

0 Likes
Message 8 of 9

Kent1Cooper
Consultant
Consultant

Copy this version, put into a command definition:

(defun C:WHATEVER (/ ss n ent edata)
  (if (setq ss (ssget "_I")); there's a selection
    (repeat (setq n (sslength ss)); then
      (setq
        ent (ssname ss (setq n (1- n)))
        edata (entget ent)
      ); setq
      (entmod
        (append
          edata
          (list (assoc 6 (tblsearch "layer" (cdr (assoc 8 edata))))); linetype of its Layer
          '((62 . 256)); color ByLayer
          (list (cons 8 (getvar 'clayer))); put on current Layer
        ); append
      ); entmod
    ); repeat
  ); if
  (prin1)
)

Paste it into a plain-text editor such as Notepad.  Change WHATEVER to a command name that will be meaningful to you.  Save it to a file with a .lsp filetype ending.

In a drawing, use the APPLOAD command, navigate to where you saved it, and Load it.

 

As written [because that was the context in Message 1], it requires you to SELECT OBJECTS FIRST, then enter the command name.  If you prefer, it could be modified to not require pre-selection of objects, but to permit that but also let you enter the command name first and then be asked to select objects.

Kent Cooper, AIA
0 Likes
Message 9 of 9

carlos_delaTorreQ8DF9
Explorer
Explorer

thaks very much, it worked like a charm!

 

Kind Regards

 

Carlos

0 Likes