Jump to content

Recommended Posts

Posted

I have this leader lisp I would like to modify but not sure how to make it work. The code below, asks the user to select the text they want to add a leader to. I then asks for the location where the user want the arrowhead then the location for the endpoint of the tail. The code sets the other end of the tail at the specified distance provided in the code.

 

What I would like it to do is once the arrowhead location has been established, the code will set the remaining two points based on the following criteria:

  1. The first end of the tail is .04 from the insertion point of the text (Currently the code is set to 0.00)
  2. The second point is 0.06 from the last point or 0.10 from the insertion point of the selected text.

Here is the entire code so you can see how thins works...

 

(defun C:SLD (/) (C:SweetLEADER)); Program Shortcut

;;; MAIN FUNCTION ¤¤¤¤¤¤¤¤
(defun C:SweetLEADER (/ *error* OldCmdecho OldOsmode OldOrthoMode OldClayer ExludeList)
 
   ;; Set Env
   (Sweet_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)
       )
       (Sweet_LEADER_RESET_ENV)
       (princ)
   )
   ;; Main Code
   (Sweet_LEADER_RUN)
)
;;; Begin Main Routine ¤¤¤¤¤¤¤¤
(defun Sweet_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")
           (Sweet_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.00 (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.00 (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")
           (Sweet_LEADER_RUN)
       )
   )
   (Sweet_LEADER_RESET_ENV)
)
;;; Set Environment Settings ¤¤¤¤¤¤¤¤
(defun Sweet_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 Sweet_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)
)

Any help here would be greatly appreciated. Thanks

 

Zen

Posted

Well for starters at least give due credit:

 

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

 

Also can be found (and at Catalyst)

 

Looks familiar? (names have been changed to protect the innocent?)

Posted
"Well for starters at least give due credit:

 

 

Looks familiar? (names have been changed to protect the innocent?)"

 

Never said I wrote the code, I just want to customize it a bit to meet our needs. I found the routine this morning and thought it was great. It is an excellent routine by the way. Just need help in tweaking it a bit

 

Have any suggestions?

Posted
I'd suggest that you read and add the following to the code

 

That is added. I just didn't post all of the code and since Timothy posted his original code there really isn't a need. Just trying to save some space is all.

 

NOTICE TO ALL

 

The code I posted was wrtten by:

 

Timothy G. Spangler

Copyright © August, 2007

 

if you want a copy then see his post above.

 

Satisfied? gezz lighten up.

 

Now can we actually get back to the original idea here. Can that code be tweaked to allow for the criteria set in my first post? I will give BILLBOARD CREDIT for the fix cuz I really don't care about that. Just would like a routine that can do this.

 

Zen

Posted

Zen,

 

I am just trying to maintain the integrity of the code that's all. If you leave the header in tact it will make it that much easier to find the original owner when you need it modified.....If you downloaded the code without a header let me know where you got it from. Please.

 

 

As for modifying the code...I am at home know but when i get to work tomorrow i'll give it a look and post back.

 

P.S. If you get use out of it, great, let me know so i know that my efforts are wasted on myself alone.

Posted

I am sure I will get use out of it because I was having trouble with my users making leaders of all size tails; small, long, none at all, it was very frustrating. I even made a block of the leaders to comy and just copy, move rotate then just move the arrowhead to the entity they were noting. They still did their own thing. Your code will ensure that all they have to do is select the text and point to the item they are noting. Done deal.

 

I look forward to seeing your code. I am going to be a AU all next week but once I am back in the office I will let you know how the users like it.

Posted

for future reference to all posters.....

 

CODE POSTING GUIDELINES

 

http://www.cadtutor.net/forum/showthread.php?t=9184

 

Please ensure that you have the right to publish code on a public forum. In most cases, the code you are publishing will be your own and it will be assumed that if no attribution is given, you are the author.

However, if you are not the author, you must make this clear and where possible, give credit to the author.

 

Any routines published here must have their header intact, including any title, instructions, author contact details, date and copyright information. If at all possible, please make sure that you have the the authors permission to publish their work.

Posted

Nice.

It's been here since 18th Sep 2006, at the start of the forum thread list.

A sticky even.

Sounds like it is something important to me.

Posted

I can't believe he's even changed the syntax to make it look different... poor Tim - all that work, and no credit when credit's due.

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