recurrent text insertions using lisp code

recurrent text insertions using lisp code

GeryKnee
Advocate Advocate
897 Views
12 Replies
Message 1 of 13

recurrent text insertions using lisp code

GeryKnee
Advocate
Advocate

Command "TEXT" typed in autocad command line window, first is asking Justification, Insertion point , height and rotation , and then , in a loop terminating using ESC , asks with prompt "Enter text:" the text values, creating text objects , the next bellow the previous.

I want just to give the insertion point.

So I wrote the following

(defun c:MyTextCommand () ;;
(if
(setq pt (getpoint "\nSpecify point for first text instance: "))
(
(command "TEXT" "J" "MC" pt 1.00 0.00 )
)
)
)
)

But now there's not loop ex by prompting "Enter text:" but returns to command prompt.

How should this work as when typed "TEXT" command?

Thanks,

Gery,

0 Likes
Accepted solutions (2)
898 Views
12 Replies
Replies (12)
Message 2 of 13

ВeekeeCZ
Consultant
Consultant
Accepted solution

Couldn't figure out any simpler way at the moment

 

(vl-load-com)

(defun c:MyTextCommand ( / p)
  (if (setq p (getpoint "\nSpecify middle text point for first text instance: "))
    (vla-sendcommand (vla-get-activedocument (vlax-get-acad-object))
      (strcat "text\rmc\rnon\r" (rtos (car p) 2 9) "," (rtos (cadr p) 2 9) "\r1\r0\r")))
  (princ)
  )

 

Message 3 of 13

Moshe-A
Mentor
Mentor

@GeryKnee  hi,

 

replace TEXT command with DTEXT command

 

cheers

Moshe

Message 4 of 13

Kent1Cooper
Consultant
Consultant

You have extraneous parentheses [at least the left parenthesis on its own line above the (command ...) line, and presumably its right parenthesis mate -- maybe more].

 

By the way, you don't need to specify the "J" for justification before giving it one -- you can just put in the justification there, directly.  And you don't need the height and rotation specified every time.

 

I'm not really sure what you're asking, but if it is to continually give another insertion point [that is, not have each Text object below the previous one], and only supply the text content for each, does this do what you want?

 

(defun c:MyTextCommand (/ pt)
  (command "_.text" "_mc" pause 1 0 (getstring T))

  (while (setq pt (getpoint "\nInsertion point for next instance: "))
    (command "_.TEXT" "_mc" pt "" "" (getstring T))
  )

  (princ)

)

Kent Cooper, AIA
Message 5 of 13

GeryKnee
Advocate
Advocate

Hi Sir,

I want to enter noumerous of texts, the next below the previous, using all the other needed parameters (justification rotation texthight and positioning) as started in the first object. Your code is good and helps as second case if you want to give and an individual position for every object the code created.

Thanks,

Gery

0 Likes
Message 6 of 13

Kent1Cooper
Consultant
Consultant

@GeryKnee wrote:

I want to enter noumerous of texts, the next below the previous, using all the other needed parameters (justification rotation texthight and positioning) as started in the first object. ....


You don't need any routine to do that.  The regular TEXT command works just that way.  Just hit Enter at the end of the first line, and it moves down to do a next line below, until you hit Enter twice to end it.  Or am I missing something?

Kent Cooper, AIA
0 Likes
Message 7 of 13

ВeekeeCZ
Consultant
Consultant
Accepted solution

@GeryKnee 

 

do not ignore @Moshe-A 's suggestion, DTEXT is a neat trick. That way the code could be simplified to just a single line.

 

(defun c:MyTextCommand ()
  (command "_.DTEXT" "_MC" pause 1. 0. )
  (princ)
  )

 

Message 8 of 13

GeryKnee
Advocate
Advocate

So,

The following is a solution with Text Height and Text Rotation parameterized :

(defun c:MyTextCommand ()

;;;;; here calculated TxtH and TxtR 
(command "_.DTEXT" "_MC" pause (rtos TxtH 2 2) (rtos TxtR 2 2) )
(princ)
)

Thank you very much Sir,

Gery

Message 9 of 13

GeryKnee
Advocate
Advocate

Yes, that's true

But TextHight is a parameter calculated from userI1 system Var.

In my Code is the following :

 

 

......

(setq us1 (getvar "USERI1" ))


(setq scaleID(rem us1 21))
;;(xW scaleID)
(setq Scale (cond
((= scaleID 00)000200)
((= scaleID 01)000100)
((= scaleID 02)000050)
((= scaleID 03)000250)
((= scaleID 05)000500)
((= scaleID 06)000750)
((= scaleID 07)000300)
((= scaleID 08)001000)
((= scaleID 09)002000)
((= scaleID 10)005000)
((= scaleID 11)002500)
((= scaleID 12)010000)
((= scaleID 13)015000)
((= scaleID 14)020000)
((= scaleID 15)025000)
((= scaleID 17)030000)
((= scaleID 18)040000)
((= scaleID 19)050000)
((= scaleID 20)100000)
(T 000200)
)
)

................


(setq TxtH(* 0.006 Scale))
(setq TxtR 0.00)

 

So, I needed to use the "TEXT" command but not set some parameters as Justify,TextHeight etc allways giving the same values or calvulating each value.

Additionaly , If the coordinates of the position where text put could be get the model space display center , sould be better because after the texts are created , will be replaced and the first text position is OK on screen center. Is there a way to define coordinates of the display center?

Thanks,

Gery.

 

 

0 Likes
Message 10 of 13

Kent1Cooper
Consultant
Consultant

@GeryKnee wrote:

.... Is there a way to define coordinates of the display center? ....


It's the VIEWCTR System Variable.

Kent Cooper, AIA
0 Likes
Message 11 of 13

paullimapa
Mentor
Mentor

Like @Kent1Cooper replied use: 

(getvar"viewctr")


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 12 of 13

Kent1Cooper
Consultant
Consultant

@GeryKnee wrote:

....

(command "_.DTEXT" "_MC" pause (rtos TxtH 2 2) (rtos TxtR 2 2) )
....


You really don't need to convert those calculated values to text strings -- the command will accept them as numbers.  Try simply:

(command "_.DTEXT" "_MC" pause TxtH TxtR)

Kent Cooper, AIA
Message 13 of 13

Kent1Cooper
Consultant
Consultant

@GeryKnee wrote:

....

(setq Scale (cond

((= scaleID 00)000200)
((= scaleID 01)000100)
....

((= scaleID 20)100000)
(T 000200)

....


I'm also curious about all those myriad leading zeros that are doing nothing for you.  In addition to eliminating those, you can eliminate the need to spell out ((= scaleID 19 times for every possible value, by using an association list:

 

(setq Scale
  (cond
    ((cadr
       (assoc scaleID
          '((0 200) (1 100) (2 50) (3 250) (5 500) (6 750) (7 300) (8 1000)
          (9 2000) (10 5000) (11 2500) (12 10000) (13 15000) (14 20000)
          (15 25000) (17 30000) (18 40000) (19 50000) (20 100000))
        ); assoc
      ); cadr
    ); association-list condition
    (200); no sublist starting with scaleID value
  ); cond
); setq​

 

[Note also the (200) at the end.  The T is needed as a condition test only if there are multiple functions to run in the none-of-the-above condition.  If there's only one function or value, it can be the condition on its own, and its value will be passed by the enclosing (cond) function.]

Kent Cooper, AIA