Layer Entity Data

Discussion in 'AutoCAD' started by Greg Young, Apr 20, 2006.

  1. Greg Young

    Greg Young Guest

    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
     
    Greg Young, Apr 20, 2006
    #1
  2. Greg Young

    Greg Young Guest

    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
     
    Greg Young, Apr 20, 2006
    #2
  3. Greg Young

    mguzik Guest

    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)
    )
    )
    )
    )
     
    mguzik, Apr 22, 2006
    #3
  4. Greg Young

    Greg Young Guest

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

    Thank you!
     
    Greg Young, Apr 24, 2006
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.