Author Topic: Entity Name of Block  (Read 2431 times)

0 Members and 1 Guest are viewing this topic.

gregb

  • Guest
Entity Name of Block
« 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

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Entity Name of Block
« Reply #1 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))
  )
)

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Entity Name of Block
« Reply #2 on: June 24, 2011, 10:27:37 AM »
Wait a second.... ANOTHER "GREG B"??!?
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

trogg

  • Bull Frog
  • Posts: 255
Re: Entity Name of Block
« Reply #3 on: June 24, 2011, 10:35:16 AM »
Greg Bs are sprouting up everywhere!!!!
HAHA

~Greg Battin

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Entity Name of Block
« Reply #4 on: June 24, 2011, 10:43:57 AM »
Greg Bs are sprouting up everywhere!!!!
That's what she said.
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

mjfarrell

  • Seagull
  • Posts: 14444
  • Every Student their own Lesson
Re: Entity Name of Block
« Reply #5 on: June 24, 2011, 10:50:28 AM »
Three, I say, THREE Greg Bs!!!
Be your Best


Michael Farrell
http://primeservicesglobal.com/

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Entity Name of Block
« Reply #6 on: June 24, 2011, 10:54:46 AM »
Three, I say, THREE Greg Bs!!!
Greg Bs on knees...
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

gregb

  • Guest
Re: Entity Name of Block
« Reply #7 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))
  )
)

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Entity Name of Block
« Reply #8 on: June 25, 2011, 10:43:22 AM »
You're welcome Greg  :-)

gregb

  • Guest
Re: Entity Name of Block
« Reply #9 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 :)

trogg

  • Bull Frog
  • Posts: 255
Re: Entity Name of Block
« Reply #10 on: June 25, 2011, 11:49:14 AM »
Yup! Nothin' special

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Entity Name of Block
« Reply #11 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.
Speaking English as a French Frog

Greg B

  • Seagull
  • Posts: 12417
  • Tell me a Joke!
Re: Entity Name of Block
« Reply #12 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?