Author Topic: Text width for attribute value within Dynamic block  (Read 5450 times)

0 Members and 1 Guest are viewing this topic.

OcCad

  • Guest
Text width for attribute value within Dynamic block
« on: November 20, 2007, 09:30:36 PM »
Hey guys,

I'm stuck. Trying to write a routine that acquires a selection set and modifies the TAG "sheets" text width within dynamic blocks. The code is what I've slapped together reading threads.

Code: [Select]
(defun c:setw ()
  (setq txw (getreal (strcat "\nEnter sheet number text width factor <" (rtos txw_default 2) ">: ")))
  (if (= txw nil) (setq txw txw_default) (setq txw_default txw))

(vl-load-com)

(setq ss nil)
(setq ss (ssget))
 (if ss
  (progn
   (setq n (sslength ss))
     (setq index 0)
       (repeat n
        (setq ent1 (entget (ssname ss index)))
        (setq index (1+ index))
        (setq blkname (cdr (assoc 2 ent1)))
         (if (vl-string-search "*U" blkname)
  (setq blkname (vla-get-effectivename (vlax-ename->vla-object (ssname ss index))))
        )
        (if (or (= (strcase blkname T) "MI Detail Bubble")
        (= (strcase blkname T) "MI Detail Cut")
        (= (strcase blkname T) "MI Section Cut")
        (= (strcase blkname T) "MI Detail Elevation")
    );or
          (progn
           (setq ent1 (entnext ent1))
           (setq ent1 (entnext ent1))
           (setq tag (entget ent1))
           (entmod (subst (cons 41 txw) (assoc 41 tag) tag))
           (entupd ent1)
  );progn
        );if
       );repeat
  );progn
);if

  (setq ss nil)
  (princ)
)

I think i'm getting stuck at
Code: [Select]
(progn
           (setq ent1 (entnext ent1))
           (setq ent1 (entnext ent1))
           (setq tag (entget ent1))
           (entmod (subst (cons 41 txw) (assoc 41 tag) tag))
           (entupd ent1)
  );progn

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Text width for attribute value within Dynamic block
« Reply #1 on: November 21, 2007, 11:51:25 AM »
One problem...these are always going to return nil since is looking for an all lower case string.

Code: [Select]
(or (= (strcase blkname T) "MI Detail Bubble")
        (= (strcase blkname T) "MI Detail Cut")
        (= (strcase blkname T) "MI Section Cut")
        (= (strcase blkname T) "MI Detail Elevation")
    );or

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Text width for attribute value within Dynamic block
« Reply #2 on: November 21, 2007, 12:01:32 PM »
Maybe this will give you some ideas:

Code: [Select]
(setq ss (ssget '((0 . "INSERT") (66 . 1))));;Will filter only attributed blocks

;;loop here

(setq obj (vlax-ename->vla-object (ssname ss index)))

(setq atts (vlax-invoke obj 'getattributes))

(foreach att atts
     ;;do your tests and modifications here
)

;;end loop

Here are the properties for att:

Quote
<Alignment>   0
<Application>   #<VLA-OBJECT IAcadApplication 00d74d3c>
<Backward>   :vlax-false
<Constant>   :vlax-false
<Document>   #<VLA-OBJECT IAcadDocument 01b33e88>
<FieldLength>   0
<Handle>   1FB
<HasExtensionDictionary>   :vlax-false
<Height>   0.1
<Hyperlinks>   #<VLA-OBJECT IAcadHyperlinks 18930d4c>
<InsertionPoint>   #<variant 8197 ...>
<Invisible>   :vlax-false
<Layer>   0
<Linetype>   ByLayer
<LinetypeScale>   1.0
<Lineweight>   -1
<LockPosition>   :vlax-true
<MTextAttribute>   :vlax-false
<MTextAttributeContent>   
<MTextBoundaryWidth>   0.0
<MTextDrawingDirection>   5
<Material>   ByLayer
<Normal>   #<variant 8197 ...>
<ObjectID>   2122763480
<ObjectName>   AcDbAttribute
<ObliqueAngle>   0.0
<OwnerID>   2122763472
<PlotStyleName>   ByLayer
<Rotation>   0.0
<ScaleFactor>   1.0
<StyleName>   arial
<TagString>   CALLOUT
<TextAlignmentPoint>   #<variant 8197 ...>
<TextGenerationFlag>   0
<TextString>   
<Thickness>   0.0
<TrueColor>   #<VLA-OBJECT IAcadAcCmColor 06ad8cd8>
<UpsideDown>   :vlax-false
<Visible>   :vlax-true

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

OcCad

  • Guest
Re: Text width for attribute value within Dynamic block
« Reply #3 on: November 21, 2007, 12:47:23 PM »
This code seems to be working fine...
Code: [Select]
(or (= (strcase blkname T) "MI Detail Bubble")
        (= (strcase blkname T) "MI Detail Cut")
        (= (strcase blkname T) "MI Section Cut")
        (= (strcase blkname T) "MI Detail Elevation")
    );or
I am consistantly getting a value for blkname when I test it

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Text width for attribute value within Dynamic block
« Reply #4 on: November 21, 2007, 12:53:53 PM »
Strange...

You could also go this route to test:

Code: [Select]
(setq blkname (strcase (vla-get-effectivename (vlax-ename->vla-object (ssname ss index)))T))

(if (member blkname
    '("mi detail bubble"
      "mi detail cut"
      "mi section cut"
      "mi detail elevation"
     )
    )
  (progn

  )
)


« Last Edit: November 27, 2007, 01:48:03 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

OcCad

  • Guest
Re: Text width for attribute value within Dynamic block
« Reply #5 on: November 21, 2007, 03:32:24 PM »
So after I am to select my entity. I need help on how to use <TagString> "Sheets" to change the text width.

Need help with (vlax-invoke ent1 'getattributes), (vla-get-tagstrings) or (vla-get-width)

Joe Burke

  • Guest
Re: Text width for attribute value within Dynamic block
« Reply #6 on: November 22, 2007, 06:05:28 AM »
So after I am to select my entity. I need help on how to use <TagString> "Sheets" to change the text width.

Need help with (vlax-invoke ent1 'getattributes), (vla-get-tagstrings) or (vla-get-width)

You want to change the ScaleFactor property of the attribute references.

(foreach att (vlax-invoke blkobj 'GetAttributes))
  (vlax-put att 'ScaleFactor txw)
)

OcCad

  • Guest
Re: Text width for attribute value within Dynamic block
« Reply #7 on: November 26, 2007, 08:56:54 PM »
Cant figure out why this is not working...

Code: [Select]
(defun c:STW ()
  (setq txw (getreal (strcat "\nEnter sheet number text width factor <" (rtos txw_default 2) ">: ")))
    (if (= txw nil)
      (setq txw txw_default)
      (setq txw_default txw)
    );if

  (vl-load-com)

  (setq ss nil)
  (setq ss (ssget '((0 . "INSERT") (66 . 1))))
    (if ss
      (progn
        (setq n (sslength ss))
        (setq index 0)
          (repeat n
            (setq obj (vlax-ename->vla-object (ssname ss index)))
            (setq index (1+ index))
            (setq atts (vlax-invoke obj 'getattributes))
            (setq blkname (strcase (vla-get-effectivename obj)))       
              (if (member blkname
                   '("mi detail bubble"
                     "mi detail cut"
                     "mi section cut"
                     "mi detail elevation"))
                (progn
                  (foreach att atts
                  (vlax-put att 'ScaleFactor txw))
                );progn
              );if
          );repeat
      );progn
    );if
 
  (setq ss nil)
  (princ)
);end defun

getting "; error: bad argument type: VLA-OBJECT nil"
« Last Edit: November 27, 2007, 12:05:47 PM by OcCad »

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Re: Text width for attribute value within Dynamic block
« Reply #8 on: November 26, 2007, 11:04:02 PM »
Code: [Select]
(progn
                  (foreach att atts)
                  (vlax-put att 'ScaleFactor txw)
                );progn

should be:
Code: [Select]
(progn
                  (foreach att atts
                    (vlax-put att 'ScaleFactor txw)
                  )
                );progn

Joe Burke

  • Guest
Re: Text width for attribute value within Dynamic block
« Reply #9 on: November 27, 2007, 05:45:24 AM »
Cant figure out why this is not working...

Sorry, I mislead you with an extra paren.

OcCad

  • Guest
Re: Text width for attribute value within Dynamic block
« Reply #10 on: November 27, 2007, 12:04:34 PM »
No, Joe, it's okay; caught it as well. However for some reason the code runs and does nothing. I've tried testing all of my variables to see where it gets stuck to end up not really finding anything. But then when I type (all variables kept global)
Code: [Select]
(foreach att atts (vlax-put att 'scalefactor txw)) the text within the block FINALLY changes. Where is it getting stuck? And is there a way to change the text of only one tag versus the other?

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Re: Text width for attribute value within Dynamic block
« Reply #11 on: November 27, 2007, 01:32:20 PM »
Where is it getting stuck? And is there a way to change the text of only one tag versus the other?
The Block name is not matching EXACTLY, including Upper/Lower case, the names being checked against (Note that you set the Blockname to UPPERCASE, yet all of the names to check are lower case). To solve that issue, change this line:
Code: [Select]
(setq blkname (strcase (vla-get-effectivename obj)))to this:
Code: [Select]
(setq blkname (strcase (vla-get-effectivename obj) t))
To only change some of the attributes based on the Tag, just check the Tagstring property and make the change accordingly.

OcCad

  • Guest
Re: Text width for attribute value within Dynamic block
« Reply #12 on: November 27, 2007, 02:08:22 PM »
Something like this?
Code: [Select]
(progn
           (foreach att (vlax-invoke obj 'getattributes)
             (cond ((= "sheet" (vla-get-tagstring att))(vlax-put-scalefactor att txw))
             );cond
           )
         );progn
« Last Edit: November 27, 2007, 02:17:22 PM by OcCad »

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Re: Text width for attribute value within Dynamic block
« Reply #13 on: November 27, 2007, 02:48:08 PM »
Something like that, yes. But, IIRC, Tagstrings are always returned uppercase.........

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Text width for attribute value within Dynamic block
« Reply #14 on: November 27, 2007, 02:53:21 PM »
I'm not sure if you've achieved your goal...but try this out:

Code: [Select]
(defun c:STW (/ ATTS BLKNAME INDEX N OBJ SS TXW TXW_DEFAULT)
  (setq
    txw (getreal (strcat "\nEnter sheet number text width factor <"
(rtos txw_default 2)
">: "
)
)
  )
  (if (= txw nil)
    (setq txw txw_default)
    (setq txw_default txw)
  ) ;if
  (vl-load-com)
  (setq ss (ssget '((0 . "INSERT") (66 . 1))))
  (if ss
    (progn
      (setq n   (sslength ss)
    index 0
      )
      (repeat n
(setq obj     (vlax-ename->vla-object (ssname ss index))
      index   (1+ index)
      atts    (vlax-invoke obj 'getattributes)
      blkname (strcase (vla-get-effectivename obj) T)
)
(if (member blkname
    '("mi detail bubble"
      "mi detail cut"
      "mi section cut"
      "mi detail elevation"
     )
    )
  (foreach att atts
    (if (= "SHEETS" (vla-get-tagstring att))
      (vla-put-scalefactor att txw)
    )
  )
) ;if
      ) ;repeat
    ) ;progn
  ) ;if
  (princ)
) ;end defun

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

OcCad

  • Guest
Re: Text width for attribute value within Dynamic block
« Reply #15 on: November 27, 2007, 04:42:20 PM »
Thanks for your help guys. Here it is if anyone likes...

Code: [Select]
(defun c:setw (/ ss n index obj atts blkname)

  (setq txw (getreal (strcat "\n[color=red]PROMPT[/color] <" (rtos txw_default 2) ">: ")))
    (if (= txw nil)
      (setq txw txw_default)
      (setq txw_default txw)
    );if

  (vl-load-com)

  (setq ss nil)
  (setq ss (ssget '((0 . "INSERT") (66 . 1))))
    (if ss
      (progn
        (setq n (sslength ss))
        (setq index 0)
          (repeat n
            (setq obj (vlax-ename->vla-object (ssname ss index)))
            (setq index (1+ index))
            (setq atts (vlax-invoke obj 'getattributes))
            (setq blkname (strcase (vla-get-effectivename obj) t))       
              (if (member blkname
       '("[color=red]block1[/color]"
         "[color=red]block2[/color]"
         "[color=red]block3[/color]"
         "[color=red]block4[/color]"
        )
      );if
                (progn
                  (foreach att atts
                     (cond
                       ((= "[color=red]TAG[/color]" (vla-get-tagstring att))
                       (vla-put-scalefactor att txw))
                     );cond
                  );foreach
                );progn
              );if
          );repeat
      );progn
    );if
 
  (setq ss nil)
  (princ)
);end defun