0 Members and 1 Guest are viewing this topic.
(defun set-value-to-attr (block-ref att-tag value / lst err _kpblc-conv-vla-to-list) ;|* settings value to attribute* Call params: block-ref Block reference pointer att-tag Attribute tag value Value to be setted* Call sample:(if (setq blk (ssname (ssget "_+.:s:e:l" '((0 . "insert") (66 . 1))) 0)) (set-value-to-attr blk "viewnumber" "qwer") ) ;_ end of if|; (defun _kpblc-conv-vla-to-list (value / res) (cond ((listp value) (mapcar (function _kpblc-conv-vla-to-list) value) ) ((= (type value) 'variant) (_kpblc-conv-vla-to-list (vlax-variant-value value)) ) ((= (type value) 'safearray) (if (>= (vlax-safearray-get-u-bound value 1) 0) (_kpblc-conv-vla-to-list (vlax-safearray->list value)) ) ;_ end of if ) (t value) ) ;_ end of cond ) ;_ end of defun (if (= (type block-ref) 'ename) (setq block-ref (vlax-ename->vla-object block-ref)) ) ;_ end of if (foreach att (_kpblc-conv-vla-to-list (vla-getattributes block-ref)) (if (wcmatch (strcase (vla-get-tagstring att)) (strcase att-tag)) (if (vl-catch-all-error-p (setq err (vl-catch-all-apply (function (lambda () (vla-put-textstring att value) ) ;_ end of lambda ) ;_ end of function ) ;_ end of vl-catch-all-apply ) ;_ end of setq ) ;_ end of vl-catch-all-error-p (princ "\nError setting value \"" value "\" to Attribute \"" att-tag "\" : " (vl-catch-all-error-p err) ) ;_ end of princ ) ;_ end of if ) ;_ end of if ) ;_ end of foreach ) ;_ end of defun