PDA

View Full Version : Parameter block a lisp.



luislhss
2013-06-03, 08:11 PM
What code should I use a lisp to insert a dynamic block indentiifcndo the parrâmetro which should be visible in the inserted block?


I appreciate the information!

fixo
2013-06-04, 09:56 PM
try this code right after insert a dynamic block as a start point,
this lisp was written in a hurry, so change to your needs


(defun c:cd (/
*error*
make-dynprop-dial
run-dynprop-dial
changedynblockprop
set_list
set_val
blk
dcl_ex
en
fn
fname
knock
lstpair
prop_lst
prop_name
val
val_lst
)
(vl-load-com)
(defun *error* (msg)
(if
(not
(member
msg
'("console break"
"Function cancelled"
"quit / exit abort"
""
)
) ;_ end of member
) ;_ end of not
(princ (strcat "\nError: " msg))
) ;_ end of if
(vla-endundomark adoc)
(princ)
) ;_ end of defun


(setq adoc (vla-get-activedocument
(vlax-get-acad-object)
) ;_ end of vla-get-activedocument
) ;_ end of setq




(vla-startundomark adoc)

(defun make-dynprop-dial ()
(setq fname (strcat (getvar "dwgprefix") "dynprop.dcl"))
;;;(setq fname (vl-filename-mktemp "dynprop.dcl"))
(setq fn (open fname "w"))
; ;
(mapcar (function (lambda (x) (write-line x fn)))
(list
"dynprop : dialog {label = \"Change dynamic property\";"
": boxed_column {label = \"Select Parameter:\";"
"spacer;"
": popup_list"
"{label = \"Property name: \";"
"key = \"props\";"
"alignment = right;"
"value = \"0\";"
"multiple_select = false;"
"allow_accept = true;"
"edit_width = 24;"
"}"
"spacer;"
": popup_list"

"{label = \"Property value:\";"
"key = \"vals\";"
"alignment = right;"
"value = \"0\";"
"multiple_select = false;"
"allow_accept = true;"
"edit_width = 24;"
"}"
"spacer;"
"}"
"spacer;"
"ok_cancel;"

"}"
) ;_ end of list
) ;_ end of mapcar
(close fn)
) ;_ end of defun
; ;
(defun run-dynprop-dial (blk / prop_name val)
(setq prop_lst nil)
(setq prop_lst (getproperties blk))
(setq dcl_ex (load_dialog fname))

(if (null (new_dialog "dynprop" dcl_ex))
(exit)
) ;_ end of if

(set_list "props" prop_lst)

(action_tile
"props"
(strcat
"(progn "
"(setq prop_name (nth (atoi $value) prop_lst))"
"(set_list \"vals\" (setq val_lst (getvalues blk prop_name))))"
) ;_ end of strcat
) ;_ end of action_tile
(action_tile
"vals"
"(setq val (nth (atoi $value) val_lst))"
) ;_ end of action_tile
(action_tile "accept" "(done_dialog 1)")
(action_tile "cancel" "(done_dialog 0)")

(setq knock (start_dialog))

(unload_dialog dcl_ex)
(vl-file-delete fname)
(list prop_name val)
) ;_ end of defun
; ;
(defun getproperties (blk / props)
(setq props (vlax-safearray->list
(variant-value
(vla-getdynamicblockproperties blk)
) ;_ end of variant-value
) ;_ end of vlax-safearray->list
) ;_ end of setq
(mapcar (function (lambda (x)
(vla-get-propertyname x)
) ;_ end of lambda
) ;_ end of function
props
) ;_ end of mapcar
) ;_ end of defun
; ;
(defun getvalues (blk prop_name)

(mapcar 'vlax-variant-value
(vlax-safearray->list
(variant-value
(vla-get-allowedvalues
(car
(vl-remove-if-not
(function (lambda (x)
(eq prop_name (vla-get-propertyname x))
) ;_ end of lambda
) ;_ end of function
(vlax-safearray->list
(variant-value
(vla-getdynamicblockproperties blk)
) ;_ end of variant-value
) ;_ end of vlax-safearray->list
) ;_ end of vl-remove-if-not
) ;_ end of car
) ;_ end of vla-get-allowedvalues
) ;_ end of variant-value
) ;_ end of vlax-safearray->list
) ;_ end of mapcar
) ;_ end of defun
; ;
(defun changedynblockprop (blk propname value)
(if (= (type blk) 'ename)
(setq blk (vlax-ename->vla-object blk))
) ;_ end of if

(setq dynobj_list
(vlax-safearray->list
(variant-value
(vla-getdynamicblockproperties blk)
) ;_ end of variant-value
) ;_ end of vlax-safearray->list
) ;_ end of setq

(foreach obj dynobj_list
(if (eq propname (vla-get-propertyname obj))
(vla-put-value obj value)
) ;_ end of if
) ;_ end of foreach
) ;_ end of defun
; ;

(defun set_list (name lst)
(start_list name)
(mapcar 'add_list lst)
(end_list)
) ;_ end of defun
; ;

(defun set_val (name val)
(set_tile name val)
) ;_ end of defun

; ;

;;(command "_-insert" "sw48")(while (= 1 (logand 1(getvar "cmdactive")))(command pause))
(setq en (entlast))
(setq blk (vlax-ename->vla-object en))
(make-dynprop-dial)
(setq lstpair (run-dynprop-dial blk))
(if (= knock 1)
(progn

(not
(vl-catch-all-error-p
(vl-catch-all-apply
'(lambda ()
(changedynblockprop blk (car lstpair) (cadr lstpair))
) ;_ end of lambda
) ;_ end of vl-catch-all-apply
) ;_ end of vl-catch-all-error-p
) ;_ end of not
) ;_ end of progn

) ;_ end of if

(princ)
) ;_ end of defun
(prompt
"\n\t\t\t |-----------------------------|\n"
)
(prompt
"\n\t\t\t <| Start with CD to execute |>\n"
)
(prompt
"\n\t\t\t |-----------------------------|\n"
)
(or (vl-load-com)(princ))

ReachAndre
2013-08-06, 12:29 PM
(vl-load-com)
(defun c:insert_and_change (/ blkobj props res boxsize bname oid)
(setq bname "Titus Air Terminal With Reheat");name of block VERBATIM (case sensitive)
(setq boxsize "16 (2405 - 3200)");name of visibility state VERBATIM (case sensitive)

(command "-insert" bname "S" 1 pause 0)

(setq oid (vla-get-ObjectId (vlax-ename->vla-object (entlast))))

(setq props (vlax-safearray->list
(variant-value
(vla-getdynamicblockproperties
(setq blkobj (vlax-ename->vla-object (entlast)))))))
(if (vl-catch-all-error-p
(setq res (vl-catch-all-apply
(function
(lambda ()
(foreach a props
(if (eq "Visibility" (vla-get-propertyname a))
(vlax-put-property a 'Value boxsize))))))))
(vl-catch-all-error-message res))

(princ)
)