Jump to content

Running TLEN LISP in AutoCAD query


samanthaberzina

Recommended Posts

Hello.

 

I have never used LISP before, however I have a massive project on at the moment where I need to calculate the total lenght of multiple polylines. There is just too much there to manually count so I looked into running TLEN.LSP. I saved it in Notepad as .lsp file and uploaded it via APPLOAD successfully, however every time I try to load it it does not work and this is all I get in the command line:

 

Command: (LOAD "C:/Users/Company/Desktop/linelengths.lsp") C:LL

 

What does C:LL stand for? Tried to Google it without much success.

 

(Also had to rename the file to LINELENGHTS as messed up the upload of the orginal TLEN file).

 

Thank you for any suggestions or advice.

Link to comment
Share on other sites

C:LL is the command name of the lisp (so like PLINE or PL is the command for a Polyline, LL is that of the lisp routine). Or at least one of the commands (there can be more in 1 lisp file).

 

Filename shouldn't matter.

 

Perhapse pasting the code here will help.

 

 content here [/ code]
Link to comment
Share on other sites

Try entering tlen at your commandline, as that is how to start the command, if it is already loaded.

Then follow the commandline prompts carefully, you'll be glad you did.

 

Sorry, I had assumed that you were using Lee Mac's lisp, for which tlen starts the lisp. :|

 

If you are unable to get this one running correctly, here is the link to Lee Mac's version.

 

http://www.lee-mac.com/totallengthandarea.html

 

Thanks Lee! :beer:

Link to comment
Share on other sites

Here is the code I have used. I got it from a link in another CAD forum.

 

(defun c:ll ()
(vl-load-com)
 (setq ss1 (ssget '((0 . "line"))); change "line" to "*line" if you want to include plines, splines
   sslen (sslength ss1)
   cnt 0)
   (if (findfile "c:\\linelengths.txt")
   (setq fn (open "c:\\linelengths.txt" "a"))
   (setq fn (open "c:\\linelengths.txt" "w"))
     )
 (repeat sslen
    (setq entname (ssname ss1 cnt)
   obj (vlax-ename->vla-object entname)
   len (rtos (vlax-get-property obj 'length) 2 4) ;adjust 4 for decimal precision
      )
 (write-line (strcat  "Line# " (rtos(1+ cnt) 2 0) (chr 9) len) fn)
 (setq cnt (1+ cnt))
   )
 (write-line (chr 10) fn)
 (close fn)
 (startapp "notepad" "c:\\linelengths.txt")
(princ)
 )

Edited by SLW210
Added Code Tags
Link to comment
Share on other sites

Try entering tlen at your commandline, as that is how to start the command, if it is already loaded.

Then follow the commandline prompts carefully, you'll be glad you did.

 

Sorry, I had assumed that you were using Lee Mac's lisp, for which tlen starts the lisp. :|

 

Yes, I tried your advice before you updated it and it just automatically changed TLEN command to LENGTHEN command.

Link to comment
Share on other sites

Yes, I tried your advice before you updated it and it just automatically changed TLEN command to LENGTHEN command.

 

The 'TLEN' command is applied for a certain lisp routine. There are many lisp routines out there on the big internet that do the things you need. And looking at the tittle of this thread Dadgad probably thought that TLEN would be the command.

 

In the posted code the command used for the LISP routine is "LL". As stated in the first line of the code (defun c:LL ())

 

As shown in the code it's looking for a txt file on the C:\ drive. Perhaps placing a file with given name on c:\ will make it work.

 

But someone will probably give a link to a better lisp routine :)

Link to comment
Share on other sites

Why don't you just change the letters in Lee Mac's routine that start the lisp routine? That way you won't invoke a native AutoCAD command. Change TLEN to TOTLEN. And document the change in the header information (where you see the ;; characters)?

Link to comment
Share on other sites

Why don't you just change the letters in Lee Mac's routine that start the lisp routine? That way you won't invoke a native AutoCAD command. Change TLEN to TOTLEN. And document the change in the header information (where you see the ;; characters)?

 

I have now saved Lee Mac's routine on my computer.

 

I want to change it so I can type in a command LINELENGTH. So where exactly I would change it, please? I have pasted the code below.

 

 

;;--------------------=={ Total Length }==--------------------;;
;;                                                            ;;
;;  Displays the total length of selected objects at the      ;;
;;  command line. The units and precision format of the       ;;
;;  printed result is dependent upon the settings of the      ;;
;;  LUNITS & LUPREC system variables respectively.            ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2013 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;

(defun c:tlen ( / e i l s )
   (if (setq s
           (ssget
              '(   (0 . "ARC,CIRCLE,ELLIPSE,LINE,*POLYLINE,SPLINE")
                   (-4 . "<NOT")
                       (-4 . "<AND")
                           (0 . "POLYLINE") (-4 . "&") (70 . 80)
                       (-4 . "AND>")
                   (-4 . "NOT>")
               )
           )
       )
       (progn
           (setq l 0.0)
           (repeat (setq i (sslength s))
               (setq e (ssname s (setq i (1- i)))
                     l (+ l (vlax-curve-getdistatparam e (vlax-curve-getendparam e)))
               )
           )
           (princ "\nTotal Length: ")
           (princ (rtos l))
       )
   )
   (princ)
)
(vl-load-com) (princ)

Link to comment
Share on other sites

Why don't you just change the letters in Lee Mac's routine that start the lisp routine? That way you won't invoke a native AutoCAD command. Change TLEN to TOTLEN. And document the change in the header information (where you see the ;; characters)?

 

I just downloaded and Loaded Lee's lisp, and it seems to overwrite the existing autocal shortcall TLEN, it worked great, with no additional need to alter anything or use ALIASEDIT. :beer:

Link to comment
Share on other sites

I have now saved Lee Mac's routine on my computer.

 

I want to change it so I can type in a command LINELENGTH. So where exactly I would change it, please? I have pasted the code below.

 

 

;;--------------------=={ Total Length }==--------------------;;
;;                                                            ;;
;;  Displays the total length of selected objects at the      ;;
;;  command line. The units and precision format of the       ;;
;;  printed result is dependent upon the settings of the      ;;
;;  LUNITS & LUPREC system variables respectively.            ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2013 - www.lee-mac.com       ;;


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

(defun c:tlen ( / e i l s )
   (if (setq s
           (ssget
              '(   (0 . "ARC,CIRCLE,ELLIPSE,LINE,*POLYLINE,SPLINE")
                   (-4 . "<NOT")
                       (-4 . "<AND")
                           (0 . "POLYLINE") (-4 . "&") (70 . 80)
                       (-4 . "AND>")
                   (-4 . "NOT>")
               )
           )
       )
       (progn
           (setq l 0.0)
           (repeat (setq i (sslength s))
               (setq e (ssname s (setq i (1- i)))
                     l (+ l (vlax-curve-getdistatparam e (vlax-curve-getendparam e)))
               )
           )
           (princ "\nTotal Length: ")
           (princ (rtos l))
       )
   )
   (princ)
)
(vl-load-com) (princ)

 

 

 

NO need, just use TLEN, assuming that you have successfully LOADED the lisp.

Try it, you'll like it.

Link to comment
Share on other sites

I just downloaded and Loaded Lee's lisp, and it seems to overwrite the existing autocal shortcall TLEN, it worked great, with no additional need to alter anything or use ALIASEDIT. :beer:

 

I seem to have messed it up initially. When I tried to load TLEN via APPLOAD the first time, for some reason I clicked that the Script is not trusted (I got confused and must have thought it will just cancel loading the file). Since then I cannot load any file that is called TLEN :lol:

Link to comment
Share on other sites

NO need, just use TLEN, assuming that you have successfully LOADED the lisp.

Try it, you'll like it.

 

OMG It works!!!!!!!!!!! Thank you, thank you so much! :thumbsup:

Link to comment
Share on other sites

The name of Lee's lisp is not TLEN, but TOTLEN, sounds like you want to LOAD that one.

Lee is incrdibly trustworthy, don't reject it when asked.

Link to comment
Share on other sites

OMG It works!!!!!!!!!!! Thank you, thank you so much! :thumbsup:

 

I am very happy to hear that Lee Mac has made another convert, to the wonderful world of increased productivity known as Lisp.

 

But don't thank me, I am just the messenger, thank Lee Mac, he's the GUY!

 

At your convenience, look over the incredible library of lisps which Lee very generously makes freely available to the global cad community.

 

One of my all time favorites is LAYER DIRECTOR.

 

Thanks Lee! :beer:

 

 

Link to comment
Share on other sites

I am very happy to hear that Lee Mac has made another convert, to the wonderful world of increased productivity known as Lisp.

 

But don't thank me, I am just the messenger, thank Lee Mac, he's the GUY!

 

At your convenience, look over the incredible library of lisps which Lee very generously makes freely available to the global cad community.

 

One of my all time favorites is LAYER DIRECTOR.

 

Thanks Lee! :beer:

 

 

 

I will definitely explore more of his work. I have been working with CAD for quite a few years, however never ventured much out of my comfort zone and I feel it is tome to improve my game and make everything a bit faster and smarter.

 

Thank you again and thanks to everyone who contributed. Very appreciated!

Link to comment
Share on other sites

Ones that you find indispensable can be loaded into the little briefcase shown on the APPLOAD dialog, then whenever you start the software, any you place there, will be ready to use throughout your session.

Link to comment
Share on other sites

Regarding your question "What does C:LL stand for?"

 

 

When the lisp file is loaded it is echoing back to the command line the name of the command that can be used. In this case entering LL at the command line will start the "LineLength.lsp"

 

 

The "C:" prefix indicates that it will work on the command line. Whenever you are looking at a .lsp file search for the C; prefix and you will find the commands that are available for use. Some lisp files will have several commands that are defined.

Link to comment
Share on other sites

A couple of extra suggestions to help you, if you add (c:tlen) to the end of the lisp when you appload it will run straight away, but after that you will need to type Tlen, also to remind you and we all get swamped with lisps most of ours are in a menu or autoloaded so remembering the command to type can get lost. Add a simple line after the comments to remind you.

I have this in a lot of lisps we have multiple staff, using alert, but add a bit more code to check that it only happens once.

;;  Author: Lee Mac, Copyright © 2013 - www.lee-mac.com       ;;


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

(if (/= tlenmess nil)(princ )(progn (alert "To run type Tlen")(setq tlenmess "Y")))

 

Ps we also have a "How to run our lisps" word doc which helps explaining the more complex lisps its around 60 pages. Some just need a few words.

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