Message 1 of 2
Get the length of a string in an attribute
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi guys,
I am trying to get the length of a string in a attribute inside a block and apply that length to a line in the same block. So far I could get the length of the attribute itself. Could someone help me please?
It must be the length of the longest attribute string.
(defun c:test ( / doc sel ent effname vlobj subent ename len val vallst higth) (setq doc (vla-get-activedocument (vlax-get-acad-object))) (princ "\n ** Select a block to adjust the line: **") (setq sel (ssget ":S" (list '(0 . "INSERT")))) (progn (vlax-for ent (setq sel (vla-get-activeselectionset doc)) (setq effname (vla-get-EffectiveName ent)) (setq vlobj ent) (vlax-for subent (vla-item (vla-get-blocks doc) effname) (if (= (vla-get-objectname subent) "AcDbAttributeDefinition") (progn (setq ename (vlax-vla-object->ename subent)) (setq len (textbox (entget ename))) (setq val (- (caadr len) (caar len))) (setq vallst (cons val vallst)) ) ) ) );vlax-for (setq higth (apply 'max vallst)) (LM:setdynpropvalue vlobj "DistanceTitre" higth) (vla-delete sel) );progn (princ) )
;; http://www.lee-mac.com/dynamicblockfunctions.html ;; Set Dynamic Block Property Value - Lee Mac ;; Modifies the value of a Dynamic Block property (if present) ;; blk - [vla] VLA Dynamic Block Reference object ;; prp - [str] Dynamic Block property name (case-insensitive) ;; val - [any] New value for property ;; Returns: [any] New value if successful, else nil (defun LM:setdynpropvalue (blk prp val) (setq prp (strcase prp)) (vl-some '(lambda (x) (if (= prp (strcase (vla-get-propertyname x))) (progn (vla-put-value x (vlax-make-variant val (vlax-variant-type (vla-get-value x)))) (cond (val) (t) ) ) ) ) (vlax-invoke blk 'getdynamicblockproperties) ) )
Thanks
Marcelo