Find attribute's block owner....

Discussion in 'AutoCAD' started by James Maeding, Feb 9, 2005.

  1. ok, that works for attributes, which is the gap I need covered.
    It would sure be nice if it worked for lines/arcs though.
    It glitched when I picked the circle.

    It is stumbling on the (entget Ent) after the first loop in the While statement.
    Its like you cannot get the entity list of the block record when the block is from an xref.

    I think you were trying to do what I did where you use the nentsel info to cover that but missed something.
    I need to look closer to refine your code.

    Either way, we still end up relying on the nentsel tree info for non-attributes.
    I'd like to figure a function to find the tree for any ename with just ename supplied.

    Looks like I am pst the hump for now though, thanks for posting your code.

    "T.Willey" <>
    |>Do you want something like this?
    |>
    |>Tim
    |>
    |>(defun c:GetTrail (/ Ent EntData EntType LastEnt LastEntData LastEntType LastEntPath EndList)
    |>
    |>(if (setq Ent (nentsel))
    |> (progn
    |> (setq LastEnt (car (last Ent)))
    |> (setq Ent (car Ent))
    |> (setq EntData (entget Ent))
    |> (setq EntType (cdr (assoc 0 EntData)))
    |> (while (/= EntType "BLOCK_RECORD")
    |> (setq EndList (cons (list Ent EntType) EndList))
    |> (setq Ent (cdr (assoc 330 EntData)))
    |> (setq EntData (entget Ent))
    |> (setq EntType (cdr (assoc 0 EntData)))
    |> )
    |> (if (= (type LastEnt) 'ENAME)
    |> (progn
    |> (setq LastEntData (entget LastEnt))
    |> (setq LastEntType (cdr (assoc 0 LastEntData)))
    |> (if (setq LastEntPath (cdr (assoc 1 (tblsearch "block" (cdr (assoc 2 LastEntData))))))
    |> (setq EndList (cons (list LastEnt LastEntType (strcat "XrPath - " LastEntPath)) EndList))
    |> (setq EndList (cons (list LastEnt LastEntType) EndList))
    |> )
    |> )
    |> )
    |> )
    |>)
    |>EndList
    |>)

    James Maeding
    jmaeding at hunsaker dot com
    Civil Engineer/Programmer
     
    James Maeding, Feb 10, 2005
    #21
  2. James Maeding

    T.Willey Guest

    Ok, here is a revised version based on what you said didn't work. This one word here.

    Tim

    (defun c:GetTrail (/ Ent EntData EntType LastEnt LastEntData LastEntType LastEntPath EndList TestList
    tmpTest tmpEnt cnt1)

    (if (setq Ent (nentsel))
    (progn
    (setq LastEnt (last Ent))
    (setq Ent (car Ent))
    (setq EntData (entget Ent))
    (setq EntType (cdr (assoc 0 EntData)))
    (while (and EntData (/= EntType "BLOCK_RECORD"))
    (setq EndList (cons (list Ent EntType) EndList))
    (setq Ent (cdr (assoc 330 EntData)))
    (setq EntData (entget Ent))
    (setq EntType (cdr (assoc 0 EntData)))
    )
    (setq TestList (mapcar '(lambda (x) (= (type x) 'ENAME)) LastEnt))
    (setq cnt1 0)
    (foreach tmpTest TestList
    (if (= tmpTest T)
    (progn
    (setq tmpEnt (nth cnt1 LastEnt))
    (setq LastEntData (entget tmpEnt))
    (setq LastEntType (cdr (assoc 0 LastEntData)))
    (if (setq LastEntPath (cdr (assoc 1 (tblsearch "block" (cdr (assoc 2 LastEntData))))))
    (setq EndList (cons (list tmpEnt LastEntType (strcat "XrPath - " LastEntPath)) EndList))
    (setq EndList (cons (list tmpEnt LastEntType) EndList))
    )
    )
    )
    (setq cnt1 (1+ cnt1))
    )
    )
    )
    EndList
    )
     
    T.Willey, Feb 10, 2005
    #22
  3. ok, one last tweak for future readers:
    You do have to deal with the 330 groups as they steer you off the wrong direction when groups are encountered.
    I made the prog reverse the entity list before grabbing the 330 group. It has worked so far so I think the last 330
    group is the parent entity...

    ;ENTITY TRAIL
    ;SPECIAL THANKS TO MICHAEL PUCKETT AND T. WILEY!
    ;RETURNS LIST OF ENAMES FROM NENTSEL ON UP TO BLOCKS CONTAINING IT
    ;(ENTITY-TRAIL (NENTSEL))

    (DEFUN ENTITY-TRAIL (NENTSEL-IN / CNT1 ENDLIST ENT ENTDATA ENTTYPE LASTENT TESTLIST TMPTEST X)
    (IF NENTSEL-IN
    (PROGN
    (SETQ LASTENT (LAST NENTSEL-IN))
    (SETQ ENT (CAR NENTSEL-IN))
    (SETQ ENTDATA (REVERSE (ENTGET ENT))) ;REVERSE TO GET LAST 330 GROUP!
    (SETQ ENTTYPE (CDR (ASSOC 0 ENTDATA)))
    (WHILE (AND ENTDATA
    (/= ENTTYPE "BLOCK_RECORD")
    )
    (SETQ ENDLIST (CONS ENT ENDLIST))
    (SETQ ENT (CDR (ASSOC 330 ENTDATA)))
    (SETQ ENTDATA (REVERSE (ENTGET ENT))) ;REVERSE TO GET LAST 330 GROUP!
    (SETQ ENTTYPE (CDR (ASSOC 0 ENTDATA)))
    )
    (SETQ TESTLIST (MAPCAR '(LAMBDA (X) (= (TYPE X) 'ENAME)) LASTENT))
    (SETQ CNT1 0)
    (FOREACH TMPTEST TESTLIST
    (IF (= TMPTEST T)
    (SETQ ENDLIST (CONS (NTH CNT1 LASTENT) ENDLIST))
    )
    (SETQ CNT1 (1+ CNT1))
    )
    )
    )
    (REVERSE ENDLIST)
    )


    James Maeding <jmaeding at hunsaker dot com>
    |>I have a prog that uses nentsel to grab things and list the properties.
    |>For eerything but attributes, nentsel gives a trail of info on nested items.
    |>
    |>I need to construct that trail for attributes.
    |>
    |>I thought about reissuing the entsel for the same point picked as the nentsel command to get the block name, but you
    |>cannot feed entsel a point to my knowlege. On top of that, it would not give a decent trail for items nested several
    |>times..
    |>
    |>I think the way to do this is to make a vla object from the attribute ename, then use the Object ID property to step
    |>back through to the top.
    |>
    |>Anyone done this before in lisp? (that cares to share :)
    |>thanks
    |>James Maeding
    |>jmaeding at hunsaker dot com
    |>Civil Engineer/Programmer

    James Maeding
    jmaeding at hunsaker dot com
    Civil Engineer/Programmer
     
    James Maeding, Feb 14, 2005
    #23
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.