Jump to content

change text size in block reference...help


leonucadomi

Recommended Posts

hello friends:

 

Does anyone have a routine to modify the size of the texts in this block?

 

I want to modify these three text sizes for one that I previously decide.

 

somebody help me please. :)

 

block.dwg

Link to comment
Share on other sites

For a single block I would do as RonJon, just edit the block and attsync.

 

A LISP and other automation works best to do the same action many times with minimal user input. How many blocks are you wanting to change by the way? Is it just a single block, many, or do you need to do this frequently? (writing, testing and verifying that a LISP works as expected takes some time, which might not be a time saving if you are only ever going to do this once or twice)

Link to comment
Share on other sites

I found this but it changes the width and I'm looking to change the text size....:(

 

 

(vl-load-com)
(defun C:BTW ; = Block Text Width
  (/ width blk ent)
  (setq width (getreal "\nWidth factor for all Text/Attributes: "))
  (setq blk (tblnext "block" t)); first one in Table
  (while blk
    (if (= (logand 20 (cdr (assoc 70 blk))) 0); not an Xref [4] or Xref-dependent [16]
      (progn ; then -- process this Block
        (setq ent (cdr (assoc -2 blk))); first object in Block definition
        (while ent
          (if (wcmatch (cdr (assoc 0 (entget ent))) "TEXT,ATTDEF")
            (vlax-put (vlax-ename->vla-object ent) 'ScaleFactor width)
          ); if
          (setq ent (entnext ent)); next object
        ); while
      ); progn
    ); if
    (setq blk (tblnext "block")); next one in Table
  ); while
  (command "_.attsync" "_name" "*"); update width in Block Attributes, if any
  (princ)
); defun

Link to comment
Share on other sites

I reckon..... if you read through the code.... (setq width .... ) gets the user to input the width - so if you look after that where 'width' is used it will give you a clue?

 

Aha!! "(vlax-put (vlax-ename->vla-object ent) 'ScaleFactor width)".. wonder what would happen if you took a guess and used "Height" instead of "ScaleFactor" ? Lets try.... if it all goes wrong wait for another to answer?

 

 

(defun C:BTH ; = Block Text Height
  (/ width blk ent)
  (setq width (getreal "\nHeight for all Text/Attributes: "))
  (setq blk (tblnext "block" t)); first one in Table
  (while blk
    (if (= (logand 20 (cdr (assoc 70 blk))) 0); not an Xref [4] or Xref-dependent [16]
      (progn ; then -- process this Block
        (setq ent (cdr (assoc -2 blk))); first object in Block definition
        (while ent
          (if (wcmatch (cdr (assoc 0 (entget ent))) "TEXT,ATTDEF")
            (vlax-put (vlax-ename->vla-object ent) 'height width)
          ); if
          (setq ent (entnext ent)); next object
        ); while
      ); progn
    ); if
    (setq blk (tblnext "block")); next one in Table
  ); while
  (command "_.attsync" "_name" "*"); update width in Block Attributes, if any
  (princ)
); defun

 

 

Though as it is, this routine does the change globally for all blocks in the drawing with no selection possible and all attributes in those blocks. It could be a good start for you to then ask "I found this, and changed it to modify text heights, but how could I get it to do this....?"

 

 

Link to comment
Share on other sites

use this code to enter the desired height but it is manually, I would like to do it selecting by window.

 

remembering that the attribute is in a block reference

 

(defun C:test ( / e h )
(setq h (getdist "\nEnter height of text:"))
(repeat 100  
(setq e (vlax-ename->vla-object (car (nentsel "\n Select an attribute to change:"))))
(vla-put-height e h)
); repeat
(princ)
)

Link to comment
Share on other sites

Try this:
 

(defun c:foo (/ b c h n s)
  ;; RJP » 2022-12-02
  (cond
    ((and (or (setq h (getdist "\nEnter height:<1> ")) (setq h 1))
	  (setq s (ssget '((0 . "INSERT") (66 . 1))))
     )
     (setq b (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
     (setvar 'cmdecho 0)
     (foreach e	(vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
       (setq n (vla-get-effectivename (vlax-ename->vla-object e)))
       (or (member n c)
	   (progn (vlax-for a (vla-item b n)
		    (if	(= "AcDbAttributeDefinition" (vla-get-objectname a))
		      (progn (vl-catch-all-apply 'vlax-put (list a 'height h)) (setq c (cons n c)))
		    )
		  )
		  (command "_.Attsync" "Name" n)
	   )
       )
     )
     (setvar 'cmdecho 1)
    )
  )
  (princ)
)
(vl-load-com)

 

And with your code, use WHILE rather than REPEAT. Also check that the item has a height property AND can be modified before trying to set it.

(defun c:test (/ e h)
  (or (setq h (getdist "\nEnter height of text:<1> ")) (setq h 1))
  (while (setq e (car (nentsel "\nSelect an attribute to change:")))
    (if	(and (vlax-property-available-p (setq e (vlax-ename->vla-object e)) 'height)
	     (vlax-write-enabled-p e)
	)
      (vla-put-height e h)
    )
  )
  (princ)
)

 

Edited by ronjonp
  • Like 2
Link to comment
Share on other sites

1 hour ago, leonucadomi said:

use this code to enter the desired height but it is manually, I would like to do it selecting by window.

 

remembering that the attribute is in a block reference

 

(defun C:test ( / e h )
(setq h (getdist "\nEnter height of text:"))
(repeat 100  
(setq e (vlax-ename->vla-object (car (nentsel "\n Select an attribute to change:"))))
(vla-put-height e h)
); repeat
(princ)
)

 

 

Just a point, to put your code with the grey background use the <> button and copy it to the pop up window, it makes it easier to see what is code and what isn't

 

 

'Test' you posted doesn't change the block definition, just the text entered into the attributes - try and see, run it and set a height and then 'attsync' what you just changed, it pops back to how it was, similarly copy 2 of the same block and try it on one, it will only change the one you select.

Link to comment
Share on other sites

FYI You will need to Regen to see changes if selecting with nentsel

 

(defun c:test (/ ADoc e h)
  (setq ADoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
  (or (setq h (getdist "\nEnter height of text:<1> ")) (setq h 1))
  (while (setq e (car (nentsel "\nSelect an attribute to change:")))
    (if (and 
          (vlax-property-available-p (setq e (vlax-ename->vla-object e)) 'height)
          (vlax-write-enabled-p e)
        )
      (vla-put-height e h)
    )
    (vla-Regen ADoc acActiveViewport)
  )
  (princ)
)

 

Edited by mhupp
Code Updated
Link to comment
Share on other sites

Just for fun... this is one I modified from Lee Macs AttCol LISP. All credit to him ( http://www.lee-mac.com/attributecolour.html )

 

This one will modify the text height in selected blocks (not the block definitions). I haven't changed the errors or anything like that, if it doesn't work as expected probably my fault

 

(Same way that your 'test' LISP does but not block definition that your BTW or RonJons FOO does)

 

 

 

;;-------------------=={ Attribute Height }==-----------------;;
;;                                                            ;;
;;  Prompts for a selection of attributed blocks and displays ;;
;;  a dialog interface enabling the user to change the text   ;;
;;  height of specific attribute tags.                        ;;
;;------------------------------------------------------------;;
;;  www.lee-mac.com                                           ;;
;;                                                            ;;
;;  Modified from Lee Mac ATTCOL LISP                         ;;
;;------------------------------------------------------------;;
;;LISP ROUTINES                                               ;;
;;ATTHEIGHT             Change block tag attribute layers     ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;This line loads Visual Lisp / ActiveX 
(vl-load-com)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun c:AttHEIGHT ( / *error* _StartUndo _EndUndo _unique _dclsel doc l lst s ss acount attheight)
  ;; ATTCOL © Lee Mac 2011 & Modified into ATTLAY by SP
  ;;*error*	For errors
  ;; _StartUndo	For unfo
  ;; _EndUndo	For undo
  ;; _unique	To check if tags are unique
  ;; _dclsel	
  ;; doc	
  ;; l		List of tags
  ;; lst	List of layers
  ;; s		Used once to check if tags are unique?
  ;; ss		Used for selecting objects
  ;; acount	A counter, for loops etc
  ;; mylayer

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Initial Values
  (setq attheight 0)  ;; First time default height
  (setq acount 0)   ;; Set counter to 0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Sub routines
;;Error Functions
  (defun *error* ( msg )
    (if doc (_EndUndo doc))
    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
        (princ (strcat "\n** Error: " msg " **")))
    (princ)
  )
;;Undo functions
  (defun _StartUndo ( doc ) (_EndUndo doc)
    (vla-StartUndoMark doc)
  )
  (defun _EndUndo ( doc )
    (if (= 8 (logand 8 (getvar 'UNDOCTL)))
      (vla-EndUndoMark doc)
    )
  )
;;Checks if l is unique 
  (defun _unique ( l ) (if l (cons (car l) (_unique (vl-remove (car l) (cdr l))))))
;;; returns the Layers object
 (defun get-layrobj ()
   (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object) ) )
 )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Makes DCL box
  (defun _dclsel ( l / file tmp dch tagreturn)
    (cond
      (
        (not
;;          (and (setq file (open (setq tmp (vl-filename-mktemp nil nil ".dcl")) "w"))
          (and (setq file (open (setq tmp (strcat (getvar "TEMPPREFIX") "Attlay.dcl")) "w"))
            (write-line
              (strcat
                "attlay : dialog { label = \"Attribute Layer\"; spacer; width = 35;"
                ": boxed_column { label = \"Tags\";"
                "  : row { "
                "      : list_box { label = \"Select Tag(s)\"; key = \"tags\"; width = 30; multiple_select = true ; alignment = centered; }"
                "  }"
                "  : row { "
                "        : button { label = \"Select All\"; key = \"ButSel\";}"
                "        : button { label = \"Clear All\"; key = \"ButClear\";}"
                "  }"
                "}"
                "  : boxed_row { label = \"Height\"; "
                "    : column { width = 15;"
                "       : text { label = \"Enter Height\";}"
                "    }"
                "    : column { width = 20;"
                "      : edit_box { key = \"sel\"; edit_width = 10; alignment = centered; label = \"\"; value = \"2.5\";}" 
                "    }"
                "  }"
                "  : boxed_row { alignment = centered; label = \"OK\";"
                "    spacer; ok_cancel;"
                "  }"
                "}"
              )
              file
            )
            (not (close file)) (< 0 (setq dch (load_dialog tmp))) (new_dialog "attlay" dch)
          )
        )
      )

      (t

;;create tags list
        (start_list "tags") (mapcar 'add_list l) (end_list) ;;creates tag list in list box
        (setq tagreturn (set_tile "tags" "0")) ;;highlights tag at position '0' in list box

;;Create layers list
        (vlax-for acount (get-layrobj)
          (setq lst (cons (vlax-get-property acount 'Name) lst))
        )
        (setq lst (acad_strlsort lst))

;;Actions from DCL Form
        (action_tile "tags" "(setq tagreturn $value)") ;;tagreturn here is position number
        (action_tile "sel" "(setq attheight (get_tile \"sel\"))")
        (action_tile "ButSel" "(SelectAll (length l))")
        (action_tile "ButClear" "(clearAll)")
;;how to check if a layer has been selected?

        
;;set tagreturn, creates list of selected tags positions (eg. "0 1 3 4 5 9 10")
        (setq tagreturn
          (if (= 1 (start_dialog))
            (mapcar '(lambda ( x ) (nth x l)) (read (strcat "(" tagreturn ")")))
          )
        )
      )
    )
    (if (< 0 dch) (unload_dialog dch)) ;;closes DCL box
    (if (setq tmp (findfile tmp)) (vl-file-delete tmp)) ;;closes DCL box
    tagreturn

  ) ;;End of DCL Box

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;magic stuff
  (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))

  (if
    (and (ssget "_:L" '((0 . "INSERT") (66 . 1)))
      (progn
        (vlax-for obj (setq ss (vla-get-ActiveSelectionSet doc))          
          (foreach att
            (append (vlax-invoke obj 'GetAttributes) (vlax-invoke obj 'GetConstantAttributes))
            (setq l (cons (cons (vla-get-TagString att) att) l))
          )
        )
        (vla-delete ss)
        (setq s (_dclsel (acad_strlsort (_unique (mapcar 'car l)))))
      )
    )

    (progn
      (_StartUndo doc)
        (foreach pair l (if (vl-position (car pair) s) (vla-put-height (cdr pair) attheight)))
        (setq mylayer 0)
      (_EndUndo doc)
    )
    (princ "\n*Cancel*")
  )
  (princ)
)

 

Edited by Steven P
Add link to original code
Link to comment
Share on other sites

  • 6 months later...
On 12/2/2022 at 8:12 PM, Steven P said:

Just for fun...

 

Hi @Steven P, thanks for this but when I run an attribute sync on that block again the text reverts to its original.

 

I looked at the code but couldn't see anything that was causing this.

  • Like 1
Link to comment
Share on other sites

the first one I posted, BTH, or the 2nd one, AttHeight ? Attheight doesn't change the block definition, just the way that instance of that block is displayed - so when you attsync that it goes bat the block definition sizes . BTH should update the block definition, and so Attsync shouldn't affect it

  • Like 1
Link to comment
Share on other sites

Yes, that one just changes the text height for that block instance and not the block definition.

 

I'd need to have a good think how to modify that to suit - not sure I'll get time to do that though! Maybe one of the other codes above will do what you want?

Link to comment
Share on other sites

4 hours ago, 3dwannab said:

Hi @Steven P, thanks for this but when I run an attribute sync on that block again the text reverts to its original.

 

I looked at the code but couldn't see anything that was causing this.

THIS modifies the block definition.

  • Like 1
Link to comment
Share on other sites

1 hour ago, ronjonp said:

THIS modifies the block definition.

I ended up using this. I did like the dialog Steven used to allow the selection of each attribute but I'd say 999/1000 I'd need this. 😛

Link to comment
Share on other sites

48 minutes ago, 3dwannab said:

I ended up using this. I did like the dialog Steven used to allow the selection of each attribute but I'd say 999/1000 I'd need this. 😛

👍

I updated the code above so ATTSYNC will only be called once per block name.

  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...