TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started 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.
(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
-
A quick modification to your code:
(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))
)
)
-
Wait a second.... ANOTHER "GREG B"??!?
-
Greg Bs are sprouting up everywhere!!!!
HAHA
~Greg Battin
-
Greg Bs are sprouting up everywhere!!!!
That's what she said.
-
Three, I say, THREE Greg Bs!!!
-
Three, I say, THREE Greg Bs!!!
Greg Bs on knees...
-
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:
(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))
)
)
-
You're welcome Greg :-)
-
Three, I say, THREE Greg Bs!!!
What can i say ... we must be either very popular or just common :)
-
Yup! Nothin' special
-
i also need to study code formatting
Just use: Ctrl+Alt+F (or Ctrl+Shift+F for a selection) in the VLIDE.
-
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?