TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: MeasureUp on March 29, 2024, 02:02:31 AM

Title: Attribute Text Width
Post by: MeasureUp on March 29, 2024, 02:02:31 AM
There is a given attribute named as ATT-01 in a given block BLK-01.
How to change the attribute text width to 0.75?

I did a search here but don't find what I am exactly after.

Thanks in advance.
Title: Re: Attribute Text Width
Post by: Lastknownuser on March 29, 2024, 07:03:56 AM
Try this it should work
Code: [Select]
(defun c:test ( / int sel ent get)
(setq int -1)
(setq sel (ssget '((0 . "INSERT") (2 . "BLK-01"))));BLK-01
(while (setq int (1+ int)
     ent (ssname sel int)
     );setq
  (while (/= (cdr (assoc 0 (setq get (entget (setq ent (entnext ent)))))) "SEQEND")
    (if (= (cdr (assoc 2 get)) "ATT-01");ATT-01
      (entupd (cdr (assoc -1 (entmod (subst (cons 41 0.75) (assoc 41 get) get)))));0.75
      );if
    );while
  );while
);defun

edit: localised all variables
Title: Re: Attribute Text Width
Post by: MeasureUp on May 06, 2024, 07:07:41 AM
Thanks for the help.
And sorry for the late reply as too busy after Easter.

Another thought...
How to update the text width if it is an attribute in title blocks in a multi-page drawing?
Thanks.
Title: Re: Attribute Text Width
Post by: ribarm on May 06, 2024, 07:57:28 AM
Thanks for the help.
And sorry for the late reply as too busy after Easter.

Another thought...
How to update the text width if it is an attribute in title blocks in a multi-page drawing?
Thanks.

Have you tried changing this line :
Code: [Select]
(setq sel (ssget '((0 . "INSERT") (2 . "BLK-01"))));BLK-01
To this :
Code: [Select]
(setq sel (ssget "_X" '((0 . "INSERT") (2 . "BLK-01"))));BLK-01
And then iterate through sel. set 'sel'...
Title: Re: Attribute Text Width
Post by: MeasureUp on May 07, 2024, 01:58:09 AM
Thanks.

I was thinking of using "vla-put-textwidth" but didn't figure it out.
Can anyone help?
Thanks again.
Title: Re: Attribute Text Width
Post by: HOSNEYALAA on May 07, 2024, 03:44:56 AM
can you  addition a sample dwg
Title: Re: Attribute Text Width
Post by: MeasureUp on May 07, 2024, 11:17:55 PM
There is nothing special in the drawing file or template.

My starting point is an example in the ActiveX section in HELP showed below.
I have no idea to redefine the "oML" in my case by given a title block "BLK-01" and an attribute "ATT-01" based on multi page drawing.

I'd like to learn this method.
Thanks.

Code: [Select]
(defun c:Example_TextManipulation()
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
 
    ;; Define the leader points
    (setq points (vlax-make-safearray vlax-vbDouble '(0 . 14)))
    (vlax-safearray-fill points '(1 1 0
                                  1 2 0
                                  2 2 0
                                  3 2 0
                                  4 4 0
                                 )
    )
    (setq i 0)

    (setq modelSpace (vla-get-ModelSpace doc))
    (setq oML (vla-AddMLeader modelSpace points i))
   
    (vla-put-TextWidth oML 7.4)
)
Title: Re: Attribute Text Width
Post by: Lastknownuser on May 09, 2024, 04:24:32 AM
There is nothing special in the drawing file or template.

My starting point is an example in the ActiveX section in HELP showed below.
I have no idea to redefine the "oML" in my case by given a title block "BLK-01" and an attribute "ATT-01" based on multi page drawing.

I'd like to learn this method.
Thanks.

Code: [Select]
(defun c:Example_TextManipulation()
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
 
    ;; Define the leader points
    (setq points (vlax-make-safearray vlax-vbDouble '(0 . 14)))
    (vlax-safearray-fill points '(1 1 0
                                  1 2 0
                                  2 2 0
                                  3 2 0
                                  4 4 0
                                 )
    )
    (setq i 0)

    (setq modelSpace (vla-get-ModelSpace doc))
    (setq oML (vla-AddMLeader modelSpace points i))
   
    (vla-put-TextWidth oML 7.4)
)

Your case is a different thing compared to code attached. If you want to do it with visual lisp (vla), you have to get Attribute Reference ATT-01 of the block BLK-01 and change its width using vla-put-scalefactor.