# Thread: How to Find a Layer if It Exists?

1. Login to Give a bone

## How to Find a Layer if It Exists?

Hello ALL,

I had a problem with my routine.
What I want is:
(1) Find a layer "Landscape" if it exists;
(2) If the layer exist, change it's color to "green" bylayer.
(3) If it doesn't exist, create it then set it to current.

I can do the steps (2) & (3) except step (1)

Any helps would be appreciated.

2. Login to Give a bone

## Re: How to Find a Layer if It Exists?

Try
Code:
`(tblsearch "LAYER" "Landscape")`

3. Login to Give a bone

## Re: How to Find a Layer if It Exists?

Originally Posted by Opie
Try
Code:
`(tblsearch "LAYER" "Landscape")`
Thanks, tblsearch is the one, but how could it tell if it found the layer?
I mean, what is the statement exactly?
Will it be:
(if (eq (tblsearch "LAYER" "Landscape"))
(command "-layer" "set" "Landscape" "color" "3" "" ""))

I am sure that the eq function is wrong.
But what is the replacement for it?

4. Login to Give a bone

## Re: How to Find a Layer if It Exists?

(if (tblsearch "LAYER" "Landscape")
(command "_-layer" "_set" "Landscape" "_color" "3" "" "")
(command "_-layer" "_make" "Landscape" "_color" "3" "" "")
)

5. Login to Give a bone

## Re: How to Find a Layer if It Exists?

Originally Posted by BoKirra
...but how could it tell if it found the layer?
The (tblsearch) function will return nil if the table entry is not found.
So you just test it for a non-nil value.

http://www.hyperpics.com/customizati...nce.asp?id=200

6. Login to Give a bone

## Re: How to Find a Layer if It Exists?

Originally Posted by rkmcswain
The (tblsearch) function will return nil if the table entry is not found.
So you just test it for a non-nil value.

http://www.hyperpics.com/customizati...nce.asp?id=200
with thanks to all.

7. Login to Give a bone

## Re: How to Find a Layer if It Exists?

Originally Posted by Opie
Try
Code:
`(tblsearch "LAYER" "Landscape")`
From the HELP, I found the following description for the tblsearch function:
(tblsearch table-name symbol [setnext])

With your sample, the table-name is LAYER.
And another one I know is STYLE.

How to get the complete list of table-name?

Thanks again.

8. Login to Give a bone

## Re: How to Find a Layer if It Exists?

Originally Posted by BoKirra
. . . How to get the complete list of table-name?
From the HELP tblnext, valid table-name values are "LAYER", "LTYPE", "VIEW", "STYLE", "BLOCK", "UCS", "APPID", "DIMSTYLE", and "VPORT".

: ) Happy Computing !

kennet

9. Login to Give a bone

## Re: How to Find a Layer if It Exists?

And to see exactly what's returned if the layer is found with tblsearch, check the DXF / TABLES Section in Developer Help.

10. Login to Give a bone

## Re: How to Find a Layer if It Exists?

Originally Posted by kennet.sjoberg
From the HELP tblnext, valid table-name values are "LAYER", "LTYPE", "VIEW", "STYLE", "BLOCK", "UCS", "APPID", "DIMSTYLE", and "VPORT".

: ) Happy Computing !

kennet
Thank you & also thanks to irneb.

Page 1 of 2 12 Last

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•