Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Getting an objects layer

8 REPLIES 8
Reply
Message 1 of 9
donied
632 Views, 8 Replies

Getting an objects layer

How can I get the layer that an entity is on. I have tried numerous method but they don't seen to be retrievin gthe layer information
8 REPLIES 8
Message 2 of 9
Anonymous
in reply to: donied

(setq en (car (entsel)))

; using vlisp
(vl-load-com)
(setq ob (vla-item (vla-get-layers (vla-get-activedocument
(vlax-get-acad-object))) (cdr (assoc 8 (entget en)))
(vlax-dump-object ob T)

; using dxf and lisp
(setq ed (tblsearch "layer" (cdr (assoc 8 (entget en)))))

note that one could also

(setq ob (vlax-ename->vla-object en))
(setq ly (vla-item (vla-get-layers (vla-get-activedocument
(vlax-get-acad-object))) (vlax-get ob 'Layer)))
(vlax-dump-object ly T)

--
TDP

First things first, but not necessarily in that order.

The Doctor
wrote in message
news:6331891@discussion.autodesk.com...
How can I get the layer that an entity is on. I have tried numerous method
but they don't seen to be retrievin gthe layer information
Message 3 of 9
Anonymous
in reply to: donied

On 2/7/2010 12:01 PM, The Dark Princess wrote:
> (setq en (car (entsel)))
>
> ...
> ; using dxf and lisp
> (setq ed (tblsearch "layer" (cdr (assoc 8 (entget en)))))
>
> ...
>

No need for (tblsearch) -- we know it's on a layer. With plain old LISP,
all you need is

(setq en (car (entsel)))
(setq lay (cdr (assoc 8 (entget en))))
Message 4 of 9
Anonymous
in reply to: donied

Bill,
She was showing the OP how to get the layer's information, not just its
name, per OP's request. Your method retrieves only the name.

"Bill Gilliss" wrote in message
news:6331909@discussion.autodesk.com...
On 2/7/2010 12:01 PM, The Dark Princess wrote:
> (setq en (car (entsel)))
>
> ...
> ; using dxf and lisp
> (setq ed (tblsearch "layer" (cdr (assoc 8 (entget en)))))
>
> ...
>

No need for (tblsearch) -- we know it's on a layer. With plain old LISP,
all you need is

(setq en (car (entsel)))
(setq lay (cdr (assoc 8 (entget en))))
Message 5 of 9
Anonymous
in reply to: donied

On 2/7/2010 1:18 PM, Doug Broad wrote:
> Bill,
> She was showing the OP how to get the layer's information, not just its
> name, per OP's request. Your method retrieves only the name.
>
>
I see your point. The request was not exactly clear -- I had read it as
a request for how to get a layer name. If it was more than that, she's
right.
Message 6 of 9
donied
in reply to: donied

Thanks for your feedback. Its the layer name I'm after so I can change onto that layer.
Message 7 of 9
donied
in reply to: donied

I have tried the above code and it does'nt appear to work. I propably should have explained myself in more detail. The program asks the user to select objects. The routine then uses a while loop to go through the selection set and extrude each object.

My code is as follows
(while ( (setq en (ssname sset cntr))
(command ".extrude" en "" extrudedist)

All works fine. But before the extrude I would like to get the layer name of each object and change onto the layer the object so that each object is extruded on the correct layer.

Thanks
Message 8 of 9
scottbolton
in reply to: donied

Dan,

Set the layer like this:

(setvar "CLAYER" (cdr (assoc 8 (entget en))))

S
Message 9 of 9
devitg
in reply to: donied

So, it shall be  

 

 

(while ( (setq en (ssname sset cntr))
(setvar "CLAYER" (cdr (assoc 8 (entget en))))
(command ".extrude" en "" extrudedist)

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost