Author Topic: Identify layer color from entity selected  (Read 3893 times)

0 Members and 1 Guest are viewing this topic.

Jim C

  • Guest
Identify layer color from entity selected
« on: October 15, 2012, 04:45:04 PM »
Hello all, new user on this forum.

I've searched (too long) for a possible solution... I've got existing code that will allow the user to select text and scale a copy of said text onto a new layer, but the problem is that the new layer is created as color 7, instead of taking on same layer properties as the source layer...

Can anyone shed some light on this?  I'm just a hacker at LISP and have tried too many things without any success....  Attached is the source code.

Jim.

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Identify layer color from entity selected
« Reply #1 on: October 15, 2012, 05:00:49 PM »
Welcome to the swamp Jim  :-) ... see if this sheds any light on how to get layer properties and create a new layer from a selected entity:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ _dxf e layer)
  2.   (defun _dxf (code ename)
  3.     (if ename
  4.       (cdr (assoc code (entget ename)))
  5.     )
  6.   )
  7.   (if (setq e (car (entsel)))
  8.     (progn
  9.       (setq layer (tblobjname "Layer" (_dxf 8 e)))
  10.       (entmakex (subst (cons 2 (strcat (_dxf 8 e) "_copy")) (assoc 2 (entget layer)) (entget layer))
  11.       )
  12.     )
  13.   )
  14. )

« Last Edit: October 15, 2012, 05:04:08 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Jim C

  • Guest
Re: Identify layer color from entity selected
« Reply #2 on: October 15, 2012, 06:48:51 PM »
Hi ronjon,

Yep, looked at your code and looks similar to what I've already got code for, but I'm wondering how to analyze the original layers' color, save it to a variable, make the new layer name (by appending it with user input) and then change the newly created layer color to match the original layers' color

It's the analyzing of the original layer color, that I'm having issues with.  I can get the LISP that I originally loaded to change the newly created layer to what ever color I want; just can't get it saved to a variable to make that change...

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Identify layer color from entity selected
« Reply #3 on: October 15, 2012, 07:51:56 PM »
To retrieve the colour of a Layer:

Code - Auto/Visual Lisp: [Select]
  1. (cdr (assoc 62 (tblsearch "LAYER" <your layer here>)))

(may require the use of abs if Layer is off)

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Identify layer color from entity selected
« Reply #4 on: October 15, 2012, 08:37:28 PM »
Hi ronjon,

Yep, looked at your code and looks similar to what I've already got code for, but I'm wondering how to analyze the original layers' color, save it to a variable, make the new layer name (by appending it with user input) and then change the newly created layer color to match the original layers' color

It's the analyzing of the original layer color, that I'm having issues with.  I can get the LISP that I originally loaded to change the newly created layer to what ever color I want; just can't get it saved to a variable to make that change...

If you use the code above before you entmod your entity, the color should be matched.

Look into tblobjname and tblsearch as Lee has used.

Paste this into the command line. It may also give you some insight.

Code - Auto/Visual Lisp: [Select]
  1.   (vlax-ename->vla-object (tblobjname "layer" "0"))
  2.   t
  3. )
« Last Edit: October 15, 2012, 08:43:25 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Jim C

  • Guest
Re: Identify layer color from entity selected
« Reply #5 on: October 17, 2012, 11:04:42 AM »
Thank you very much gentlemen!!!!  With your assistance, my LISP routine now does exactly what I want....

Jim.