Results 1 to 3 of 3

Thread: Parameter block a lisp.

  1. #1
    Member
    Join Date
    2009-01
    Posts
    37
    Login to Give a bone
    0

    Default Parameter block a lisp.

    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!

  2. #2
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: Parameter block a lisp.

    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
    Code:
    (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))

  3. #3
    I could stop if I wanted to
    Join Date
    2015-12
    Posts
    385
    Login to Give a bone
    0

    Default Re: Parameter block a lisp.

    (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)
    )

Similar Threads

  1. Count and group Block Parameter by lisp,
    By hoangtungxd8947436 in forum AutoLISP
    Replies: 2
    Last Post: 2015-02-09, 11:56 PM
  2. 2012: Autocad Dynamic Block > IP address from Flip parameter on Dip Switch Block
    By chupp.ryan348046 in forum Dynamic Blocks - Technical
    Replies: 1
    Last Post: 2013-01-11, 07:55 PM
  3. Select & entget object information in XREF and block-in-block with Lisp
    By Wish List System in forum AutoCAD Wish List
    Replies: 0
    Last Post: 2012-11-14, 09:11 AM
  4. Block Action Parameter to insert another block
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 0
    Last Post: 2010-06-09, 05:25 PM
  5. LISP Block Insert routine no longer works once a parameter is modified
    By JAC.95598 in forum Dynamic Blocks - Technical
    Replies: 1
    Last Post: 2005-11-22, 04:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •