Jump to content

Lisp to change text height


CADNADIAN

Recommended Posts

Is there a lisp to simply change the height of a specific text in a layer?

 

I wrote this so far, but having troubles.

 

(defun C:CommandName ()

 (command "_.chprop"

   (ssget "_X" '((8 . "layer1")))

   "" ; complete selection

   "_ht" 1.5

   ""); (princ)

it asks to change the general properties and not the properties i want to change.

Edited by rkmcswain
added [CODE] tags
Link to comment
Share on other sites

*not thoroughly tested*

(defun c:test ( / entx ht i ss)
 (setq ht (getint "\nSpecify Text Height:"))
(if (setq ss (ssget "_:L" '((-4 . "<and") (0 . "TEXT,MTEXT") (8 . "layer1") (-4 . "and>") ))) ;; Change "_X" to "_:L" to choose selected items
 (repeat (setq i (sslength ss))
   (setq i (1- i))
   (setq entx (entget(ssname ss i)))
   (entmod (subst (cons 40 ht) (assoc 40 entx) entx))
 )
 (princ "\No Text items on Layer1 Found")
 )
 (princ)
)

Link to comment
Share on other sites

<... '((-4 . "<and") (0 . "TEXT,MTEXT") (8 . "layer1") (-4 . "and>")) ...>

 

FWIW, note that the ssget filter list uses an implicit AND logic, meaning that the operators in your example are redundant.

Link to comment
Share on other sites

Hi Lee,

Can you give an example when operators are needed? I can't figure this out.

 

As for the OP's question, another option that would differ from Happy Hobbit's code would be a selection of source text/mtext entity.

Link to comment
Share on other sites

 

Ahh, thanks!

I get it now.. when different entities must be filtered by their specific properties - like circles with specific radius-R1 and arcs with specific radius-R2 (from your example).

I never had to use it, but I think it would be useful for style filtering (dimstyles, tstyles, mleaderstyles... etc - all in one).

Link to comment
Share on other sites

*not thoroughly tested*

(defun c:test ( / entx ht i ss)
 (setq ht (getint "\nSpecify Text Height:"))
(if (setq ss (ssget "_:L" '((-4 . "<and") (0 . "TEXT,MTEXT") (8 . "layer1") (-4 . "and>") ))) ;; Change "_X" to "_:L" to choose selected items
 (repeat (setq i (sslength ss))
   (setq i (1- i))
   (setq entx (entget(ssname ss i)))
   (entmod (subst (cons 40 ht) (assoc 40 entx) entx))
 )
 (princ "\No Text items on Layer1 Found")
 )
 (princ)
)

 

 

Thank you so very much hobbit!

 

It appears that the method of this routine prompts a selection of text from the user (select object)- and modifies the text based on another prompt (specify text height). Is there a way to simply have zero user interaction? By this i mean, if my company has a standard size of text that i want my text layer to be changed to without typing anything.

 

Thats why i used the SSGET route

Link to comment
Share on other sites

Simple changes

 

; changes
(defun c:text4 ( / entx ht i ss)
(setq ht 4)
; rest the same

 

Also no code verision

FILTER TEXT APPLY then PROPERtIES text height 4

Link to comment
Share on other sites

Alternatively:

 

Change

 (cons 40 [color="red"]ht[/color]) 

to

 (cons 40 [color="red"]4[/color]) 

 

Delete this line:

 [color="red"](setq ht (getint "\nSpecify Text Height:"))[/color] 

 

Remove ht from this:

 ( / entx[color="red"] ht [/color]i ss) 

 

Hello BIGAL what do you mean by code version?

 

 

*EDIT*

 

Best change this as well:

'((-4 . "<and") (0 . "TEXT,MTEXT") (8 . "layer1") (-4 . "and>"))

to

'((0 . "TEXT,MTEXT") (8 . "layer1"))

 

On the advice of Lee Mac.What he doesn't know about Autolisp isn't worth knowing!

Link to comment
Share on other sites

Alternatively:

 

Change

 (cons 40 [color=red]ht[/color]) 

to

 (cons 40 [color=red]4[/color]) 

Delete this line:

 [color=red](setq ht (getint "\nSpecify Text Height:"))[/color] 

Remove ht from this:

 ( / entx[color=red] ht [/color]i ss) 

Hello BIGAL what do you mean by code version?

 

 

*EDIT*

 

Best change this as well:

'((-4 . "<and") (0 . "TEXT,MTEXT") (8 . "layer1") (-4 . "and>"))

to

'((0 . "TEXT,MTEXT") (8 . "layer1"))

On the advice of Lee Mac.What he doesn't know about Autolisp isn't worth knowing!

 

 

Did you guys actually test this ?

 

Its not working on my end. It cant even "appload" for some reason

 

I think what BIGAL meant by "no code version" is that "text height" is a property that requires user interaction to edit, even when using a lisp routine.

Link to comment
Share on other sites

I just shuffled it around a bit, but it works for me:

 

(defun c:test (/ ss i ed)

   (if (setq ss (ssget "_X" '((0 . "TEXT") (8 . "layer1"))))
       (progn
           (setq i 0)
           (repeat (sslength ss)
               (setq ed (entget (ssname ss i))
                     i (1+ i)
                     ed (subst (cons 40 4.0) (assoc 40 ed) ed)
               )
               (entmod ed)
            )
        )
   )
   (princ)
)

Link to comment
Share on other sites

  • 3 weeks later...

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...