PDA

View Full Version : Using LISP to insert a Dynamic block



Ferroequine
2005-12-19, 04:23 PM
Has anyone found a way to have LISP insert a Dynamic Block, and then modify that block to show a certain visibility state? The only references I have seen so far only check the effectiveName property after the fact...

barry.40197
2005-12-19, 05:13 PM
Original code by: Mark Douglas

Example 1:
(command ".insert" "DynNail" PtStr 1 1 Rang)
(myModifyBk (entlast) (list "Visibility" "Vis1"))

Example 2:
(command ".insert" "DynBolt" PtStr 1 (rtd Rang))
(myModifyBk (entlast) (list "Bolt Length" (distance PtStr PtEnd) "Bolt Size" "8"))

jwf
2006-01-05, 01:05 AM
i have a similiar problem with wanting to insert a D-Block prompting me to set my parameters. any idea if this is possible. i know just enough lisp to get by, so be gentle.

Chris.N
2006-01-05, 02:24 PM
Has anyone found a way to have LISP insert a Dynamic Block, and then modify that block to show a certain visibility state? The only references I have seen so far only check the effectiveName property after the fact... if you use toolpalettes, you can have multiple buttons of same block, but with different 'presets' in properties for that icon.

jwf
2006-01-05, 02:55 PM
We are trying to insert Duct Risers or drops, and those can be any two dimensions(I.E.=20x24). We are using Tool Palettes for the Default Visibilities.

Chris.N
2006-01-05, 04:03 PM
We are trying to insert Duct Risers or drops, and those can be any two dimensions(I.E.=20x24). We are using Tool Palettes for the Default Visibilities. dont' know if this would help, but did you know you can globally change pre-selected DB's (of same) and change parameters/visibility in the 'properties' dialog?

jwf
2006-01-05, 05:28 PM
It would be nice if the D-block would prompt you to change certain parameters when you insert them, like attributes do.

mark.62793
2006-01-08, 03:00 AM
It would be nice if the D-block would prompt you to change certain parameters when you insert them, like attributes do.

I completely agree that would be great if you could modify them at insertion.

INTRESTEIN
2009-06-11, 10:38 PM
I know this is a few years later on this topic.. but i know this is now possible with this routine...

InsertPrompt.lsp

(vl-load-com)
(vl-load-reactors)
(defun ss->objlist (ss / cnt objlist)
(setq cnt (sslength ss))
(repeat cnt (setq objlist (append objlist (list (vlax-ename->vla-object (ssname ss (- cnt 1))))))
(setq cnt (- cnt 1))) )
(setq ss nil)
Objlist)
(defun gp:binsertatts (a b / ss obj objattr nwstr)
(if (or (eq (car b) "EXECUTETOOL") (eq (car b) "INSERT"))
(setvar "attreq" 0)))
(defun gp:binsertatte (a b / ss obj objattr nwstr objdyn newvalue prmpts cnt dyn dynp)
(if (or (eq (car b) "EXECUTETOOL") (eq (car b) "INSERT"))
(progn
(setq dyn (getvar "dynmode"))
(setq dynp (getvar "dynprompt"))
(setvar "dynprompt" 1)
(setvar "dynmode" 1)
(setq ss (ssget "L"))
(setq obj (ss->objlist ss))
(foreach o obj
(if (= (cdr (assoc 0 (entget (vlax-vla-object->ename o)))) "INSERT")
(progn
(if (= (vla-get-HasAttributes o) :vlax-true)
(progn
(setq objattr (vlax-safearray->list (vlax-variant-value (vla-GetAttributes o))))
(foreach oa objattr
(setq oatr oa)
(if (= (vla-get-Constant oa) :vlax-false)
(progn
(setq nwstr (getstring (strcat "\nSpecify " (vla-get-TagString oa) ": <" (vla-get-TextString oa) ">: ")))
(if (/= nwstr "") (vla-put-TextString oa nwstr))
(setq nwstr nil))))))
(if (= (vla-get-IsDynamicBlock o) :vlax-true)
(progn
(setq objdyn (vlax-safearray->list (vlax-variant-value (vla-GetDynamicBlockProperties o))))
(foreach od objdyn
(if (and (= (vla-get-Show od) :vlax-true) (= (vla-get-ReadOnly od) :vlax-false)
(/= (vla-get-PropertyName od) "Origin"))
(progn
(if (= (vlax-safearray-get-u-bound (vlax-variant-value (vla-get-AllowedValues od)) 1) -1)
(progn
(if (= (vla-get-Description od) "")
(setq prmpts (strcat "\nEnter value for " (vla-get-PropertyName od) ":"))
(setq prmpts (strcat "\nEnter value for " (vla-get-Description od) ":")))
(cond
((= (vla-get-UnitsType od) acAngular) (setq newvalue (getorient prmpts)))
((= (vla-get-UnitsType od) acDistance) (setq newvalue (getdist prmpts)))
((= (vla-get-UnitsType od) acArea) (setq newvalue (getreal prmpts))))
(if (/= newvalue nil) (vla-put-Value od (vlax-make-variant newvalue))))
(progn
(setq prmpts "[")
(setq cnt 1)
(foreach pt (vlax-safearray->list (vlax-variant-value (vla-get-AllowedValues od)))
(if (= (vla-get-UnitsType od) 0)
(setq prmpts (strcat prmpts (itoa cnt) ")." (vl-string-translate "/" "|" (vl-string-translate " " "-" (vlax-variant-value pt))) " "))
(setq prmpts (strcat prmpts (itoa cnt) ")." (vl-string-translate "/" "|" (vl-string-translate " " "-" (rtos (vlax-variant-value pt) 2))) " ")))
(setq cnt (+ cnt 1)))
(setq prmpts (strcat (vl-string-right-trim " " prmpts) "]"))
(initget 0 (vl-string-trim "[]" prmpts))
(if (= (vla-get-Description od) "")
(setq newvalue (getkword (strcat "\nEnter value for " (vla-get-PropertyName od) ":" (vl-string-translate " " "/" prmpts))))
(setq newvalue (getkword (strcat "\nEnter value for " (vla-get-Description od) ":" (vl-string-translate " " "/" prmpts)))))
(if (/= newvalue nil)
(progn
(setq newvalue (nth (- (atoi (substr newvalue 1 (vl-string-position 41 newvalue))) 1) (vlax-safearray->list (vlax-variant-value (vla-get-AllowedValues od)))))
(vla-put-Value od newvalue)
))))))))))))))
(setvar "attreq" 1)
(setvar "dynmode" dyn)
(setvar "dynprompt" dynp)
(princ))
(setq rinsrte (vlr-command-reactor nil '((:vlr-commandEnded . gp:binsertatte))))
(setq rinsrts (vlr-command-reactor nil '((:vlr-commandWillStart . gp:binsertatts))))



What im not sure about is how to embed this into a button to put it on the right layer,color,linetype (aka list: (list "E-POWR-N" 4 "Continuous") )

feargt
2010-03-24, 08:56 AM
I know this is a few years later on this topic.. but i know this is now possible with this routine...

InsertPrompt.lsp

(vl-load-com)
(vl-load-reactors)
(defun ss->objlist (ss / cnt objlist)
(setq cnt (sslength ss))
(repeat cnt (setq objlist (append objlist (list (vlax-ename->vla-object (ssname ss (- cnt 1))))))
(setq cnt (- cnt 1))) )
(setq ss nil)
Objlist)
(defun gp:binsertatts (a b / ss obj objattr nwstr)
(if (or (eq (car b) "EXECUTETOOL") (eq (car b) "INSERT"))
(setvar "attreq" 0)))
(defun gp:binsertatte (a b / ss obj objattr nwstr objdyn newvalue prmpts cnt dyn dynp)
(if (or (eq (car b) "EXECUTETOOL") (eq (car b) "INSERT"))
(progn
(setq dyn (getvar "dynmode"))
(setq dynp (getvar "dynprompt"))
(setvar "dynprompt" 1)
(setvar "dynmode" 1)
(setq ss (ssget "L"))
(setq obj (ss->objlist ss))
(foreach o obj
(if (= (cdr (assoc 0 (entget (vlax-vla-object->ename o)))) "INSERT")
(progn
(if (= (vla-get-HasAttributes o) :vlax-true)
(progn
(setq objattr (vlax-safearray->list (vlax-variant-value (vla-GetAttributes o))))
(foreach oa objattr
(setq oatr oa)
(if (= (vla-get-Constant oa) :vlax-false)
(progn
(setq nwstr (getstring (strcat "\nSpecify " (vla-get-TagString oa) ": <" (vla-get-TextString oa) ">: ")))
(if (/= nwstr "") (vla-put-TextString oa nwstr))
(setq nwstr nil))))))
(if (= (vla-get-IsDynamicBlock o) :vlax-true)
(progn
(setq objdyn (vlax-safearray->list (vlax-variant-value (vla-GetDynamicBlockProperties o))))
(foreach od objdyn
(if (and (= (vla-get-Show od) :vlax-true) (= (vla-get-ReadOnly od) :vlax-false)
(/= (vla-get-PropertyName od) "Origin"))
(progn
(if (= (vlax-safearray-get-u-bound (vlax-variant-value (vla-get-AllowedValues od)) 1) -1)
(progn
(if (= (vla-get-Description od) "")
(setq prmpts (strcat "\nEnter value for " (vla-get-PropertyName od) ":"))
(setq prmpts (strcat "\nEnter value for " (vla-get-Description od) ":")))
(cond
((= (vla-get-UnitsType od) acAngular) (setq newvalue (getorient prmpts)))
((= (vla-get-UnitsType od) acDistance) (setq newvalue (getdist prmpts)))
((= (vla-get-UnitsType od) acArea) (setq newvalue (getreal prmpts))))
(if (/= newvalue nil) (vla-put-Value od (vlax-make-variant newvalue))))
(progn
(setq prmpts "[")
(setq cnt 1)
(foreach pt (vlax-safearray->list (vlax-variant-value (vla-get-AllowedValues od)))
(if (= (vla-get-UnitsType od) 0)
(setq prmpts (strcat prmpts (itoa cnt) ")." (vl-string-translate "/" "|" (vl-string-translate " " "-" (vlax-variant-value pt))) " "))
(setq prmpts (strcat prmpts (itoa cnt) ")." (vl-string-translate "/" "|" (vl-string-translate " " "-" (rtos (vlax-variant-value pt) 2))) " ")))
(setq cnt (+ cnt 1)))
(setq prmpts (strcat (vl-string-right-trim " " prmpts) "]"))
(initget 0 (vl-string-trim "[]" prmpts))
(if (= (vla-get-Description od) "")
(setq newvalue (getkword (strcat "\nEnter value for " (vla-get-PropertyName od) ":" (vl-string-translate " " "/" prmpts))))
(setq newvalue (getkword (strcat "\nEnter value for " (vla-get-Description od) ":" (vl-string-translate " " "/" prmpts)))))
(if (/= newvalue nil)
(progn
(setq newvalue (nth (- (atoi (substr newvalue 1 (vl-string-position 41 newvalue))) 1) (vlax-safearray->list (vlax-variant-value (vla-get-AllowedValues od)))))
(vla-put-Value od newvalue)
))))))))))))))
(setvar "attreq" 1)
(setvar "dynmode" dyn)
(setvar "dynprompt" dynp)
(princ))
(setq rinsrte (vlr-command-reactor nil '((:vlr-commandEnded . gp:binsertatte))))
(setq rinsrts (vlr-command-reactor nil '((:vlr-commandWillStart . gp:binsertatts))))



What im not sure about is how to embed this into a button to put it on the right layer,color,linetype (aka list: (list "E-POWR-N" 4 "Continuous") )

Hi Mikesidea,

Thanks for posting the code. I had tried unsuccessfully to locate elsewhere.
When I copy this code into the Vlisp app and try to load it, I get the message that there are too many right parenthesis. Could you please post a working copy of the code again? Would be very much appreciated.

thanks

Opie
2010-03-25, 02:23 PM
Hi Mikesidea,

Thanks for posting the code. I had tried unsuccessfully to locate elsewhere.
When I copy this code into the Vlisp app and try to load it, I get the message that there are too many right parenthesis. Could you please post a working copy of the code again? Would be very much appreciated.

thanks
On line 6 in mikesidea's code above remove the last parenthesis.

(setq cnt (- cnt 1))) )
It should work then.