Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How can I change text height in the drawing and move objects with LISP?

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
Anonymous
2289 Views, 7 Replies

How can I change text height in the drawing and move objects with LISP?

Hello,

 

I have created a lisp which does some things, but I need to add a couple of things to fulfill it.

First, it renames some layers to desired names.
Second, It changes the color to them.
Third, it changes the standard text style to Arial.ttf.
Forth, it changes the style of the points.
Fifth, asks the user in which scale is working. 200 or 500?
Sixth, is changing the size of the point style, according to the typing scale.

 

I want to do two more things. The first is when the used type the scale to do

 

1. If the scale is 200 --> make all text heights of the drawing 0.24, else
if the scale is 500 --> make all text heights of the drawing 0.60


and

 

2. If the scale is 200 --> Objects in layer "TR_LAYER" to move (x,y,z)=(0.6,1.5,0)
                                     Objects in layer "TR_ELEVATION" to move (x,y,z)=(0.6,2.5,0)

    If the scale is 500 --> Objects in layer "TR_LAYER" to move (x,y,z)=(0.7,1.5,0)
                                     Objects in layer "TR_ELEVATION" to move (x,y,z)=(0.7,2.0,0)

 

Is it possible? I am attaching you my lisp until now....

 

(defun c:doit ()
; Μετονομασία layer Rename layer
(command "._rename" "la" "PUNTI" "TR_POINTS")
(command "._rename" "la" "CODICEPUNTO" "TR_LABELS")
(command "._rename" "la" "QUOTAPUNTO" "TR_ELEVATION")

 

; Ορισμός χρώματος για τα layer Color change
(command "_.layer" "_color" 9 "TR_POINTS" "")
(command "_.layer" "_color" 3 "TR_LABELS" "")
(command "_.layer" "_color" 9 "TR_ELEVATION" "")

 

; Αλλαγή style Text style change
(command "_STYLE" "Standard" "Arial.ttf" "" "" "" "" "")

 

; Αλλαγή σχεδίου στο σημείοPoint style change
(setvar 'pdmode 3)
(setvar 'pdsize 1)

 

; Επιλογή σχεδίου Choosing scale
(setq x (getint "Τι κλίμακα είναι το σχέδιο; 200 ή 500;"))

 

; Αλλαγή point style Point style change
(if (= x 200) (setvar 'pdsize 0.02) (setvar 'pdsize 0.05))

(princ)
)
(princ)

7 REPLIES 7
Message 2 of 8
Kent1Cooper
in reply to: Anonymous

For the Point size, consider using a negative number, which will make Points a certain percentage of the screen size, and won't care what scale you are using -- one setting for all scales.  As you Zoom in or out, you need to REGEN to change them, but with that, all Points will appear the same size on-screen no matter what the scale or Zoom level.

 

For the Text height, put the STYLE command after  the selection of the scale, and do this:

 

(command "_STYLE" "Standard" "Arial.ttf" (* 0.0012 x) "" "" "" "")

 

That will cover you for either scale.

 

The Moving can be done something like this [untested]:

 

(command

  "_.move" (ssget "_X" '((8 . "TR_LAYER"))) ""

    (list (if (= x 200) 0.6 0.7) 1.5 0.0) ""

  "_.move" (ssget "_X" '((8 . "TR_ELEVATION"))) ""

    (list (if (= x 200) 0.6 0.7) (if (= x 200) 2.5 2.0) 0.0) ""

)

 

If there are objects on those Layers in different spaces, the above will "see" [in object selection in the Move commands] only those in the current space.  So if you want to Move them in different spaces, something would have to be done to switch to each space in which they occur to Move them, or their positions would have to be adjusted by entity data manipulation [much more complicated because it has to be done differently for different kinds of objects].

Kent Cooper, AIA
Message 3 of 8
Anonymous
in reply to: Kent1Cooper

Thank you very much for your feedback.

 

As far as for the point size, I code it to "Set Size in Absolute Units" and it really does what I wanted to do.

 

I knew, after a lot of studying on the matter, how to make all text heights of the drawing that are in the "Standard" style, to change according to the typed scale. 

The thing is that I want to change from the text properties and not from the style "Standard". I don't know how possible is this, and I find some really complicated articles.

 

I am very satisfied with the move command, it worked perfectly and thank you very much for helping me. I haven't encountered any problem.

 

(I also wrote wrong a layer... "TR_LAYER" was "TR_LABELS", but it is ok, I fixed the problem when I studied your code.)

 

 

Message 4 of 8
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:
....
1. If the scale is 200 --> make all text heights of the drawing 0.24, else
if the scale is 500 --> make all text heights of the drawing 0.60
....

.... I want to change from the text properties and not from the style "Standard". ....


By "all text heights," do you mean the height of all Text objects only [that would be easy], or would you want to also change the height in Mtext objects, Dimension text content, Multileader text content, etc.?

Kent Cooper, AIA
Message 5 of 8
Anonymous
in reply to: Anonymous

Only text objects. The only things that the drawing has are texts and points. Nothing else.
Message 6 of 8
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:
Only text objects. The only things that the drawing has are texts and points. Nothing else.

Try this again, after  the scale has been chosen]:

 

  (setq ss (ssget "_X" '((0 . "TEXT"))))
  (repeat (setq n (sslength ss))
    (vla-put-Height
      (vlax-ename->vla-object (ssname ss (setq n (1- n))))
      (* 0.0012 x)
    )
  )

Kent Cooper, AIA
Message 7 of 8
Anonymous
in reply to: Kent1Cooper

It gives me the following error:

 

; error: no function definition: VLAX-ENAME->VLA-OBJECT

 

What should I do, in order to work properly?

Message 8 of 8
Kent1Cooper
in reply to: Anonymous

Add this line at the very beginning or very end of the code:

(vl-load-com)

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report