Need your help to insert a "setq" string during a text command :)

Need your help to insert a "setq" string during a text command :)

Anonymous
Not applicable
1,507 Views
4 Replies
Message 1 of 5

Need your help to insert a "setq" string during a text command :)

Anonymous
Not applicable

Hi everyone, first I'd like to apologize if my english is too bad for your eyes. Frenchy here, and I learned english by myself with video games so I sometimes have troubles to write correctly... ^^

 

I'm working on a routine to draw a line and half-circle around a text to indicate the level (height) of a user defined point.

The line and half-circle are now OK, but when I try to insert the text nothing is writing.

 

For now, there are no math in the lisp, I don't think I'll have trouble with this but I'd like to understand why the text command doesn't work corrrectly.

Here's my code, I hope you'll understand what I'm trying to do 🙂

(defun c:Altimetrie ()
  (setq st (getvar "TEXTSTYLE"))
  ;sauvegarde le style de texte courant
  (setq os (getvar "osmode"))
  ;mémorise les accroches aux objets définis par l'utilisateur
    (setvar 'osmode (+ 1 2 4 16 32 128 512 2048 4096))
;autorise les accrochages aux objets
  (command "_STYLE" "Standard" "" ""  "" "" "" "")
  ;définit le style de texte sur standard
  (setq pt1 (getpoint "\nCliquez sur le point de référence : "))
  ;Permet de définir le point servant de référence pour l'altimétrie
  (setq niv (getreal "\nQuelle est l'altimétrie de ce point ? <0.00>"))
  ;demande l'altimétrie à l'utilisateur et la mémorise
  (setq pt2 (getpoint "\nCliquez sur le point d'insertion : "))
  ;Permet de sélectionner le point d'insertion de l'indicateur d'altimétrie
  (setvar 'osmode 0)
  ;supprime les accrochages aux objets
  (setq txt (list (car pt2) (+ (cadr pt2) 10)))
  ;mémorise le point d'insertion du texte
  (setq pt3 (list (- (car pt2) 25) (cadr pt2)))
  ;mémorise l'extrémité gauche de la ligne et de l'arc de cercle
  (setq pt4 (list (+ (car pt2) 25) (cadr pt2)))
  ;mémorise l'extrémité droite de la ligne et de l'arc de cercle
  (command "_STYLE" st "" "" "" "" "" "")
  ;définit le style sur standard
  (command "_LINE" pt3 pt4 "")
  ;trace la ligne au niveau de l'altimétrie indiquée
  (command "_ARC" "c" pt2 pt4 pt3)
  ;trace un arc de cercle pour entourer l'altimétrie
   (command "_TEXT" "j" "bc" txt "15" "0" (strcat (rtos niv)) "")
  ;texte justifié bas-centre puis écrit la valeur de l'altimétrie - ne fonctionne pas
  (setvar 'osmode os)
  )

Any help is welcome, I'm at the beggining of my autolisp life 😃

0 Likes
Accepted solutions (3)
1,508 Views
4 Replies
Replies (4)
Message 2 of 5

chriscowgill7373
Advisor
Advisor
Accepted solution

 what doesnt work?  does it give you an error message?  or not do anything?

I would actually recommend using Visual Lisp to create a text entity instead of the text command.  It would run quicker than using a command.

(setq atext (vla-addtext
					   *acadmodelspace*
					   (strcat acar " Acres")
					   (vlax-3d-point
					     atextins
					   ) ;_ end of vlax-3d-point
					   (* 0.09 annoscale)
					 ) 
		)
	  

In this case, I had a string for acar that I was combining with acres, and a 3d point (the insertion point for atextins. the height was determined by my height times the current drawing annotation scale.  You could then use visual lisp to put justifications and other properties to the text entity.


Christopher T. Cowgill, P.E.

AutoCAD Certified Professional
Civil 3D Certified Professional
Civil 3D 2024 on Windows 10

Please select the Accept as Solution button if my post solves your issue or answers your question.

Message 3 of 5

Sea-Haven
Mentor
Mentor
Accepted solution

A suggestion

 

(setvar 'osmode 6839)

(setvar 'style "standard")

Your problem is more than likely the text style "standard" has the height set so when you set height it thinks its angle 1 less input.

(setq ts (cdr (assoc 40 (tblsearch "STYLE" (getvar "TEXTSTYLE")))))
      (if (zerop ts)
           (command "TEXT" "498,18" "3.5" "90" ans)
           (command "TEXT" "498,18" "90" ans)
       )  
Message 4 of 5

ВeekeeCZ
Consultant
Consultant
Accepted solution

Version without messing with variables. (command "TEXT") is too much affected by the current setting. (entmake) is not. 

 

(defun c:Altimetrie ( / pt1 niv pt2 pt3 pt4 ptt)

  (or *alt-niv*
      (setq *alt-niv* 0.))

  (if (and (setq pt1 (getpoint "\nCliquez sur le point de référence: "))
	   (setq niv (cond ((getdist (strcat "\nQuelle est l'altimétrie de ce point? <" (rtos *alt-niv* 2 2) ">: ")))
			   (*alt-niv*)))
	   (setq pt2 (getpoint pt1 "\nCliquez sur le point d'insertion: "))
	   )
    (progn
      (setq ptt (list (car pt2) (+ (cadr pt2) 10))
	    pt3 (list (- (car pt2) 25) (cadr pt2))
	    pt4 (list (+ (car pt2) 25) (cadr pt2)))
      (command "_.LINE" "_non" pt3 "_non" pt4 "")  		; 	non is the osmode temp-override
      (command "_.ARC" "_c" "_non" pt2 "_non" pt4 "_non" pt3)
      (entmake (list (cons 0 "TEXT")  ;; http://help.autodesk.com/view/ACD/2020/ENU/?guid=GUID-62E5383D-8A14-47B4-BFC4-35824CAE8363
		     (cons 10 ptt)
		     (cons 11 ptt)
		     (cons 40 15) 
		     (cons 72 1)
		     (cons 73 1)
		     (cons 1  (rtos niv 2 2))))))
  (princ)
  )
Message 5 of 5

Anonymous
Not applicable

Thanks a lot to all three for your help, I apologize for the time it took to answer I had a lot to do at home...

I found what was the matter in my code, the variable I tried to put in my text was a "getint", and because an integer isn't a string nothing happened x)

Yesterday at night, I found that using ITOA during the text command can do the trick, but I'm very interested about your solutions.

I wonder I can write a code like yours one day, thanks for the ;;tips to explain things to me

I don't know how vla works, but I'll take a look at it thanks !
 
 
 
 
 
 
 
 

Thanks again to all one more time, have a nice day/night/life/something else 😃

 

0 Likes