Author Topic: Getting a Layer Name  (Read 1731 times)

0 Members and 1 Guest are viewing this topic.

MeasureUp

  • Bull Frog
  • Posts: 462
Getting a Layer Name
« on: May 18, 2018, 12:51:17 AM »
I am wondering if there is another way to get layer name.
Here is what I have to get a layer name.
Code: [Select]
(cdr (assoc 2 (list (nth 1 (tblsearch "layer" "MyLayer")))))
Thanks in advance.

BIGAL

  • Swamp Rat
  • Posts: 1414
  • 40 + years of using Autocad
Re: Getting a Layer Name
« Reply #1 on: May 18, 2018, 03:54:34 AM »
Tblsearch does just that checks to see if a layer exists, please explain more what it is your trying to do. Do just want to see if it exists and if not make it ?
A man who never made a mistake never made anything

Coder

  • Swamp Rat
  • Posts: 827
Re: Getting a Layer Name
« Reply #2 on: May 18, 2018, 05:57:30 AM »
I am wondering if there is another way to get layer name.
Here is what I have to get a layer name.
Code: [Select]
(cdr (assoc 2 (list (nth 1 (tblsearch "layer" "MyLayer")))))
Thanks in advance.

You already have the layer name there "MyLayer". Haven't you?

MeasureUp

  • Bull Frog
  • Posts: 462
Re: Getting a Layer Name
« Reply #3 on: May 18, 2018, 08:48:55 AM »
Sorry guys. What I am trying to do is comparing the layer names. If they are matched then I will do the next tasks.
I am thinking if there is an approach to get layer name other than the code I mentioned before.
Hope this is not confused.

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Getting a Layer Name
« Reply #4 on: May 18, 2018, 09:48:48 AM »
If I have to do something like that repeatedly, especially if it's a sub-set of all layers, I'll iterate over the layers and put the names and/or properties into a list organized how it best suits the task at hand.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

JohnK

  • Administrator
  • Seagull
  • Posts: 10643
Re: Getting a Layer Name
« Reply #5 on: May 18, 2018, 10:49:13 AM »
Agree on the list.

Also, resist the temptation to organize/clean/etc that list once you gather the information (unless you have to) because you have tools at your disposal like ASSOC to grab information from that list quickly. Your program doesn't need to iterate a list looking for an item more often then not--with lookup type of functions like ASSOC-. -i.e. Don't waste (computer/programming/cycle) time cleaning that list unless you have to; use lookup functions instead.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

MeasureUp

  • Bull Frog
  • Posts: 462
Re: Getting a Layer Name
« Reply #6 on: May 20, 2018, 09:42:27 PM »
Appreciate your inputs. Thanks guys.