TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: GDF on July 18, 2006, 02:49:06 PM

Title: Xplode Control
Post by: GDF on July 18, 2006, 02:49:06 PM
I'm looking for ways to improve the following...

Code: [Select]
(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
Title: Re: Xplode Control
Post by: T.Willey on July 18, 2006, 02:59:34 PM
Combind the two codes to lock and unlock, with asking for an argument.
Code: [Select]
(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
Code: [Select]
(defun C:XPL (/ tmp)
  (initget "Lock Unlock") 
  (if (/= (getkword "\n* Select Xplode Type:  <L>ock   Unlock * " ) "Unlock")
   (XpProp :vlax-false)
   (XpProp :vlax-true)
  )
  (princ)
)
Title: Re: Xplode Control
Post by: GDF on July 18, 2006, 03:01:02 PM
Tim

Thanks

Gary
Title: Re: Xplode Control
Post by: T.Willey on July 18, 2006, 03:04:14 PM
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).
Title: Re: Xplode Control
Post by: LE on July 18, 2006, 03:05:44 PM
Do you guys do not like the use of "[" .... "]" (context menu) for the getword function ?

Code: [Select]
(getkword "\nSelect Xplode Type [Lock/Unlock]:  " )
Title: Re: Xplode Control
Post by: GDF on July 18, 2006, 03:12:57 PM
Do you guys do not like the use of "[" .... "]" (context menu) for the getword function ?

Code: [Select]
(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
Title: Re: Xplode Control
Post by: T.Willey on July 18, 2006, 03:25:23 PM
Do you guys do not like the use of "[" .... "]" (context menu) for the getword function ?

Code: [Select]
(getkword "\nSelect Xplode Type [Lock/Unlock]:  " )
I do.  It was just a quick fix for what Gary wanted.
Title: Re: Xplode Control
Post by: CAB on July 18, 2006, 05:45:53 PM
Another idea, untested.
Code: [Select]
(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))
Title: Re: Xplode Control
Post by: GDF on July 19, 2006, 11:31:50 AM
Alan

Thanks

Gary