Get the length of a string in an attribute

Get the length of a string in an attribute

msarqui
Collaborator Collaborator
987 Views
1 Reply
Message 1 of 2

Get the length of a string in an attribute

msarqui
Collaborator
Collaborator

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

0 Likes
988 Views
1 Reply
Reply (1)
Message 2 of 2

john.uhden
Mentor
Mentor

You could simplify your code by using the getattributes method.

Your use of textbox and (apply 'max ...) is good.

You appear to be able to handle your own challenges very well.  Keep up the good work.

I don't know anything about dynamic blocks, but you should be able to vla-add a line of desired length.

John F. Uhden

0 Likes