View Full Version : Help - Rotation angle of text
fclao
2008-12-05, 04:44 AM
Is there a variable for current rotation angle of text? I'm writing a routine that needs to get that.
Thanks in advance!!
irneb
2008-12-05, 06:46 AM
It doesn't seem to be a sysvar. I've even run a sysvar-reactor to check what changes if the user specifies a new angle. None of the sysvars listed from this reactor, have anything to do with rotation. So, all I can think this is, is an undocumented global variable (not sysvar, more like a lisp variable, but probably in the ARX).
ccowgill
2008-12-05, 02:13 PM
Is there a variable for current rotation angle of text? I'm writing a routine that needs to get that.
Thanks in advance!!if you are selecting a piece of text, you can use vla-get-rotation to get the rotation of the selected text. you must convert the ename to vla-object and also must have (vl-load-com) somewhere in your routines loaded before this routine runs.
irneb
2008-12-06, 01:57 PM
if you are selecting a piece of text, you can use vla-get-rotation to get the rotation of the selected text. you must convert the ename to vla-object and also must have (vl-load-com) somewhere in your routines loaded before this routine runs.Yep, you can obtain a specific text's rotation that way, or even just through (cdr (assoc 50 data)) - where data is got fron (entget ename).
But, the OP wants to know what that current default rotation is. You know, the value shown at the command prompt when you place a new text. This is always the same as the last text you placed. So maybe if there was an entprev function, you could get the last entity with entlast, then step backwards until you reach a text entity & get its rotation. Unfortunately, I know of no function to get a previous entity in the drawing's database like entnext does. And starting from (entnext) to get the 1st entity, and go through the entire DWG until you reach the last TEXT, is probably very inefficient.
fclao
2008-12-08, 05:21 AM
Yep, you can obtain a specific text's rotation that way, or even just through (cdr (assoc 50 data)) - where data is got fron (entget ename).
But, the OP wants to know what that current default rotation is. You know, the value shown at the command prompt when you place a new text. This is always the same as the last text you placed. So maybe if there was an entprev function, you could get the last entity with entlast, then step backwards until you reach a text entity & get its rotation. Unfortunately, I know of no function to get a previous entity in the drawing's database like entnext does. And starting from (entnext) to get the 1st entity, and go through the entire DWG until you reach the last TEXT, is probably very inefficient.
I'm not selecting text, but need to get the last rotation angle. Before running my routine, and use the previous setting to reset it back, as the routine terminates.
I'm considering to terminate the routine with setting the rotation angle to 0, by running a text command with 0 rotation and blank text. This might be a better option, since most of our text are usually done at 0 angle.
Thanks
cadtag
2008-12-10, 04:02 PM
Unfortunately, I know of no function to get a previous entity in the drawing's database like entnext does.
Handles are created sequentially as entities are created -- you may want to look into that to generate an (entprev) function..
irneb
2008-12-10, 04:19 PM
Handles are created sequentially as entities are created -- you may want to look into that to generate an (entprev) function..Now that's an idea! To change the hexadecimal handle string to an integer, decrement it, change it back to hexadecimal & use handent! Brilliant!
So this is how it would look:(defun entprev (en / ed h)
(if (not en) ;Act as exact mirror function to entnext
(setq en (entlast))
) ;_ end of if
(setq ed (entget en)) ;Get entity's data
(setq h (cdr (assoc 5 ed))) ;Get entity's handle
(setq h (1- (dec h))) ;Decrement handle
(while (and (> h 0) (not (setq en (handent (hex h))))) ;Get calculated ename from handle
(setq h (hex (1- (dec h)))) ;Decrement handle
) ;_ end of while
en ;Return calculated entity
) ;_ end of defun
To run this code you'll also need the conversion functions as per 'Gile's code here (http://forums.augi.com/showthread.php?t=90683).
irneb
2008-12-10, 04:59 PM
Scratch that code ... just tried it on one of my DWGs. Here's a text screen of my testing:Command: (setq en (entnext))
<Entity name: 7eaa5738>
Command: (while en (print (setq en (entprev en))) (setq ed (entget en)) (prin1
(assoc 5 ed)))
<Entity name: 7eaa5730> (5 . "3F9E")
<Entity name: 7eaa5728> (5 . "3F9D")
<Entity name: 7eaa5720> (5 . "3F9C")
<Entity name: 7eaa5718> (5 . "3F9B")
<Entity name: 7eaa5710> (5 . "3F9A")
<Entity name: 7eaa5708> (5 . "3F99")
<Entity name: 7eaa5700> (5 . "3F98")
<Entity name: 7eaa56f8> (5 . "3F97")
<Entity name: 7eaa56f0> (5 . "3F96")
<Entity name: 7eaa56e8> (5 . "3F95")
<Entity name: 7eaa56e0> (5 . "3F94")
<Entity name: 7eaa56d8> (5 . "3F93")
<Entity name: 7eaa56d0> (5 . "3F92")
<Entity name: 7eaa56c8> (5 . "3F91")
<Entity name: 7eaa56c0> (5 . "3F90")
<Entity name: 7eaa56b8> (5 . "3F8F"); error: bad argument type: stringp 16270
Command: (setq en (handent "3F8F"))
<Entity name: 7eaa56b8>
Command: (setq ed (entget en))
((-1 . <Entity name: 7eaa56b8>) (0 . "LINE") (330 . <Entity name: 7688cc10>) (5
. "3F8F") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "AR_ABOVE") (100 .
"AcDbLine") (10 44187.0 10165.0 0.0) (11 35610.0 32.0008 0.0) (210 0.0 0.0 1.0))
So it still finds entities earlier than the 1st found by (entnext), and then gives an error :?. WTF? Is it then untrue that handles are sequencial ... I've also noticed handles sometimes skip a few "numbers" - that's why I've added the while statement in the entprev function (that's possibly because of deleted entities).
Could it have been that the object with the handle of 3F8E had been previously deleted?
irneb
2008-12-10, 05:14 PM
Could it have been that the object with the handle of 3F8E had been previously deleted?Sorry, yes - I was editing my post to add that! But the Line entity in my test code is an existing line (not deleted):(
Where your posted code crashed was on the next entity having hex number "3F8E" or decimal number of 16270 and not "3F8F" as you have displayed.
I have run your code on a new drawing of just lines, 6 total. It started at the second to last object and went all the way back to the beginning, displaying the results of 5 items. This is one less since you have to start with at least one entity for your while loop.
irneb
2008-12-10, 05:50 PM
Ok, so in most instances this code should work correctly (you're saying?) I've also tested this on a new drawing, and found the same as you. So I guess it's not as bad as I thought?
I'm just a bit skeptical that it found lines before the "supposedly" first entity in my DWG (which has about 43000 entities and was worked on for the last year). Maybe my example DWG has some corruption that AUDIT couldn't find ???? :eek:
Anyhow ... this might just allow the OP's request to work ... I'll look into it on Friday as I'm flying to site tomorrow (won't be @ a PC).
kennet.sjoberg
2008-12-11, 07:39 PM
I think OP is asking for the value in the text command
Specify rotation angle of text <0.00000>:
and not a rotation of a text object
That value is always <0.00000> when open a drawing, even if you created a text object with an angle in previous session.
So to create an "empty" text is a good (and bad if not removed ) idea
here is a function to set the value to 0
(defun TextAngle0 ( / LastEnt )
(setq LastEnt (entlast) )
(command "._text" "0,0" "" 0 "MyDummyTExt" )
(if (eq LastEnt (entlast) ) ; Prevent the function from erasing wrong object
( )
(command "._erase" (entlast) "" )
)
(princ)
)
usage
(TextAngle0)
: ) Happy Computing !
kennet
irneb
2008-12-12, 07:16 AM
Ahhh ... there goes kennet again ... thinking out the box! Much simpler solution, thanks kennet ...
So here's what you'd want to use:(defun TextAngle0 ( / TxtStl LastEnt return)
(setq LastEnt (entlast)) ;Get the last entity to check
(setq TxtStl (tblsearch "STYLE" (getvar "TEXTSTYLE"))) ;Get the current Text Style
(if (> (cdr (assoc 40 TxtStl)) 0.0) ;Check if style has height
(command "._text" "0,0" "" "MyDummyTExt") ;Create dummy without specifying height
(command "._text" "0,0" "" "" "MyDummyTExt") ;Create dummy with specifying height
)
(if (eq LastEnt (entlast)) ; Prevent the function from erasing wrong object
(setq return nil) ;If text not last return nil
(progn
(setq LastEnt (entget (entlast))) ;Get dummy text's data
(setq return (cdr (assoc 50 LastEnt))) ;Get rotation angle of text
(entdel (entlast)) ;Delete the text without issuing command
)
)
return ;Return the value
)Please note this returns the angle in radians. If you want to convert to degrees, you could use the example in help file:; Convert value in radians to degrees
(defun Radian->Degrees (nbrOfRadians)
(* 180.0 (/ nbrOfRadians pi))
)
kennet.sjoberg
2008-12-12, 09:48 AM
Ahhh ... there goes kennet again ... thinking out the box! Much simpler solution, thanks kennet ...
(defun CTAng ( AngleType / LastEnt LastAng ) ; Current Text Angle
(setq LastEnt (entlast) )
(command "._text" "0,0" "" "" "MyDummyText" )
(if (eq LastEnt (entlast) ) ; Prevent the function from erasing wrong object
( )
(progn
(cond
((= (strcase AngleType nil ) "D" ) (setq LastAng (* (/ (cdr (assoc 50 (entget (entlast)))) PI ) 180 )) )
((= (strcase AngleType nil ) "R" ) (setq LastAng (cdr (assoc 50 (entget (entlast))))) )
(t nil) ; invalid argument input to the function, valid argument is "D" "d" "R" and "r"
)
(command "._erase" (entlast) "" )
)
)
LastAng
)
Usage :
(CTAng "D" ) or (CTAng "R" )
: ) Happy Computing !
kennet
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.