Jump to content

Multiple Text Entity Rotate by each entity insertion point, make visible in PLAN.


chris2012

Recommended Posts

I am looking to rotate multiple text entities about their own individual insertion points to an orientation legible in plan view. This is not a simple matter of changing the angle of rotation as this rotates about the wrong axis (and of course multiple items)!

Through experimenting with dxf codes I have established that if codes 210,220 and 230 are set to 0,0,1 then this does achieve the desired result.

i.e.

(210 0.0) (220 0.0) (230 1.0)

 

The reason I am doing this is to format text output from another drawing package.

 

I have found and am trying to modify the attached Lee Mac "change colour" lisp to achieve the result highlighted above and would be greatful for any help from the collective on this. Note that I alighted on this code as it adds the desired entities if they do not originally exist.

 

Thanks in advance for any help \ pointers

 

Chris

 

(defun c:doit (/ i ss ent eLst)
(if (setq i -1 ss (ssget "_:L"))
(while (setq ent (ssname ss (setq i (1+ i))))
(setq eLst (entget ent))

(setq eLst (subst '(8 . "0") (assoc 8 eLst) eLst))
(entmod
(if (assoc 62 eLst)
(subst '(62 . 3) (assoc 62 eLst) eLst)
(append eLst '((62 . 3)))))))
(princ))

Edited by SLW210
Added Code Tags!!
Link to comment
Share on other sites

snapshot.jpglightning fast Alan thanks. I have had a look at your link but this is not what I'm after. Have posted a screen grab to show the orientation of text.
Link to comment
Share on other sites

Alan

 

Thanks for this, I have had a detailed look at your lisp and (as I understand it) it appears excellent at addressing the rotation variable (code 50) associated with an entity, however it does not appear to address the rotation about the other two axis. In aircraft jargon if rotation could be thought of as roll, the rotations I am interested in are pitch and yaw. I don't suppose you would be interested in updating your code to account for this?????:unsure:

 

Chris

Link to comment
Share on other sites

Hi Chris,

 

I may have misunderstood your requirements, but the following code will alter the DXF 210 normal vector to that of the WCS plane (0,0,1) for a set of Text objects, whilst tranforming the insertion points to their equivalent positions relative to the WCS plane (since Text insertion points are expressed in OCS):

(defun c:txt2plan ( / e i s )
   (if (setq s (ssget "_:L" '((0 . "TEXT"))))
       (repeat (setq i (sslength s))
           (setq e (entget (ssname s (setq i (1- i))))
                 e (subst '(210 0.0 0.0 1.0) (assoc 210 e) e)
           )
           (entmod e)
       )
   )
   (princ)
)

This second program will alter the normal vector however will retain the original insertion point positions:

(defun c:txt2plan ( / e i s )
   (if (setq s (ssget "_:L" '((0 . "TEXT"))))
       (repeat (setq i (sslength s))
           (setq e (entget (ssname s (setq i (1- i))))
                 e (subst '(210 0.0 0.0 1.0) (assoc 210 e) e)
                 e (subst  (cons 10 (trans (cdr (assoc 10 e)) (cdr (assoc -1 e)) 0)) (assoc 10 e) e)
                 e (subst  (cons 11 (trans (cdr (assoc 11 e)) (cdr (assoc -1 e)) 0)) (assoc 11 e) e)
           )
           (entmod e)
       )
   )
   (princ)
)

Link to comment
Share on other sites

Excellent job Lee, thanking you :D! The second program works just great.

For the icing on the cake (and with reference to the screen grab above what would be really excellent if the text could be rotated around the line going through it.

i.e. the blue text (beams) would be rotated about the blue line (x direction) so it is visible when looking down from the z direction.

the red text (columns) should be set to 45 degrees on plan but I can manage this from what you have given me.

If you could afford any more time with this it would be brilliant!

 

Chris

Link to comment
Share on other sites

Lee

 

From a review of dxfs created by using your second lisp program, I have identifed that if (cons 50) is set to

[90 degrees + (ACOS (cons 210) x 180/pi)] then the text will flip up as desired. (Where cons 210 is the original value of cons 210.)

Any chance of a mod to accomodate this?

 

Chris

Edited by chris2012
elaboration \ clarification
Link to comment
Share on other sites

Sorry for the delay; been at the dentist and at lunch. Good to see that Lee got you sorted.

thanks for your input Alan

Link to comment
Share on other sites

I have identifed that if (cons 50) is set to

[90 degrees + (ACOS (cons 210) x 180/pi)] then the text will flip up as desired. (Where cons 210 is the original value of cons 210.)

 

In the drawing database, DXF Group 210 is a 3D normal vector expressed in WCS, not a single numerical value as it appears in the source code for a DXF file.

 

However, given that you are referring to the x-coordinate of this vector, the following program implements your requested modification:

 

(defun c:txt2plan ( / e i s )
   (if (setq s (ssget "_:L" '((0 . "TEXT"))))
       (repeat (setq i (sslength s))
           (setq e (entget (ssname s (setq i (1- i))))
                 e (subst  (cons 50 (+ (/ pi 2.0) (acos (cadr (assoc 210 e))))) (assoc 50 e) e)
                 e (subst '(210 0.0 0.0 1.0) (assoc 210 e) e)
                 e (subst  (cons 10 (trans (cdr (assoc 10 e)) (cdr (assoc -1 e)) 0)) (assoc 10 e) e)
                 e (subst  (cons 11 (trans (cdr (assoc 11 e)) (cdr (assoc -1 e)) 0)) (assoc 11 e) e)
           )
           (entmod e)
       )
   )
   (princ)
)

;; ArcCosine  -  Lee Mac
;; Args: -1 <= x <= 1

(defun acos ( x )
   (if (<= -1.0 x 1.0)
       (atan (sqrt (- 1.0 (* x x))) x)
   )
)

(princ)

acos from here.

Link to comment
Share on other sites

In the drawing database, DXF Group 210 is a 3D normal vector expressed in WCS, not a single numerical value as it appears in the source code for a DXF file.

 

However, given that you are referring to the x-coordinate of this vector, the following program implements your requested modification:

 

(defun c:txt2plan ( / e i s )
(if (setq s (ssget "_:L" '((0 . "TEXT"))))
(repeat (setq i (sslength s))
(setq e (entget (ssname s (setq i (1- i))))
e (subst (cons 50 (+ (/ pi 2.0) (acos (cadr (assoc 210 e))))) (assoc 50 e) e)
e (subst '(210 0.0 0.0 1.0) (assoc 210 e) e)
e (subst (cons 10 (trans (cdr (assoc 10 e)) (cdr (assoc -1 e)) 0)) (assoc 10 e) e)
e (subst (cons 11 (trans (cdr (assoc 11 e)) (cdr (assoc -1 e)) 0)) (assoc 11 e) e)
)
(entmod e)
)
)
(princ)
)

;; ArcCosine - Lee Mac
;; Args: -1 <= x <= 1

(defun acos ( x )
(if (<= -1.0 x 1.0)
(atan (sqrt (- 1.0 (* x x))) x)
)
)

(princ)

acos from here.

 

Lee this is great.

 

One final modification. Works 50% of the time. If the 220 vector component is negative then the rotation angle should be set at 180 deg minus the currently calculated angle.

Any chance a last tweak?

 

Chris

Edited by chris2012
clarity
Link to comment
Share on other sites

Lee

 

Turns out the plus sign in the following line should reflect the sign of the 220 component

 

(/ "220" (abs("220")))

 

e (subst (cons 50 (+ (/ pi 2.0) (acos (cadr (assoc 210 e))))) (assoc 50 e) e)

 

Chris

Link to comment
Share on other sites

Turns out the plus sign in the following line should reflect the sign of the 220 component

 

Try the following:

(defun c:txt2plan ( / e i s v )
   (if (setq s (ssget "_:L" '((0 . "TEXT"))))
       (repeat (setq i (sslength s))
           (setq e (entget (ssname s (setq i (1- i))))
                 v (cdr (assoc 210 e))
                 e (subst  (cons 50 ((if (minusp (cadr v)) - +) (/ pi 2.0) (acos (car v)))) (assoc 50 e) e)
                 e (subst '(210 0.0 0.0 1.0) (assoc 210 e) e)
                 e (subst  (cons 10 (trans (cdr (assoc 10 e)) v 0)) (assoc 10 e) e)
                 e (subst  (cons 11 (trans (cdr (assoc 11 e)) v 0)) (assoc 11 e) e)
           )
           (entmod e)
       )
   )
   (princ)
)

;; ArcCosine  -  Lee Mac
;; Args: -1 <= x <= 1

(defun acos ( x )
   (if (<= -1.0 x 1.0)
       (atan (sqrt (- 1.0 (* x x))) x)
   )
)
(princ)

Link to comment
Share on other sites

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