TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Andrea on September 29, 2008, 02:04:24 PM

Title: Leadering Text...
Post by: Andrea on September 29, 2008, 02:04:24 PM
for who are interested...
I have create a simple routine to draw leader. It detect Mtext and Dtext.

command: TLEADER2 to draw Leader
command: TLEADERCONFIG to have vertical Line or accolade when detecting Mtext.

Download TLEADER2 here (http://www.theswamp.org/screens/index.php?dir=Andrea/&file=TLEADER2.VLX)
(http://www.theswamp.org/screens/Andrea/TLEADER2demo.gif)
Title: Re: Leadering Text...
Post by: GDF on September 29, 2008, 02:15:44 PM
Andrea

Not working for me.
I get the follwing:

Command: TLEADER2
nil


Gary
Title: Re: Leadering Text...
Post by: Andrea on September 29, 2008, 02:43:20 PM
If you try this in a drawing who have no text....
nil will be the result.

is this what happen ?
Title: Re: Leadering Text...
Post by: GDF on September 29, 2008, 04:00:59 PM
If you try this in a drawing who have no text....
nil will be the result.

is this what happen ?

I get nil in all cases: text, dtext or mtext.


Command: (LOAD "E:/Arch_WorkOn/upDates/TLEADER2.VLX")
    --  T L E A D E R 2 --           :Activé
Par: Andrea Andreettinil



Command: tleader2
nil
Command:




Title: Re: Leadering Text...
Post by: TimSpangler on September 29, 2008, 04:51:08 PM
No workie for me neither.

Using 2007
Title: Re: Leadering Text...
Post by: Andrea on September 29, 2008, 04:53:40 PM
anyone else have the same problem ?
 :?

It work for all user here..and home.
but..let me recheck the code and I let you know..
sorry about that.

Andrea.
Title: Re: Leadering Text...
Post by: ronjonp on September 29, 2008, 04:58:02 PM
It works here.
Title: Re: Leadering Text...
Post by: Andrea on September 29, 2008, 05:03:37 PM
strange... :?

I 've made a test on AutoCAD 2006, 2007, 2008 and 2009..
and work well.

I also make a test on english and French release.
I have asked to some friends working to another firms... if the troutine work and say yes.

now, i'm a little confused..
Title: Re: Leadering Text...
Post by: TimSpangler on September 29, 2008, 05:03:51 PM
I love the concept.  Here is one that I rewrote a little while ago. Not really sure were it came from but it was very limited and din't always work.

*Disclaimer*
Work with Dtext Mtext and Text
This code will only work on text objects that are horiz or vert
The leader is placed on the layer of the selected text object
Leader is based on the current dimstyle.

Here is the rewrite:
Code: [Select]
;;; ------------------------------------------------------------------------
;;;    TEXTLEADER.LSP Version 1.2
;;;
;;;    Copyright© August, 2007
;;;    Timothy G. Spangler
;;;
;;;    Permission to use, copy, modify, and distribute this software
;;;    for any purpose and without fee is hereby granted, provided
;;;    that the above copyright notice appears in all copies and
;;;    that both that copyright notice and the limited warranty and
;;;    restricted rights notice below appear in all supporting
;;;    documentation.
;;;
;;;    Add leader to text (Non Associating Leader).
;;;
;;; ------------------------------------------------------------------------
(defun C:TL (/) (C:TEXTLEADER)); Program Shortcut

;;; MAIN FUNCTION ;;;;;;;;;;;;;;;;;;;;;;;;;
(defun C:TEXTLEADER (/ *error* OldCmdecho OldOsmode OldOrthoMode OldClayer ExludeList)
  
;; Set Env
(TEXT_LEADER_SET_ENV)

;;; Error Handling Routine ;;;
(defun *error* (MSG)
(if(not(member MSG '("Function cancelled" "quit / exit abort")))
(princ (strcat "\n*** Program Error: " (strcase MSG) " ***"))
(princ "\n... Program Cancelled ...")
)
(while (< 0 (getvar "CMDACTIVE"))
(command)
)
(TEXT_LEADER_RESET_ENV)
(princ)
)
;; Main Code
(TEXT_LEADER_RUN)
)
;;; ------------ Begin Main Routine
(defun TEXT_LEADER_RUN (/ TextEnt TextEntList TextLayer DtextBox DtextEntList TextRotate MtextLine
 DtextInsPoint TempPoint LeaderEnd)

;; Get text object from selection
(while (null (setq TextEnt (entsel "\n Select Top or Bottom Line of Text: ")))
(princ "\n Nothing Selected...")
)
;; Get entity list from text
(setq TextEntList (entget (car TextEnt)))
;; Get text layer
(setq TextLayer (cdr(assoc 8 TextEntList)))
;; Set layer to text layer
(setvar "CLAYER" TextLayer)
;; If selected text is "TEXT"
(if (= (cdr (assoc 0 TextEntList)) "TEXT")
 (progn
   (setq DtextBox (textbox (entget (car TextEnt))))
   (setq DtextEntList (entget (car TextEnt)))
(setq TextRotate (cdr(assoc 50 DtextEntList)))
 )
)
;; If selected text is "MTEXT"
(if (= (cdr (assoc 0 TextEntList)) "MTEXT")
 (progn
   (command "explode" TextEnt)
   (setq MtextLine (ssget (cadr TextEnt)))
   (setq DtextEntList (entget (ssname MtextLine 0)))
   (setq DtextBox (textbox (entget (ssname MtextLine 0))))
   (setq TextRotate (cdr(assoc 50 DtextEntList)))
(command "u")
 )
)
;; If selected entity is not "TEXT" or "MTEXT"
(if (member (cdr (assoc 0 TextEntList)) ExludeList)
 (progn
(alert "Selected entity is not TEXT or MTEXT")
(TEXT_LEADER_RUN)
)
)
;; Get insertion point of text
(setq DtextInsPoint (cdr (assoc 10 DtextEntList)))
;; Check the rotation of the text
(cond
((equal TextRotate 1.5708 0.0001)
;; Get center point of textbox (from 0,0)
(setq TempPoint
(list
(/ (+ (cadar DtextBox)(cadadr DtextBox)) 2.0)
(/ (+ (caadr DtextBox)(caar DtextBox)) 2.0)
(cadddr (assoc 10 DtextEntList))
)
)
;; Get the center point of the selected text object
(setq InsertPoint
(list
(- (car DtextInsPoint)(car TempPoint))
(+ (cadr DtextInsPoint)(cadr TempPoint))
(+ (caddr DtextInsPoint)(caddr TempPoint))
)
)
;; Set the leader end point
(setq LeaderEnd
(+ (/ (- (caadr DtextBox) (caar DtextBox)) 2.0)
   (* 0.0625 (getvar "dimscale")) ;CHANGE THIS TO CHANGE GAT BETWEEN TEXT AND LEADER
)
)
;; Prompt to create the leader
(prompt "\n Select Leader Start and Bend Points: ")
;; Run the leader command with the point filter
(command "leader"
PAUSE
  ".X"
  InsertPoint
  PAUSE
  (polar InsertPoint (angle InsertPoint (getvar "lastpoint")) LeaderEnd)
  ""
  ""
  "n"
)
)
((equal TextRotate 0.0 0.0001)
;; Get center point of textbox (from 0,0)
(setq TempPoint
(list
(/ (+ (caadr DtextBox) (caar DtextBox)) 2.0)
(/ (+ (cadar DtextBox) (cadadr DtextBox)) 2.0)
(cadddr (assoc 10 DtextEntList))
 )
)
;; Get the center point of the selected text object
(setq InsertPoint
(list
(+ (car DtextInsPoint) (car TempPoint))
(+ (cadr DtextInsPoint) (cadr TempPoint))
(+ (caddr DtextInsPoint) (caddr TempPoint))
 )
)
;; Set the leader end point
(setq LeaderEnd
(+ (/ (- (caadr DtextBox) (caar DtextBox)) 2.0)
   (* 0.0625 (getvar "dimscale")) ;CHANGE THIS TO CHANGE GAP BETWEEN TEXT AND LEADER
)
)
;; Prompt to create the leader
(prompt "\n Select Leader Start and Bend Points: ")
;; Run the leader command with the point filter
(command "leader"
PAUSE
  ".Y"
  InsertPoint
  PAUSE
  (polar InsertPoint (angle InsertPoint (getvar "lastpoint")) LeaderEnd)
  ""
  ""
  "n"
)
)
((/= (or (equal TextRotate 0.0 0.0001)(equal TextRotate 1.5708 0.0001)))
(alert "Selected text not at a suitable angle")
(TEXT_LEADER_RUN)
)
)
(TEXT_LEADER_RESET_ENV)
)
;;; ------------ Set Environment Settings
(defun TEXT_LEADER_SET_ENV (/)

;; Set sysetem variables
(setq OldCmdecho (getvar "CMDECHO"))
(setq OldOsmode (getvar "OSMODE"))
(setq OldOrthoMode (getvar "ORTHOMODE"))
(setq OldClayer (getvar "CLAYER"))

(setvar "CMDECHO" 0)
(setvar "ORTHOMODE" 0)
(setvar "OSMODE" 513)

;;; Undo marker
(command "_UNDO" "BEGIN")

;; Set the exclusion list
(setq ExludeList (list "3DFACE" "3DSOLID" "ARC" "ATTDEF" "ATTRIB"  "BODY" "CIRCLE" "DIMENSION" "ELLIPSE"
"HATCH" "IMAGE" "INSERT" "LEADER" "LINE" "LWPOLYLINE" "MLINE" "OLEFRAME" "OLE2FRAME" "POINT" "POLYLINE"
"RAY" "REGION" "SEQUEND" "SHAPE" "SOLID" "SPLINE" "TOLERANCE" "TRACE" "VERTEX" "VIEWPORT" "XLINE"))

;; Add program description to status line
(grtext -2 (strcat "Text Leader " "v1.2" " Copyright© 2007"))
)
;;; ------------ Reset Environment Settings
(defun TEXT_LEADER_RESET_ENV (/)

;;; Undo marker
(command "_UNDO" "END")

;; Reset system variable
(grtext -2 "")
(setvar "CLAYER" OldClayer)
(setvar "OSMODE" OldOsmode)
(setvar "ORTHOMODE" OldOrthoMode)
(setvar "CMDECHO" OldCmdecho)

(princ)
)
;;;
;;; Echos to the command line
(princ "\n Text Leader v1.2© \n Timothy Spangler, \nAugust, 2007....loaded.")
(terpri)
(princ "Type \"TL\" to run")
(print)
;;; End echo
Title: Re: Leadering Text...
Post by: Andrea on September 29, 2008, 05:04:18 PM
It works here.

wich AutoCAD version Ronjomp ?
Title: Re: Leadering Text...
Post by: Bob Wahr on September 29, 2008, 05:08:21 PM
2008 sp1, XP sp3.

Works fine for me.
Title: Re: Leadering Text...
Post by: Andrea on September 29, 2008, 05:10:23 PM
(http://www.theswamp.org/screens/Andrea/TLEADER2demo2.gif)
Title: Re: Leadering Text...
Post by: Bob Wahr on September 29, 2008, 06:33:51 PM
It kinda makes me tingly in my nether regions.  Good job Andrea.
Title: Re: Leadering Text...
Post by: Andrea on September 29, 2008, 07:11:24 PM
It kinda makes me tingly in my nether regions.  Good job Andrea.

 :-)
thanks.




Title: Re: Leadering Text...
Post by: Bob Wahr on September 29, 2008, 07:18:55 PM
Side note:  Is that baby in your avatar yours?  It is incredibly cute.
Title: Re: Leadering Text...
Post by: CAB on September 29, 2008, 09:09:10 PM
Good one Andrea.
Works in 2000 but the ghosting is very slow. The cursor flashes and you have to pause the mouse for a second or two before the vectors are drawn.  The Move Reactor does not work if you click & hold to move text. It also doesn't work if you move the leader parts.

PS I don't mean to be critical, just indicating areas where he routine can be improved.


Here is another dynamic leader
http://www.theswamp.org/index.php?topic=7089.0
Title: Re: Leadering Text...
Post by: Andrea on September 29, 2008, 10:29:52 PM
Thanks  :-)

Works in 2000 but the ghosting is very slow. The cursor flashes and you have to pause the mouse for a second or two before the vectors are drawn. 
Ok, i'll take a look on how i can improve this.

The Move Reactor does not work if you click & hold to move text. It also doesn't work if you move the leader parts.

Good Catch...didn't think about it.
but...
I use
Code: [Select]
(list "MOVE" "STRETCH" "GRIP_MOVE" "GRIP_STRETCH")for the reactor list command,....and don't know realy what is the command for Dragging only.
anyone know ?


PS I don't mean to be critical, just indicating areas where he routine can be improved.

Don't worry,..I take all comments and suggestions.

Thanks,..  ;-)
Title: Re: Leadering Text...
Post by: GDF on September 30, 2008, 09:44:46 AM
Andrea

I give up, why is it working forsome but not all? Still cannot get it to work. I have tried everything.
Right now I am using 2008.

Gary
Title: Re: Leadering Text...
Post by: Andrea on September 30, 2008, 10:13:45 AM
Andrea

I give up, why is it working forsome but not all? Still cannot get it to work. I have tried everything.
Right now I am using 2008.

Gary

Sorry Garry,..
bad to hear that..

some questions..
do you load some 3rd party software ? like Inroads, autoTurn..etc. ?
maybe there is some conflict ?   :|
Title: Re: Leadering Text...
Post by: GDF on September 30, 2008, 10:24:48 AM
No, we use our own inhouse routines...

Could be some varable setting.

Gary
Title: Re: Leadering Text...
Post by: Andrea on September 30, 2008, 11:12:48 AM
No, we use our own inhouse routines...

Could be some varable setting.

Gary

maybe..
but i'm curious to know..
did you made the test by loading only the TLEADER2 application ?

Title: Re: Leadering Text...
Post by: GDF on September 30, 2008, 11:21:35 AM
Andrea

I unloaded ALL routines and restarted AutoCAD...and I still get "nil" at the command line.

Gary
Title: Re: Leadering Text...
Post by: Andrea on September 30, 2008, 11:42:55 AM
Andrea

I unloaded ALL routines and restarted AutoCAD...and I still get "nil" at the command line.

Gary

OK Thanks Gary,..
nil = is the result when you have no text in the current drawing.

I don't know realy where to start..
I'll take a look, make more tests and let you know when get new release.

andrea.