Results 1 to 4 of 4

Thread: AutoLISP function to change DB's values

  1. #1
    AUGI Addict truevis's Avatar
    Join Date
    2004-07
    Location
    Massachusetts, USA
    Posts
    1,191
    Login to Give a bone
    0

    Default AutoLISP function to change DB's values

    This works for numerical values. If the DB has allowed values, it seems to change to the nearest allowed.

    Sample usage:
    _$ (change-db (entlast) 21 "Door Width" )
    T
    _$ (change-db (entlast) 21 "Door width" )
    nil

    PHP Code:
    ;;; Change a given value in your insert

    (defun change-db  (esb val prop obj v vval sal salnth count changed?)
      (
    setq obj (vlax-ename->vla-object esb))
      (
    setq v (vla-getdynamicblockproperties obj))
      (
    setq vval (vlax-variant-value v))
      (
    setq sal (vlax-safearray->list vval))
      (
    setq salnth (length sal))
      (
    setq count 0)
      (while (< 
    count salnth)
        (if (= (
    vlax-get-property (nth count sal"PropertyName"prop)
          (
    progn (vlax-put-property (nth count sal)
                                    
    "Value"
                                    
    (vlax-make-variant val vlax-vbdouble))
                 (
    setq count salnth)
                 (
    setq changedt))
          (
    setq count (+ count 1))))
      
    changed?); returns T if changed 

  2. #2
    I could stop if I wanted to
    Join Date
    2001-01
    Posts
    257
    Login to Give a bone
    0

    Default Re: AutoLISP function to change DB's values

    Truevis

    The getdbval routine works great. Thank you very much. I am playing with the change-db routine on a flipped block and I have not been able to change the flip state of a selected block. I am getting a weird: "Automation error. Input invalid". I am using (change-db (entlast) 1 "Flip state") when I get the message. Thanks

    Manuel

  3. #3
    I could stop if I wanted to kpblc2000's Avatar
    Join Date
    2006-09
    Posts
    212
    Login to Give a bone
    0

    Default Re: AutoLISP function to change DB's values

    Another variant to set any kind of dynamic properties of dynblock (indexed or not):
    Code:
    (defun set-dyn-value (ent             property        value
                          /               *error*         adoc
                          loc:conv-ent-to-vla             loc:conv-vla-to-list
                          loc:prop
                          )
                         ;|
    *    Set a new value of dynamic property of block
    *    Call parameters:
    	ent		pointer to dynamic block (ename | vla). nil -> exit
    	property	property name to be changed. Mask symbols allowed
    	value		new value of property
    |;
      (defun *error* (msg)
        (vla-endundomark adoc)
        (princ msg)
        (princ)
        ) ;_ end of defun
    
      (defun loc:conv-ent-to-vla (pointer)
        (cond
          ((= (type pointer) 'ename) (vlax-ename->vla-object pointer))
          ((= (type pointer) 'vla-object) pointer)
          (t nil)
          ) ;_ end of cond
        ) ;_ end of defun
    
      (defun loc:conv-vla-to-list (value)
        (cond
          ((not value) nil)
          ((listp value)
           (mapcar 'loc:conv-vla-to-list value)
           )
          ((= (type value) 'variant)
           (loc:conv-vla-to-list (vlax-variant-value value))
           )
          ((= (type value) 'safearray)
           (if (>= (vlax-safearray-get-u-bound value 1) 0)
             (loc:conv-vla-to-list (vlax-safearray->list value))
             ) ;_ end of if
           )
          (t value)
          ) ;_ end of cond
        ) ;_ end of defun
    
      (vl-load-com)
      (vla-startundomark
        (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
        ) ;_ end of vla-startundomark
      (if
        (and
          ent
          (setq ent (loc:conv-ent-to-vla ent))
          (vlax-property-available-p ent 'isdynamicblock)
          (equal (vla-get-isdynamicblock ent) :vlax-true)
          (setq loc:prop
                 (car (vl-remove-if-not
                        '(lambda (x)
                           (wcmatch (strcase (vla-get-propertyname x)) (strcase property))
                           ) ;_ end of lambda
                        (loc:conv-vla-to-list
                          (vla-getdynamicblockproperties ent)
                          ) ;_ end of loc:conv-vla-to-list
                        ) ;_ end of vl-remove-if-not
                      ) ;_ end of car
                ) ;_ end of setq
          ) ;_ end of and
         (progn
           (vl-catch-all-apply
             (function
               (lambda ()
                 (vla-put-value
                   loc:prop
                   (if (vla-get-allowedvalues loc:prop)
                     (vlax-make-variant
                       value
                       (vlax-variant-type (vla-get-value loc:prop))
                       ) ;_ end of vlax-make-variant
                     (cond
                       ((= (type (vla-get-value prop)) 'str)
                        (vl-princ-to-string value)
                        )
                       ((= (type (vla-get-value prop)) 'int)
                        (atoi (vl-princ-to-string value))
                        )
                       (t value)
                       ) ;_ end of cond
                     ) ;_ end of if
                   ) ;_ end of vla-put-value
                 ) ;_ end of lambda
               ) ;_ end of function
             ) ;_ end of vl-catch-all-apply
           ) ;_ end of progn
         ) ;_ end of if
      (vla-endundomark adoc)
      (princ)
      ) ;_ end of defun
    P.S. Written and tested on AutoCAD2007+SP1

  4. #4
    AUGI Addict truevis's Avatar
    Join Date
    2004-07
    Location
    Massachusetts, USA
    Posts
    1,191
    Login to Give a bone
    0

    Default Re: AutoLISP function to change DB's values

    Quote Originally Posted by cadconcepts View Post
    The getdbval routine works great. Thank you very much. I am playing with the change-db routine on a flipped block and I have not been able to change the flip state of a selected block. I am getting a weird: "Automation error. Input invalid". I am using (change-db (entlast) 1 "Flip state") when I get the message. Thanks
    Maybe because flip states are vlax-vbBoolean, not vlax-vbdouble

    See http://intervision.hjem.wanadoo.dk/d...es.htm#Variant

    kpblc2000: cool function!

Similar Threads

  1. Elevation Retrive? Using AutoLisp Function
    By sanrajbhar677632 in forum AutoLISP
    Replies: 3
    Last Post: 2011-11-08, 04:40 AM
  2. Autolisp function to determine point location
    By BrenBren in forum API Wish List
    Replies: 2
    Last Post: 2010-09-28, 03:45 PM
  3. Autolisp Function to Determine Point Location
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 2
    Last Post: 2008-05-21, 10:50 AM
  4. Change the F1 function key to perform some other function
    By Spanky in forum AutoCAD Customization
    Replies: 7
    Last Post: 2007-11-28, 04:14 PM
  5. AutoLISP function to get values of existing dynamic block insert
    By truevis in forum Dynamic Blocks - Technical
    Replies: 0
    Last Post: 2007-11-17, 04:34 PM

Posting Permissions

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