Layer Entity Data

How can I make lisp return entity data for a known layer that can then be passed to the entmod command to modify the layer?

I tried:

(tblsearch "layer" layname)

But this doesn't seem to return enough information to pass to entmod.

I *could* use "command", but that would be creating a half-assed lisp routine IMO.

TIA

Greg

Reply to
Greg Young
Loading thread data ...

Hey Greg,

IMO: Keep it simple. If "command" works, use it.

Reply to
CADmechanic

entmod can modify graphical AND non graphical entities (which is what a layer is).

The goal is to get the entity data for a layer that can be passed to entmod.

Here is an example of why tblsearch doesn't work in this case:

(defun laytog (layname) (setq lay (tblsearch "layer" layname)) (setq lstate (cdr (nth 2 lay))) (cond ((= lstate 0) (setq modlay (subst (cons 70 1) (assoc 70 lay) lay))) ((= lstate 1) (setq modlay (subst (cons 70 0) (assoc 70 lay) lay))) ) (entmod modlay) )

The list of dotted pairs returned by tblsearch in this function is this:

((0 . "LAYER") (2 . "GRID") (70 . 1) (62 . 2) (6 . "Continuous"))

This information cannot be passed to entmod because it is missing the -1 group (the entity name), which is the primary identifier for objects in the database.

So... what function would I use to retrieve the correct list of dotted pairs information from the database so that it can be modified and updated in the database?

Greg

roy wrote:

Reply to
Greg Young

I thought entmod was for modifying entities. It sounds like you want to change some of the data describing a layer in it's table.

Maybe a little clearer picture of what you would like to achieve would help.

Reply to
roy

from the vlisp help file:

The entmod function updates database information for the entity name specified by the ?1 group in elist. The primary mechanism through which AutoLISP updates the database is by retrieving entities with entget, modifying the list defining an entity, and updating the entity in the database with entmod. The entmod function can modify both graphical and nongraphical objects.

I think you have a logic error. The layer table is definately a nongraphical entity, but just because entmod can modify both graphical and nongraphical objects does not mean it can modify ALL nongraphical objects. eh?

It would be an interesting piece of code, I have tried similar and hit the same wall. I see the value. You could do some neat stuff modifying the 70's.....

I am going to sit back and wait and see if there is a sharper knife in the drawer here.

Reply to
roy

Give this a try:

;;;******************************************************************************************* ;;; FUNCTION: ENTMOD-LAYER ;;; DESCRIPTION: MODIFIES LAYER TO ARGS ;;; ARGS: name, color, linetype ;;; EXAMPLE: (ENTMOD-LAYER "BORDER" 4 "Continuous") ;;; RETURNS: nil ;;;******************************************************************************************* (defun ENTMOD-LAYER (name color ltype / en el) (setq en (tblobjname "LAYER" name)) (if en (progn (setq el (entget en) el (subst (cons 62 color) (assoc 62 el) el) el (subst (cons 6 ltype) (assoc 6 el) el) ) (entmod el) )

) )

or this one to create a layer:

;;;******************************************************************************************* ;;; FUNCTION: Entmake-LAYER ;;; DESCRIPTION: CREATES LAYER TO ARGS ;;; ARGS: name, color, linetype ;;; EXAMPLE: (Entmake-LAYER "Test 2" 5 "Continuous") ;;; RETURNS: nil ;;;******************************************************************************************* (defun Entmake-LAYER (name color ltype) (if (not (tblobjname "LAYER" name)) (entmake (list '(0 . "LAYER") '(100 . "AcDbSymbolTableRecord") '(100 . "AcDbLayerTableRecord") (cons 2 name) '(70 . 0) (cons 62 color) (cons 6 ltype) '(290 . 1) '(370 . -3) ) ) ) )

roy wrote:

Reply to
mguzik

Worked like a charm. The problem I was having was that I was using tblsearech instead of tblobjname.

Thank you!

snipped-for-privacy@laws> Give this a try:

;;;*******************************************************************************************

;;;*******************************************************************************************

;;;*******************************************************************************************

;;;*******************************************************************************************

Reply to
Greg Young

DITTOS. MANY THANKS.

Reply to
roy

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.