Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Contributor
econnerly
Posts: 20
Registered: ‎07-27-2009
Message 1 of 15 (870 Views)

Need LISP to draw line / pline to match TEXT rotation!

870 Views, 14 Replies
10-07-2011 12:12 PM

I have searched everywhere but have found nothing. There are a ton of lisp to match text rotation to a selected line, but not vice versa.

Anyone out there have anything?

*Expert Elite*
azrdgldr
Posts: 1,250
Registered: ‎01-09-2007
Message 2 of 15 (867 Views)

Re: Need LISP to draw line / pline to match TEXT rotation!

10-07-2011 12:17 PM in reply to: econnerly

Set your ucs to object and select the text object.  Make sure your ortho is on and draw your line or pline to the length desired.

Contributor
econnerly
Posts: 20
Registered: ‎07-27-2009
Message 3 of 15 (856 Views)

Re: Need LISP to draw line / pline to match TEXT rotation!

10-07-2011 12:58 PM in reply to: azrdgldr

Nice! Thanks.
Im sure that should be easy to write a lisp routine that would set the usc for while drawing the line and then set the ucs back to "previous" when the command is over.

Valued Mentor
stevor
Posts: 891
Registered: ‎12-26-2005
Message 4 of 15 (850 Views)

Re: Need LISP to draw line / pline to match TEXT rotation!

10-08-2011 04:30 AM in reply to: econnerly

Try:

 

 ; DXF data value from code number
 (defun DXF_ (n aLst) (cdr (assoc n aLst)) )
 
 ; Text Line
 (defun C:txl (/  dl en es ps pe p1 p2 tbx clns nlns dyr )
   (setvar "cmdecho" 0) (terpri) (grtext -1 " AusCadd.com  ")
   (setq Clns (getvar "clayer")  nlns "Text-Line")
   (princ"\n Set Layer to: ") (prin1 lyns)
   (if (not (equal (strcase (getvar "clayer")) (strcase nlns)))
     (command "-layer" "make" nlns  "") ) :
   ;
   (if (and (setq es (ent_seld  es "\n  Sel  Text  Ent: "))
            (setq en (car es)  dl (entget en))
            (= "TEXT" (DXF_ 0 DL)) )
    (PROGN (redraw)  ; expert >3
     (command "UCS" "save" "temp" "ucs" "ob" en )
     (princ " UCS saved to Temp, set to Object  ")
     (setq tbx (textbox dL)  p1 (car tbx)  p2 (cadr tbx)
           dyr 3 ; can be entered each time, or upon file load, etc
           ps (list (car p1) (- (/ tH dyr)) 0)   ; left
           pe (list (car p2) (- (/ tH dyr)) 0) ) ; right
     ;
     (command "Line" "none" ps "none" pe "") ; "0" or 0 ?
     (command "UCS" "res" "temp"   ) ; restore UCS
     (setvar "clayer" clns)  ;   Layer
     ;
    ) (princ" Nyet ") )  ;  pr
  (princ)
 ) ;  def 

S
*Expert Elite*
pbejse
Posts: 2,511
Registered: ‎11-24-2009
Message 5 of 15 (843 Views)

Re: Need LISP to draw line / pline to match TEXT rotation!

10-08-2011 07:38 AM in reply to: econnerly

econnerly wrote:

I have searched everywhere but have found nothing. There are a ton of lisp to match text rotation to a selected line, but not vice versa.

Anyone out there have anything?


One thing comes to mind

 

POLAR TRACKING:

 

(defun c:test ()
  	(setvar 'polarmode 4)
  	(setq Txt (car (entsel "\nSelect Text/Mtext: :")))
  	(wcmatch (cdr (assoc 0 (setq txt (entget txt)))) "*TEXT")
  	(setvar 'polarang (cdr (assoc 50 txt)))
  	(command "_line"))
)

 

Valued Mentor
stevor
Posts: 891
Registered: ‎12-26-2005
Message 6 of 15 (822 Views)

Re: Need LISP to draw line / pline to match TEXT rotation!

10-10-2011 03:40 AM in reply to: econnerly

If you try mine, C:TXL, the lie:

 

(if (and (setq es (ent_seld  es "\n  Sel  Text  Ent: "))

 

needs to be replaced by:

 

(if (and (setq es (entsel  "\n  Sel  Text  Ent: "))

 

because Ent_SelD is a local subroutine to include a default selection,  accidentally left in, and not appropriate for this. [sorry ]

S
Valued Mentor
stevor
Posts: 891
Registered: ‎12-26-2005
Message 7 of 15 (818 Views)

Re: Need LISP to draw line / pline to match TEXT rotation!

10-10-2011 03:56 AM in reply to: econnerly

Again, if you use c:TXL the following additions:

 

add the line

           TH (dxf_ 40 dl)
after 

     (setq tbx (textbox dL)  p1 (car tbx)  p2 (cadr tbx)
because: unknown.

 

Also, Expert must be set to 4 or more, which it usally is, but a test and reset could have been added, yet was not.

 

 

S
*Expert Elite*
Kent1Cooper
Posts: 5,872
Registered: ‎09-13-2004
Message 8 of 15 (806 Views)

Re: Need LISP to draw line / pline to match TEXT rotation!

10-10-2011 05:27 AM in reply to: econnerly

econnerly wrote:

....
Im sure that should be easy to write a lisp routine that would set the usc for while drawing the line and then set the ucs back to "previous" when the command is over.


Or, you can change the SNAPANG System Variable to match the Text, rather than the UCS.  If you want a single Line segment, in simplest terms:
 

(defun C:TAL (/ sang orth txt); = Text-Aligned Line
  (setq
    sang (getvar 'snapang)
    orth (getvar 'orthomode)
    txt (entget (car (entsel "\nSelect Text to Align Line with: ")))
  ); setq
  (setvar 'snapang (cdr (assoc 50 txt)))
  (setvar 'orthomode 1)
  (command "_.line" pause pause "")
  (setvar 'snapang sang)
  (setvar 'orthomode orth)
)

 

If you want to be able to draw multiple sequential Line segments, or a Polyline:

 

....

  (setvar 'orthomode 1)
  (command "_.line"); or "_.pline"

  (while (> (getvar 'cmdactive) 0) (command pause))
  (setvar 'snapang sang)

....

 

Either works with Mtext as well as Text.  Add error handling, selected-object-type control, switching to Text's Layer, etc., as desired.

Kent Cooper
Contributor
econnerly
Posts: 20
Registered: ‎07-27-2009
Message 9 of 15 (794 Views)

Re: Need LISP to draw line / pline to match TEXT rotation!

10-10-2011 08:58 AM in reply to: econnerly

You guys rock! Thanks very much. Both routines produce the result that I was looking for!

*Expert Elite*
Kent1Cooper
Posts: 5,872
Registered: ‎09-13-2004
Message 10 of 15 (764 Views)

Re: Need LISP to draw line / pline to match TEXT rotation!

10-11-2011 07:22 AM in reply to: stevor

stevor wrote:

....

     (command "UCS" "save" "temp" "ucs" "ob" en )
     (princ " UCS saved to Temp, set to Object  ")
....

     (command "UCS" "res" "temp"   ) ; restore UCS
....


You could avoid the need to save a temporary UCS [which you probably should also delete after you're done with it], by just using the Previous option to put it back where it was:

 

....

     (command "UCS" "ob" en)
....

     (command "UCS" "_previous") ; restore UCS
....

 

If you were doing multiple operations that might involve changing the UCS more than once in the process, then I could see more value in saving a temporary UCS to restore later.

Kent Cooper
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.