Author Topic: Tag width adjusted in Title Block attribute  (Read 1496 times)

0 Members and 1 Guest are viewing this topic.

jlogan02

  • Bull Frog
  • Posts: 327
Tag width adjusted in Title Block attribute
« on: September 28, 2018, 06:56:57 PM »
Micheal Puckett wrote this piece of code for me earlier this year and I've updated a couple of times to my liking. I just added the ability to let the user pick the TitleLine whose width they want to adjust.

It works fine in that it adjusts a TitleLine that extends outside the title block. However, it doesn't seem to matter where on the attribute a user picks. The routine simply adjust whichever TitleLine overruns the title block. So if TitleLine1 is wider than the title block and a user picks TitleLine4 or just somewhere on the attribute, the routine adjusts TitleLine1. But that's not how it should work. It should be, Pick the TitleLine you want to adjust. Not just pick anywhere. Or maybe it shouldn't. As long as it's working. My guess is that any text that is wider than 5.25 gets adjust down. I haven't tried expanding any of the other attribute lines to see because their width will never be larger than what is already specified. The concern is really just TitleLines1,2, & 3

At any rate. I'd like to know where I've gone wrong.

Code - Auto/Visual Lisp: [Select]
  1. ;;Adjusts any selected TitleLine whose text is wider than the defined width of the title block.
  2. ;;User selects the STA_TW button and then selects desired text.
  3. ;;
  4. ;;4-12-2018 Routine created by Michael Puckett @ CAD ANALYST
  5. ;;4-12-2018 Modified by Jerry Logan
  6. ;;4-12-2018 Added functionality for use with dimscale.
  7. ;;9-28-2018 Added user selection to change width of any tag that is outside the title block lines.
  8. ;;
  9. ;;After select STA_TW button select attribute. The routine will find any TitleLine that is wider than the
  10. ;;title block allows and adjust it's width to fit inside the title block.
  11. ;;
  12. ;;Command: STA_ATT_WIDTH
  13. ;;
  14. ;;
  15.  
  16.  
  17. (defun mpx-get-bounding-box ( object / a b )
  18.     (vl-catch-all-apply 'vlax-invoke-method (list object 'GetBoundingBox 'a 'b))
  19.     (if a (mapcar 'vlax-safearray->list (list a b)))
  20. )
  21.  
  22. (defun mpx-restrict-attrib-widths ( block-reference tag-spec max-width / bb dx ratio flag )
  23.     (and
  24.         (eq 'vla-object (type block-reference))
  25.         (eq "AcDbBlockReference" (vla-get-objectname block-reference))
  26.         (eq :vlax-true (vla-get-hasattributes block-reference))
  27.         (setq tag-spec (strcase (if (eq 'str (type tag-spec)) tag-spec "*")))
  28.         (foreach a (vlax-invoke block-reference 'GetAttributes)
  29.             (and
  30.                 (wcmatch (vla-get-tagstring a) tag-spec)
  31.                 (setq bb (mpx-get-bounding-box a))
  32.                 (setq dx (abs (apply '- (mapcar 'car bb))))
  33.                 (< 1.0 (setq ratio (/ dx max-width)))
  34.                 (setq flag t)
  35.                 (vla-put-scalefactor a (* (vla-get-scalefactor a) (/ 1.0 ratio)))
  36.             )
  37.        
  38.         )
  39.         (if flag (vla-update block-reference))
  40.     )
  41.     (princ)
  42. )
  43.  
  44. (defun c:STA_ATT_WIDTH ( / block-spec tag-spec max-width ss i )
  45.  
  46.    (setq temperr *error*)
  47.    (setq *errer* trap1)
  48.    (setq oldecho (getvar "cmdecho"))
  49.    (setvar "cmdecho" 0)
  50. ;;--------------------------------
  51. ;;This was Micheal's original code
  52. ;;(setq
  53.        ;;block-spec "TBLK_ATT_CTL"
  54.         ;;tag-spec   "Desired TitleLine tag goes here"
  55.         ;;max-width  (* 5.25 (getvar 'dimscale));;multiply 5.25 dimscale
  56.         ;;)
  57.  
  58. ;;--------------------------------
  59. ;;This is how I changed it
  60.         block-spec "TBLK_ATT_CTL"
  61.         max-width  (* 5.25 (getvar 'dimscale));;multiply 5.25 dimscale
  62.         )
  63.    (setq tag-spec (entsel "\nselect TitleLine: ")  ;;removed tag-spec "TitleLine#"
  64.        
  65.         )
  66. ;;------------------------------
  67.    
  68.  (if (setq ss (ssget "x" (list '(0 . "insert")'(66 . 1)(cons 2 block-spec))))
  69.         (repeat (setq i (sslength ss))
  70.             (mpx-restrict-attrib-widths
  71.                 (vlax-ename->vla-object (ssname ss (setq i (1- i))))
  72.                 tag-spec
  73.                 max-width
  74.             )
  75.         )
  76.     )
  77.     (setvar "cmdecho" oldecho)
  78.     (princ)
  79.    
  80. )
  81.  
  82. (defun trap1 ( / errmsg)
  83.     (command "u" "b")
  84.     (setvar "cmdecho" oldecho)
  85.     (setq *errer* temperr)
  86.     (prompt "\nResetting System Variables ")
  87.   (princ)
  88. )

J. Logan
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

Dlanor

  • Bull Frog
  • Posts: 263
Re: Tag width adjusted in Title Block attribute
« Reply #1 on: September 29, 2018, 10:04:48 AM »
Just an observation from my initial scanning of the code, but in MP's original code "tag-spec" variable was set to a string. Your modification is setting it to an entsel selection list.

To select an attribute within a block you need to use nentsel and then get the tagstring.

Line No 65

Code - Auto/Visual Lisp: [Select]
  1.  (setq tag-spec (vlax-get-property (vlax-ename->vla-object (car (nentsel "\nselect TitleLine: "))) 'tagstring))