Jump to content

Recommended Posts

Posted

hello all:

I use a code that aligns a text with a line

The problem is that sometimes I need to rotate the text 180 degrees

I would like to modify this routine

so that when you rotate the text you have the option to rotate it 180 or exit if it is the correct angle

image.thumb.png.3eaaa6f8dd0fd4992dbc0d00d8934c7a.png

 

here code.

defun c:TY (/)
   (setq old_err *error*)
  (defun *error* (a /)
    (princ "")
    (setq *error* old_err)
    (princ)
  )
  (setvar "cmdecho" 0)
  (vl-load-com)
  (setq	VlaObjLine
	 (vlax-ename->vla-object
	   (car (entsel "Selecciona una linea : "))
	 )
  )
  (setq LinAngle (vla-get-Angle VlaObjLine))
  (while (setq VlaObjText
		(vlax-ename->vla-object
		  (car (entsel "Selecciona un texto : "))
		)
	 )
    (vla-put-Rotation VlaObjText LinAngle)
    (vlax-release-object VlaObjText)
  )
  (vlax-release-object VlaObjLine)
  (setvar "cmdecho" 1)
   (princ)

  );fin defun


thanks


 

 

Posted

Hi
Maybe it's better to solve the problem from scratch. Below '(setq LinAngle...)' write:

(if (and (< LinAngle 4.71239) (> LinAngle 1.5708))
  (setq LinAngle (+ LinAngle PI))
)

 

Posted

Note: It doesn't matter if 'LinAngle' exceeds 2PI, AutoCAD takes care of subtracting the excess

  • Thanks 1
Posted (edited)

But if for some reason you want to keep the current behavior and change the orientation at the end, the code could be like this:

 

(defun c:TY (/)
  (setq old_err *error*)
  (defun *error* (a /)
    (princ "")
    (setq *error* old_err)
    (princ)
  )
  (setvar "cmdecho" 0)
  (vl-load-com)
  (setq	VlaObjLine
	 (vlax-ename->vla-object
	   (car (entsel "Selecciona una linea : "))
	 )
  )
  (setq LinAngle (vla-get-Angle VlaObjLine))
;;;  (if (and (< LinAngle 4.71239) (> LinAngle 1.5708))
;;;    (setq LinAngle (+ LinAngle PI))
;;;  )
  (while (setq VlaObjText
		(vlax-ename->vla-object
		  (car (entsel "Selecciona un texto : "))
		)
	 )
    (vla-put-Rotation VlaObjText LinAngle)
    (while (not (member (setq cambiar? (strcase (getstring "\n¿Rotar el texto?  <No>/Si: "))) '("" "N" "NO" "S" "SI")))
      (princ "\nOpcion seleccionada no valida. Repite, por favor...")
    )
    (if (member cambiar? '("S" "SI"))
      (vla-put-Rotation VlaObjText (+ LinAngle PI))
    )
    (vlax-release-object VlaObjText)
  )
  (vlax-release-object VlaObjLine)
  (setvar "cmdecho" 1)
  
  (princ)

)

 

Edited by GLAVCVS
  • Thanks 1

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