Jump to content

rotate text to align line


motee-z

Recommended Posts

Mr ASMI

 

what a great lisp

related to that lisp there is one comment I want to select a text not type again.

 

Second, how did u do that presentation (*.GIF file)

 

thanx and regards

Link to comment
Share on other sites

  • Replies 40
  • Created
  • Last Reply

Top Posters In This Topic

  • CAB

    11

  • ASMI

    9

  • asos2000

    9

  • motee-z

    4

Top Posters In This Topic

Posted Images

> asos2000

 

what a great lisp

related to that lisp there is one comment I want to select a text not type again.

 

Yes, I have some ideas. And this is one of them.

 

Second, how did u do that presentation (*.GIF file)

 

This animated *.gif is prodused with Camtasia Studio software. It provides to record on-screen user actions, add subtitles, pictures and sound also export into *.avi, *.swf, animated *.gif and some other formats.

 

> CAB

 

Thank you. It while spontaneous idea expressed in a small piece of a code. Completion is required.

Link to comment
Share on other sites

OK, One more offering:

You may enter the text or press Enter to except last text used by the routine or

pick text from the drawing to copy string from.

;;;     TextAlignWithObject.lsp
;;;      by Charles Alan Butler
;;;         Copyright 2007
;;;  by Precision Drafting & Design All Rights Reserved.
;;;  Contact at ab2draft @ TampaBay.rr.com
;;;
;;;   Version 1.0 Beta  Feb 19, 2007
;;;   Version 1.1 Beta  Aug 20, 2008, added fuzz to angle detection
;;;   Version 1.2 Beta  Aug 24, 2008, added text input options
;;;
;;; DESCRIPTION 
;;; Add text to DWG at angle of selected object
;;;
;;;
;;;  Limitations
;;;  No error checking
;;;
;;;
;;; Command Line Usage 
;;; Command: TAO
;;;
;;;
;;;  This software is provided "as is" without express or implied      ;
;;;  warranty.  All implied warranties of fitness for any particular   ;
;;;  purpose and of merchantability are hereby disclaimed.             ;
;;;  You are hereby granted permission to use, copy and modify this    ;
;;;  software without charge, provided you do so exclusively for       ;
;;;  your own use or for use by others in your organization in the     ;
;;;  performance of their normal duties, and provided further that     ;
;;;  the above copyright notice appears in all copies and both that    ;
;;;  copyright notice and the limited warranty and restricted rights   ;
;;;  notice appear in all supporting documentation.                    ;


(defun c:tao() (c:TextAlignWithObject)) ; shortcut

(defun c:TextAlignWithObject (/ tmp ang pt txtht FixTextAngle addtext
                             get_pt_and_angle)
 (vl-load-com)

 ;;  ------------------< sub functions >----------------------
 ;;  Returns a text angle in radians, flops text at >90 and <270 
 (defun FixTextAngle (ang)
   (if (and (> ang (+ (* 0.5 pi) 0.0001)) (< ang (+ (* 1.5 pi) 0.0001)))
     (+ ang pi)
     ang
   )
 )


 ;;  Create a text object 
 (defun addtext (ipt   ; insert point
                 hgt   ; text height
                 text  ; text string
                 ang   ; test angle
                 aln   ; text alignment
                 lay   ; text layer
                 / txtObj)
   (setq txtObj
          (vla-addtext
            (if (= (getvar "cvport") 1)
              (vla-get-paperspace (vla-get-activedocument (vlax-get-acad-object)))
              (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))
            )
            text
            (vlax-3d-point ipt)
            hgt
          )
   )
   (vla-put-layer txtObj lay)
   (vla-put-rotation txtObj ang)
   (vla-put-alignment txtObj aln)
   (vla-put-textalignmentpoint txtobj (vlax-3d-point ipt))

 )

 ;;  User selection of curve object
 ;;  return pick point & average angle of curve at pick point
 (defun get_pt_and_angle (prmpt / ent p@pt parA parB pt ang)
   (if (and (setq ent (entsel prmpt))
            (not (vl-catch-all-error-p
                   (setq pt (vl-catch-all-apply
                              'vlax-curve-getClosestPointTo
                              (list (car ent) (cadr ent))
                            )
                   )
                 )
            )
       )
     (progn
       (setq ent  (car ent)
             p@pt (vlax-curve-getParamAtPoint ent pt)
             parA (max 0.0 (- p@pt 0.05))
             parB (min (+ p@pt 0.05) (vlax-curve-getEndParam ent))
             ang (angle (vlax-curve-getPointAtParam ent parA)
                        (vlax-curve-getPointAtParam ent ParB)
                 )
       )
       (list pt ang)
     )
   )
 )



 
 ;;  ------------------< START HERE >----------------------
 
 ;;  Get text string to insert
 (or txtstr (setq txtstr "Default Text"))
 (while ; Loop while getting User Input 
   (cond
     ((null (setq tmp (getpoint_or_text 2 (strcat "\nPick or Enter text string: <" txtstr "> "))))
      (princ "\nERROR - pick text or enter text or Press ENTER.")
     )
     ((= tmp "") ; ENTER was pressed
      (if (= "" txtstr)
        (princ "\nERROR - No default text, Try Again.")
        nil ; exit loop
      )
     )
     ((and tmp (= (type tmp) 'str)) ; user entered a string tmp
      (setq txtstr tmp)
      nil ; exit loop
     )
     ((and tmp (listp tmp) ; a point was picked
           (setq en (car (nentselp tmp))) ; get the object
      )
      (if (vlax-property-available-p (vlax-ename->vla-object en) 'TextString)
        (null (setq txtstr (vla-get-textstring (vlax-ename->vla-object en))))
        (princ "\nERROR - Not a text object, Try Again.")
      )
     )
     ((princ "\nERROR - pick text or enter text or Press ENTER."))             
   )
 )
 ;| Old input string 
 (if (/= (setq tmp (getstring t (strcat "\nEnter text string: < " txtstr " > "))) "")
   (setq txtstr tmp)
 )
 |;
   
 ;;  Get object to align text & insert point
 ;;  Object must have curve data
 (if (setq lst (get_pt_and_angle "\nSelect point on object to label."))
   (progn
     (setq pt  (car lst)
           ang (FixTextAngle (cadr lst))
     )
     ;;  Text height by style or current Text Size
     (if (zerop (setq txtht (getvar 'textsize)))
       (setq txtht (getvar "TextSize"))
     )
     (addtext pt txtht txtstr ang acalignmentbottomcenter (getvar "clayer")) 
   )
   (prompt "\n**  Missed or no curve data for object.")
 )
 (princ)
)
(prompt "\nTextAlignWithObject.lsp loaded enter TAO to run.")
(princ)


;;;=======================[ getpoint_or_text.lsp ]======================= 
;;; Author: Copyright© 2005 Charles Alan Butler 
;;; Version:  1.0 Dec. 12, 2005
;;; Purpose: To get user entered text or picked point
;;; Sub_Routines: -None 
;;; Requirements: -ctype is the cursor type
;;;                      0  Display the normal crosshairs.
;;;                      1  Do not display a cursor (no crosshairs).
;;;                      2  Display the object-selection "target" cursor
;;;               -prmpt is the user prompt, start it with \n
;;; Returns: - picked point or
;;;            the user entered text or
;;;            ""  for Enter Key
;;;            nil for Escape Key
;;;==============================================================
(defun getpoint_or_text (ctype prmpt / char code data result flag p str)
 (vl-load-com)
 (vl-catch-all-apply
   '(lambda ()
      (setq flag t
            str ""
      )
      (princ prmpt)
      (while flag
        (setq p    (grread t 15 ctype)
              code (car p)
              data (cadr p)
        )
        (cond
          ((= code 3) ; clicked point
           (setq result data
                 flag nil
           )
          )
          ((= code 2) ; keyboard
           (setq char data)
           (cond
             ((<= 32 char 126)
              (princ (chr char))
              (setq str (strcat str (chr char)))
             )
             ((= char 
              ;; backspace was hit .. go chop off a character
              (and (> (strlen str) 0)
                   (princ (strcat (chr  " " (chr ))
                   (setq str (substr str 1 (1- (strlen str))))
              )
             )
             ((= char 13)
              (setq result str
                    flag nil
              )
             )
           )
          )
        )
      ) ;_ while
    )
 )
 result
)

Link to comment
Share on other sites

Mr. CAB

- The lisp makes a copy for the text when picking the text. see attached

- How can I change the text gap and angle When pick a text?

- When finish Aligning, Could be an option to rotate a text

Example

Rotate Text 180 Degree [Yes/No] :

it helps when rotate the UCS in viewport. See Attached

- Could the lisp crossing the text and aligning an object to another abject?

 

 

Thanx and regards

Txt01.JPG

Txt02.JPG

Link to comment
Share on other sites

Mr ASMI

please read reply # 26

 

I just add new option "Rotate text to 0°- 90° [Yes/No]:". Look to picture. Code on my website.

 

I (think that CAB too) write the programs at this forum while it interestingly for us. If it is not interesting to us we do not write.

 

- Could the lisp crossing the text and aligning an object to another abject?

 

Yes.

talon_rotate.gif

Link to comment
Share on other sites

Very nice ASMI, I applaud your efforts. Only one problem... after going through all the prompts, the grvecs are displayed, and I accept the position, the text does not display. Anyone else have this problem?

Link to comment
Share on other sites

Only one problem... after going through all the prompts, the grvecs are displayed, and I accept the position, the text does not display. Anyone else have this problem?

 

Strange. Can you send to me part of your file to e-mail alex@asmitools.com. Maybe it some Civil 3D features?

Link to comment
Share on other sites

  • 4 weeks later...
  • 1 year later...

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