Finding the layer of an attribute's insert in an xref block.

Discussion in 'AutoCAD' started by Allen Johnson, Aug 6, 2004.

  1. I'm trying to find out what layer the INSERT of a selected ATTRIBUTE is on when the attribute is in
    an xreff'd INSERT.

    I'm using nentsel to select the attribute. Using the code below, if the attribute of the block is
    on layer "0", it returns "0", but I really want to know the layer that it's block is on. I've
    checked the Xref and the block is on layer "A-Anno-Text". But I can't seem to figure out how to get
    the function to return "A-Anno-Text".

    Any ideas?

    ;;------------------------------------------------------------------------------------------

    (defun C:FA (/ e ee eee la txt pos nb)

    (setq e (nentsel "Select object:"))
    (terpri)

    (if (= (type e) 'LIST)
    (progn
    (if (= (length e) 4)
    ; then it's a nested block object
    (setq nb (print (last e)) ; name list of the nested blocks
    ee (terpri)
    ee (foreach eee nb
    (setq ee (entget eee))
    (princ (field 0 ee))
    (princ "\t : \t")
    (princ (field 2 ee))
    (princ "\t : \t")
    (princ (field 8 ee))
    (princ "\n")
    )
    la (if (= (length nb) 1)
    (progn ; not a nested block, just return the name of the xref the selected component is on
    (setq ee (entget (car e)))
    (field 8 ee)
    )
    (progn ; it's a nested block, return the name of the layer of the innermost block
    (setq nb (car nb) ; innermost block object
    ee (entget nb)
    ; entity list of the innermost block
    )
    (field 8 ee)
    )
    )
    )
    )
    ; else it's a regular object, so get its layer name
    (setq e (entget (car e)))
    (princ (field 0 ee))
    (princ "\t : \t")
    (princ (field 2 ee))
    (princ "\t : \t")
    (princ (field 8 e))
    (princ "\n")
    )
    )
    (princ)
    )

    ;;------------------------------------------------------------------------------------------

    (defun FIELD (val ent) (cdr (assoc val ent)))

    ;;------------------------------------------------------------------------------------------
     
    Allen Johnson, Aug 6, 2004
    #1
  2. Give this a shot:

    (defun C:Test (/ pickObj myObj)
    (vl-load-com)
    (setq pickObj (nentsel))
    (setq myObj (vlax-EName->vla-Object (car pickObj)))
    (vla-Get-Layer (vla-ObjectIDToObject
    (vla-Get-Database myObj)
    (vla-Get-OwnerID myObj))))


    --
    R. Robert Bell


    I'm trying to find out what layer the INSERT of a selected ATTRIBUTE is on
    when the attribute is in
    an xreff'd INSERT.

    I'm using nentsel to select the attribute. Using the code below, if the
    attribute of the block is
    on layer "0", it returns "0", but I really want to know the layer that it's
    block is on. I've
    checked the Xref and the block is on layer "A-Anno-Text". But I can't seem
    to figure out how to get
    the function to return "A-Anno-Text".

    Any ideas?

    ;;--------------------------------------------------------------------------
    ----------------

    (defun C:FA (/ e ee eee la txt pos nb)

    (setq e (nentsel "Select object:"))
    (terpri)

    (if (= (type e) 'LIST)
    (progn
    (if (= (length e) 4)
    ; then it's a nested block object
    (setq nb (print (last e)) ; name list of the nested blocks
    ee (terpri)
    ee (foreach eee nb
    (setq ee (entget eee))
    (princ (field 0 ee))
    (princ "\t : \t")
    (princ (field 2 ee))
    (princ "\t : \t")
    (princ (field 8 ee))
    (princ "\n")
    )
    la (if (= (length nb) 1)
    (progn ; not a nested block, just return the name of the xref the
    selected component is on
    (setq ee (entget (car e)))
    (field 8 ee)
    )
    (progn ; it's a nested block, return the name of the layer of the
    innermost block
    (setq nb (car nb) ; innermost block object
    ee (entget nb)
    ; entity list of the innermost block
    )
    (field 8 ee)
    )
    )
    )
    )
    ; else it's a regular object, so get its layer name
    (setq e (entget (car e)))
    (princ (field 0 ee))
    (princ "\t : \t")
    (princ (field 2 ee))
    (princ "\t : \t")
    (princ (field 8 e))
    (princ "\n")
    )
    )
    (princ)
    )

    ;;--------------------------------------------------------------------------
    ----------------

    (defun FIELD (val ent) (cdr (assoc val ent)))

    ;;--------------------------------------------------------------------------
    ----------------
     
    R. Robert Bell, Aug 6, 2004
    #2
  3. Thanks!
    I do appreciate your help, because I sure couldn't figure out how to get it.

    That works when it's in an XREF, but, alas, the routine seemed to bomb out when the object wasn't an
    XREF.

    So after much trial, I came up with this, FWIW:

    ;;--------------------------------------------------------------------------
    (defun FIELD (val ent) (cdr (assoc val ent)))
    ;;--------------------------------------------------------------------------
    (defun C:TA ()
    (get-nested-layername (nentsel "Select object: "))
    )
    ;;--------------------------------------------------------------------------
    (defun get-nested-layername (sel / e po no la myObj ownerObj)
    ;; get the picked object list data
    (setq po (entget (car sel))
    la (field 8 po)
    )

    (if (and (= (length sel) 4) (= la "0"))
    (progn
    ;; get the first nested object
    (setq no (entget (car (last sel))))
    )
    )

    (if (and (= (field 0 po) "ATTRIB")
    (= (field 0 no) "INSERT")
    (= la "0")
    )
    ;; if it's an ATTRIB on layer "0" and it has a nested object that's an INSERT,
    ;; then get its owner object's layername...
    (progn
    (setq myObj (vlax-EName->vla-Object (car sel))
    ownerObj (vla-ObjectIDToObject
    (vla-Get-Database myObj)
    (vla-Get-OwnerID myObj)
    )
    la (vla-Get-Layer ownerObj)
    )
    )
    ;; else if the picked object is on layer "0" and it has a nested object,
    ;; then get the nested object's layername...
    (progn
    (if (and (= la "0") no)
    (setq la (field 8 no))
    )
    )
    )
    (princ "\nLayer: ")
    la
    )
    ;;--------------------------------------------------------------------------
     
    Allen Johnson, Aug 6, 2004
    #3
  4. I think I understand..... how about this function?

    ; get the insert entity name from the atrrib entity name
    ; [ename] - attrib entity name
    ; return: insert entity name in which [ename] is defined
    ; (attribInsert (car (nentsel "\nselect an attribute: ")))
    (defun attribInsert (ename / data)
    (while
    (and
    (setq ename (entnext ename))
    (setq data (entget ename))
    (/= "SEQEND" (cdr (assoc 0 data)))
    )
    )
    (cdr (assoc -2 data))
    )

    Then just grab the layer name.
     
    Jason Piercey, Aug 6, 2004
    #4
  5. Thanks.
     
    Allen Johnson, Aug 6, 2004
    #5
  6. Then how about this?

    (defun C:Test (/ pickObj myObj ownerObj)
    (vl-load-com)
    (setq pickObj (nentsel))
    (setq myObj (vlax-EName->vla-Object (car pickObj)))
    (setq ownerObj (vla-ObjectIDToObject
    (vla-Get-Database myObj)
    (vla-Get-OwnerID myObj)))
    (vla-Get-Layer
    (cond ((= (vla-Get-ObjectName ownerObj) "AcDbBlockTableRecord") myObj)
    (ownerObj))))


    --
    R. Robert Bell


    Thanks!
    I do appreciate your help, because I sure couldn't figure out how to get it.

    That works when it's in an XREF, but, alas, the routine seemed to bomb out
    when the object wasn't an
    XREF.

    So after much trial, I came up with this, FWIW:

    ;;--------------------------------------------------------------------------
    (defun FIELD (val ent) (cdr (assoc val ent)))
    ;;--------------------------------------------------------------------------
    (defun C:TA ()
    (get-nested-layername (nentsel "Select object: "))
    )
    ;;--------------------------------------------------------------------------
    (defun get-nested-layername (sel / e po no la myObj ownerObj)
    ;; get the picked object list data
    (setq po (entget (car sel))
    la (field 8 po)
    )

    (if (and (= (length sel) 4) (= la "0"))
    (progn
    ;; get the first nested object
    (setq no (entget (car (last sel))))
    )
    )

    (if (and (= (field 0 po) "ATTRIB")
    (= (field 0 no) "INSERT")
    (= la "0")
    )
    ;; if it's an ATTRIB on layer "0" and it has a nested object that's an
    INSERT,
    ;; then get its owner object's layername...
    (progn
    (setq myObj (vlax-EName->vla-Object (car sel))
    ownerObj (vla-ObjectIDToObject
    (vla-Get-Database myObj)
    (vla-Get-OwnerID myObj)
    )
    la (vla-Get-Layer ownerObj)
    )
    )
    ;; else if the picked object is on layer "0" and it has a nested object,
    ;; then get the nested object's layername...
    (progn
    (if (and (= la "0") no)
    (setq la (field 8 no))
    )
    )
    )
    (princ "\nLayer: ")
    la
    )
    ;;--------------------------------------------------------------------------
     
    R. Robert Bell, Aug 6, 2004
    #6
  7. Nope.
    When you select a line within the block object, it returns "0" instead of the block name.
    Of course the line defined within the block IS on layer "0", but I want that if it is on "0", then
    to return the layer that its insert is on. (did I make any sense?)
    The routine I posted (with added revisions to your original code), works.
    But if you want to try to continue along this vein (at least until you strike gold) , feel free.
    Thanks again!
     
    Allen Johnson, Aug 6, 2004
    #7
  8. You're welcome.
     
    Jason Piercey, Aug 6, 2004
    #8
  9. Yeah, it makes sense.

    (defun C:Test (/ pickObj myObj blkObj rootObj ownerObj)
    (vl-load-com)
    (setq pickObj (nentsel))
    (setq myObj (vlax-EName->vla-Object (car pickObj)))
    (if (and (/= (vla-Get-ObjectName myObj) "AcDbAttribute")
    (= (length pickObj) 4))
    (setq blkObj (vlax-EName->vla-Object (car (nth 3 pickObj)))))
    (setq rootObj (if (and blkObj (not (vlax-Property-Available-P blkObj
    'Path)))
    blkObj
    myObj))
    (setq ownerObj (vla-ObjectIDToObject
    (vla-Get-Database rootObj)
    (vla-Get-OwnerID rootObj)))
    (vla-Get-Layer
    (cond ((= (vla-Get-ObjectName ownerObj) "AcDbBlockTableRecord") rootObj)
    (ownerObj))))


    --
    R. Robert Bell


    Nope.
    When you select a line within the block object, it returns "0" instead of
    the block name.
    Of course the line defined within the block IS on layer "0", but I want that
    if it is on "0", then
    to return the layer that its insert is on. (did I make any sense?)
    The routine I posted (with added revisions to your original code), works.
    But if you want to try to continue along this vein (at least until you
    strike gold) , feel free.
    Thanks again!
     
    R. Robert Bell, Aug 9, 2004
    #9
  10. Not to complain about it, but, if the attribute in a block on a XREF is not on layer "0" it returns
    the insert object's layer, not the attribute layer name (TA is my version, TB is your version):


    Command:
    Command: ta
    Select object: "X-FP-001-C|Z-WORK"

    Command:
    Command: tb
    Select object: "X-FP-001-C|A-anno-rnum"


    The ATTRIBUTE is actually on layer Z-WORK in xref X-FP-001-C, however the INSERT is on layer
    A-ANNO-RNUM
     
    Allen Johnson, Aug 9, 2004
    #10
  11. In your initial post that's what you said you wanted... "I'm trying to find
    out what layer the INSERT of a selected ATTRIBUTE is on..." That is also the
    title of your thread.

    --
    R. Robert Bell


    Not to complain about it, but, if the attribute in a block on a XREF is not
    on layer "0" it returns
    the insert object's layer, not the attribute layer name (TA is my version,
    TB is your version):


    Command:
    Command: ta
    Select object: "X-FP-001-C|Z-WORK"

    Command:
    Command: tb
    Select object: "X-FP-001-C|A-anno-rnum"


    The ATTRIBUTE is actually on layer Z-WORK in xref X-FP-001-C, however the
    INSERT is on layer
    A-ANNO-RNUM
     
    R. Robert Bell, Aug 9, 2004
    #11
  12. You're right, my mistake.
     
    Allen Johnson, Aug 9, 2004
    #12
  13. I should have added "if on layer 0"
    Sorry.
     
    Allen Johnson, Aug 9, 2004
    #13
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.