Jump to content

Requesting help on modifying a LISP routine...


Heesh

Recommended Posts

I recently came across TEXTLEADER.LSP Version 1.2 on CADALYST. Program was authored by Timothy G. Spangler (Copyright August, 2007) and works great. However, some of my co-workers have requested that this routine be initiated via button bar. Made the connection to a button, but the routine still requires enterring "TL" at the command prompt. Can anyone tell me how to modify the routine so that it can be initiated directly from the button without the command line input? Any help would be much appreciated.

Link to comment
Share on other sites

  • Replies 26
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    13

  • Heesh

    9

  • TimSpangler

    3

  • lpseifert

    2

Firstly, Welcome to CADTutor, I'm sure you'll like it here :)

 

 

Just put the command prompt syntax in the macro box of the button customization - should do the trick. :)

 

i.e.

 

(defun c:[b][color=Red]test[/color][/b] ()
     ....
)

So in this case, type "test" in the button macro box.

Link to comment
Share on other sites

Thanks for the warm welcome. I've tried the suggestions and haven't been able to resolve the problem. I already had the macro call entered. The LISP routine line reads:

(defun C:TL (/) (C:TEXTLEADER))

I've tried putting TL into the macro call and nothing happens. The LISP routine is named TEXTLEADER.LSP, so I've been using TEXTLEADER in the macro call. With this, pressing the button gets me "(load "TextLeader") ; error: bad argument type: FILE nil" and then I can run the routine by typing TL at the command line. If the button is not used at least once, TL is not recognized. However, after pressing the button once, TL will continue to work until AutoCAD is shut down. I'm pretty sure I'm doing something wrong with the button association, however, I am at a loss as to what. Also, I'm thinking that the LISP routine may be coded such that TL is required to make it function regardless of how it is initiated.

Hope this makes my problem more clear and that someone can make sense of it. Again, any suggestions would be most appreciated.

Link to comment
Share on other sites

Thanks for explaining your problem further.

 

The line:

 

(defun c:TL () (C:TEXTLEADER))

 

Is merely a "Program Shortcut" and would function the same way as if the user had typed "TextLeader" in the command prompt.

 

The issue, it seems, is that the file is not being loaded properly. Could you post the LISP you are using to check if there is any error in the actual LISP itself (shouldn't be, considering the source). But, my guess is a load error.

Link to comment
Share on other sites

Here's a copy of the complete routine text from TEXTLEADER.LSP. Again, thanks for taking the time to help.

 

;;; Cadalyst Tips & Tools Weekly - November 24, 2008 - [website deleted on posting to CADTutor]

;;; ------------------------------------------------------------------------

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

(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 System 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"))

)

;;; ----------------- 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 "Type "TL" to run")

(print)

Link to comment
Share on other sites

The LISP looks fine, as I said - that TL is just a program shortcut so that the user does not have to type the whole syntax everytime.

 

How are you loading the LISP - startup suite or ACADDOC.lsp? or manually?

Link to comment
Share on other sites

Neither. Or manually through the button, actually. We typically attach the routine to a button through the macro call. In the Customize User Interface > Properties > Command > Macro I have ^C^C(load "TextLeader").

 

This is the same process we are using for dozens of button assignments, and it seems to work. Just not for this one...

Link to comment
Share on other sites

With just ^C^C(load "TextLeader"), the LISP routine won't automatically run unless you have a (c:TextLeader) within the LISP routine outside of the function.

 

Try it with this:

;;; Cadalyst Tips & Tools Weekly - November 24, 2008 - [website deleted on posting to CADTutor]
;;; ------------------------------------------------------------------------
;;; TEXTLEADER.LSP Version 1.2
;;;
;;; Copyright (C) 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 ...")
   ) ;_  end if
   (while (< 0 (getvar "CMDACTIVE"))
       (command)
   ) ;_  end while
   (TEXT_LEADER_RESET_ENV)
   (princ)
   ) ;_  end defun
   ;; Main Code
   (TEXT_LEADER_RUN)
) ;_  end defun
;;; ------------ 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...")
   ) ;_  end while
   ;; 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)))
   ) ;_  end progn
   ) ;_  end if
   ;; 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")
   ) ;_  end progn
   ) ;_  end if
   ;; 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)
   ) ;_  end progn
   ) ;_  end if
   ;; 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))
         ) ;_  end list
    ) ;_  end setq
    ;; Get the center point of the selected text object
    (setq InsertPoint
         (list
             (- (car DtextInsPoint) (car TempPoint))
             (+ (cadr DtextInsPoint) (cadr TempPoint))
             (+ (caddr DtextInsPoint) (caddr TempPoint))
         ) ;_  end list
    ) ;_  end setq
    ;; 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
         ) ;_  end +
    ) ;_  end setq
    ;; 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"
    ) ;_  end command
   )
   ((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))
         ) ;_  end list
    ) ;_  end setq
    ;; Get the center point of the selected text object
    (setq InsertPoint
         (list
             (+ (car DtextInsPoint) (car TempPoint))
             (+ (cadr DtextInsPoint) (cadr TempPoint))
             (+ (caddr DtextInsPoint) (caddr TempPoint))
         ) ;_  end list
    ) ;_  end setq
    ;; 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
         ) ;_  end +
    ) ;_  end setq
    ;; 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"
    ) ;_  end command
   )
   ((/= (or (equal TextRotate 0.0 0.0001) (equal TextRotate 1.5708 0.0001)))
    (alert "Selected text not at a suitable angle")
    (TEXT_LEADER_RUN)
   )
   ) ;_  end cond
   (TEXT_LEADER_RESET_ENV)
) ;_  end defun
;;; ----------------- Set Environment Settings
(defun TEXT_LEADER_SET_ENV (/)

   ;; Set System 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"
         ) ;_  end list
   ) ;_  end setq
) ;_  end defun
;;; ----------------- 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)
) ;_  end defun
;;;
;;; Echos to the command line
(princ "Type " TL " to run")
(c:TextLeader)
(print)

Link to comment
Share on other sites

Sorry, No joy. I block copied your version directly into the TEXTLEADER.LSP file and saved with the same name in the same location. I get the same error and results.

Link to comment
Share on other sites

Try remarking out this line near the bottom of the code

(princ "Type " TL " to run")

Also, the code has a call to invoke the command Textleader imbedded. Subsequent usage needs only TL (or Textleader)

Link to comment
Share on other sites

Loading the LISP files this way means that they must be in the ACAD Search Directory, so that ACAD will search for the correct file when prompted. Is this where you are saving them?

Link to comment
Share on other sites

Try remarking out this line near the bottom of the code

(princ "Type " TL " to run")

Also, the code has a call to invoke the command Textleader imbedded. Subsequent usage needs only TL (or Textleader)

 

 

 

Ahhhh nice spotting lpseifert! Didn't see that one! :P

 

Heesh, either comment block it out using ;| |;, or change it to:

 


(princ "\nType \"TL\" to run.")

Link to comment
Share on other sites

The LISP I have posted will run automatically when loaded, as per the modification:

 

(c:TextLeader)

 

If all else fails, try removing the

 

(c:TextLeader)

 

then add the lisp file to the start-up suite and just put

 

^C^CTL in the macro box.

Link to comment
Share on other sites

Nice program!!

 

Here in the office we have this launching from a button just as you requested. Here is how we load/ run our programs....

 

If it is in a menu, say Test.cui. Then we create Test.mnl This will load every time test.cui loads. Inside the mnl we have this:

 

(autoload "C:/YOUR_PATH_HERE/TextLeader.lsp" '("TL" "TEXTLEADER"))

 

Then in the button macro and menu pull down we have this:

 

^C^C^PTL or this: ^C^C^PTEXTLEADER

 

This "should" yield the requested results. If not try this after autocad loads

 

(findfile "textleader.lsp") this "should" return the path of the file. if not then its not in the search path.

 

*Using autoload instead of load keeps programs from getting loaded until they are needed. Just better practice IMHO

 

Let us know how it works..

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