TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: GDF on July 18, 2006, 02:49:06 PM
-
I'm looking for ways to improve the following...
(defun XPL-IT (/ item vo itemname blkname)
(if (and (setq item (car (entsel "\n* Select Block to Lock *")))
(setq vo (vlax-ename->vla-object item))
(null
(vl-catch-all-error-p
(setq itemname (vl-catch-all-apply 'vlax-get-property (list vo 'name))))))
(setq blkname itemname)
(alert "Not a Block"))
(setq blocks (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
(setq blkdef (vla-item blocks blkname))
(vla-put-Explodable blkdef :vlax-false)
(princ))
(defun XPU-IT (/ item vo itemname blkname)
(if (and (setq item (car (entsel "\n* Select Block to Lock *")))
(setq vo (vlax-ename->vla-object item))
(null
(vl-catch-all-error-p
(setq itemname (vl-catch-all-apply 'vlax-get-property (list vo 'name))))))
(setq blkname itemname)
(alert "Not a Block"))
(setq blocks (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
(setq blkdef (vla-item blocks blkname))
(vla-put-Explodable blkdef :vlax-true)
(princ))
;;;
(defun C:XPL (/ tmp)
(initget "L U")
(setq tmp
(getkword
"\n* Select Xplode Type: <L>ock <U>nlock *"
)
)
(initget 7) ;;disallow null,zero & negative
(cond
((= tmp "L")(XPL-IT))
((= tmp "U")(XPU-IT))
)
(princ)
)
Gary
-
Combind the two codes to lock and unlock, with asking for an argument.
(defun XpProp (PropSet / item vo itemname blkname)
(if (and (setq item (car (entsel "\n* Select Block *")))
(setq vo (vlax-ename->vla-object item))
(null
(vl-catch-all-error-p
(setq itemname (vl-catch-all-apply 'vlax-get-property (list vo 'name))))))
(setq blkname itemname)
(alert "Not a Block"))
(setq blocks (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
(setq blkdef (vla-item blocks blkname))
(vla-put-Explodable blkdef PropSet)
(princ))
Then call it like
(defun C:XPL (/ tmp)
(initget "Lock Unlock")
(if (/= (getkword "\n* Select Xplode Type: <L>ock Unlock * " ) "Unlock")
(XpProp :vlax-false)
(XpProp :vlax-true)
)
(princ)
)
-
Tim
Thanks
Gary
-
You're welcome. I would put it into one function, no need to have have two, IMO. If you wanted to, you could even have a prompt telling the user they are selecting a block to lock or unlock (I took that out).
-
Do you guys do not like the use of "[" .... "]" (context menu) for the getword function ?
(getkword "\nSelect Xplode Type [Lock/Unlock]: " )
-
Do you guys do not like the use of "[" .... "]" (context menu) for the getword function ?
(getkword "\nSelect Xplode Type [Lock/Unlock]: " )
Luis
Your right, I keep forgetting that. Bad doggy...
Tim
You're welcome. I would put it into one function, no need to have have two, IMO. If you wanted to, you could even have a prompt telling the user they are selecting a block to lock or unlock (I took that out).
Tim
Thanks again.
I replaced the error alert with:
(ARCH:MsgBox " Xplode Property Lock" 48 "This not a Block\nPlease try again.")
beginning message:
(ARCH:MsgBox " Xplode Property Lock" 64 "Please select a Block\to Lock the Xplode Property.")
or something similar.
Gary
-
Do you guys do not like the use of "[" .... "]" (context menu) for the getword function ?
(getkword "\nSelect Xplode Type [Lock/Unlock]: " )
I do. It was just a quick fix for what Gary wanted.
-
Another idea, untested.
(defun xpprop (propset / item vo itemname blkname typ)
(setq typ (if (eq propset :vlax-false) "Lock" "Unlock"))
(if (and (setq item (car (entsel "\n* Select Block to " typ " *")))
(setq vo (vlax-ename->vla-object item))
(null
(vl-catch-all-error-p
(setq itemname (vl-catch-all-apply 'vlax-get-property (list vo 'name)))
)
)
)
(progn
(setq blkname itemname)
(setq blocks (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
(setq blkdef (vla-item blocks blkname))
(vla-put-explodable blkdef propset)
)
(alert "Not a Block")
)
(princ)
)
(defun c:xpl () (xpprop :vlax-false) (princ))
(defun c:xpul () (xpprop :vlax-true) (princ))
-
Alan
Thanks
Gary