TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: gregb on June 24, 2011, 09:16:29 AM

Title: Entity Name of Block
Post by: gregb on June 24, 2011, 09:16:29 AM
I have a dynamic block that is a circle with an attribute, if i select the circle i can get the entity name of the block, how do i get the block entity name if i select the attribute?

if i select the attribute i just get the pick point and the attributes entity name

Thanks for your help.

Code: [Select]
(defun c:foo (/ CODE DTA ED INP KEY)
  (setq  inp   (grread)
        code (car inp)
        dta   (cadr inp)
  )                                      ; grread => (2 ord of key pressed) OR (3, (pick point))
  (cond
    ((= 2 code)                          ; character typed => S = 83, s = 115 X = 88, x = 120
     (setq key (strcase (chr dta)))
    )

    ((= 3 code)                          ; picked a point
     (setq ed (nentselp dta))            ; so get entity at picked point


     (cond ((= 0 (length ed)) (setq key NIL)) ; nothing selected)

                                        ; simple entity selected line, arc text, polyline => (entity pick_point)
           ((= 2 (length ed))
            (setq key (cdr (assoc 0 (entget (car ed)))))
           )

                                        ; block selected 0 = entity handle of selected subentity, 1 = pick point,  3 = ?????, 4 = entity handle of block
           ((= 4 (length ed))
            (setq  ed   (list (car (nth 3 ed)) (nth 1 ed))
                  key  (cdr (assoc 0 (entget (car ed))))
                  key  (vla-get-effectivename
                        (vlax-ename->vla-object (car ed))
                      )
            )
           )

     ) ;_cond
    ) ;_ (= 3 code)
  ) ;_ cond
  (if  (= key NIL)
    (setq inp (list "Nothing" NIL NIL))
    (setq inp (list key (car ed) (cadr ed))) ; entity type, entity name, pick point
  )
  ;; return values
) ;_ defun
Title: Re: Entity Name of Block
Post by: Lee Mac on June 24, 2011, 09:34:25 AM
A quick modification to your code:

Code: [Select]
(defun c:foo ( / code dta ed inp key )
  (setq
    inp  (grread)
    code (car  inp)
    dta  (cadr inp)
  )
  (cond
    ( (= 2 code)
      (setq key (strcase (chr dta)))
    )
    ( (= 3 code)
      (setq ed (nentselp dta))
      (cond
        ( (= 0 (length ed))
          (setq key NIL)
        )
        ( (= 2 (length ed))
          (setq key (cdr (assoc 0 (entget (car ed)))))
          (if (eq "ATTRIB" key)
            (setq
              ed  (list (cdr (assoc 330 (entget (car ed)))) (cadr ed))
              key (vla-get-effectivename (vlax-ename->vla-object (car ed)))
            )
          )
        )
        ( (= 4 (length ed))
          (setq
            ed  (list (car (nth 3 ed)) (nth 1 ed))
            key (vla-get-effectivename (vlax-ename->vla-object (car ed)))
          )
        )
      )
    )
  )
  (if key
    (setq inp (list key (car ed) (cadr ed)))
    (setq inp (list "Nothing" NIL NIL))
  )
)
Title: Re: Entity Name of Block
Post by: Matt__W on June 24, 2011, 10:27:37 AM
Wait a second.... ANOTHER "GREG B"??!?
Title: Re: Entity Name of Block
Post by: trogg on June 24, 2011, 10:35:16 AM
Greg Bs are sprouting up everywhere!!!!
HAHA

~Greg Battin
Title: Re: Entity Name of Block
Post by: Matt__W on June 24, 2011, 10:43:57 AM
Greg Bs are sprouting up everywhere!!!!
That's what she said.
Title: Re: Entity Name of Block
Post by: mjfarrell on June 24, 2011, 10:50:28 AM
Three, I say, THREE Greg Bs!!!
Title: Re: Entity Name of Block
Post by: Matt__W on June 24, 2011, 10:54:46 AM
Three, I say, THREE Greg Bs!!!
Greg Bs on knees...
Title: Re: Entity Name of Block
Post by: gregb on June 25, 2011, 10:41:26 AM
Thank you very much :) ... looks like i also need to study code formatting, yours is MUCH easier to read, thanks again.

A quick modification to your code:

Code: [Select]
(defun c:foo ( / code dta ed inp key )
  (setq
    inp  (grread)
    code (car  inp)
    dta  (cadr inp)
  )
  (cond
    ( (= 2 code)
      (setq key (strcase (chr dta)))
    )
    ( (= 3 code)
      (setq ed (nentselp dta))
      (cond
        ( (= 0 (length ed))
          (setq key NIL)
        )
        ( (= 2 (length ed))
          (setq key (cdr (assoc 0 (entget (car ed)))))
          (if (eq "ATTRIB" key)
            (setq
              ed  (list (cdr (assoc 330 (entget (car ed)))) (cadr ed))
              key (vla-get-effectivename (vlax-ename->vla-object (car ed)))
            )
          )
        )
        ( (= 4 (length ed))
          (setq
            ed  (list (car (nth 3 ed)) (nth 1 ed))
            key (vla-get-effectivename (vlax-ename->vla-object (car ed)))
          )
        )
      )
    )
  )
  (if key
    (setq inp (list key (car ed) (cadr ed)))
    (setq inp (list "Nothing" NIL NIL))
  )
)
Title: Re: Entity Name of Block
Post by: Lee Mac on June 25, 2011, 10:43:22 AM
You're welcome Greg  :-)
Title: Re: Entity Name of Block
Post by: gregb on June 25, 2011, 10:44:28 AM
Three, I say, THREE Greg Bs!!!

What can i say ... we must be either very popular or just common :)
Title: Re: Entity Name of Block
Post by: trogg on June 25, 2011, 11:49:14 AM
Yup! Nothin' special
Title: Re: Entity Name of Block
Post by: gile on June 25, 2011, 01:13:22 PM
Quote
i also need to study code formatting

Just use: Ctrl+Alt+F (or Ctrl+Shift+F for a selection) in the VLIDE.
Title: Re: Entity Name of Block
Post by: Greg B on June 25, 2011, 02:27:01 PM
Huh...I thought it was a mix-up with the new forum version.

heh..

Welcome brother greg b's!

Should I head back to my old old old nickname from the CADVault days?