Author Topic: lisp not working in AC2008  (Read 3533 times)

0 Members and 1 Guest are viewing this topic.

stevesfr

  • Newt
  • Posts: 54
lisp not working in AC2008
« on: November 28, 2008, 12:19:29 PM »
can someone look at the attached lisp and perhaps edit it so it works in acad2008? :cry:
thx, steveo
Can't remember what I'm supposed to forget.

Alan Cullen

  • Guest
Re: lisp not working in AC2008
« Reply #1 on: November 28, 2008, 12:41:25 PM »
Lisp will work in any acad version. That is not the problem. I think your fire up is in error...I get the following error......

Error: LOAD failed: "takeoff" in function nil

Just some suggestions.....place your error handler at the start....and any subroutines up early. Leave the main program to the very end of the code. Re-arrange it all and see how you go......

Error handler
sub routine 1
sub routine 2
sub routine 3
main startup routine.

jvillarreal

  • Bull Frog
  • Posts: 332
Re: lisp not working in AC2008
« Reply #2 on: November 28, 2008, 12:43:21 PM »
*EDITED*

Replace the "1" with "P1" in the argument list of CBC_SEGLEN like so..
Code: [Select]
(defun CBC_SEGLEN (PLIST / P0 P1 B ATANB D/2 R)
      (setq P0 (caar PLIST) B (cdar PLIST) P1 (caadr PLIST))
      (cond
         ((null P1) 0)
         ((zerop B) (distance P0 P1))
         (t
            (setq
               ATANB (atan B)
               D/2   (* 0.5 (distance P0 P1))
               R     (/ D/2 (sin (* 2.0 ATANB)))
            )
            (abs (* R 4.0 ATANB))
         )
      )
   )
« Last Edit: November 28, 2008, 12:47:52 PM by jvillarreal »

stevesfr

  • Newt
  • Posts: 54
Re: lisp not working in AC2008
« Reply #3 on: November 28, 2008, 01:04:40 PM »
*EDITED*

Replace the "1" with "P1" in the argument list of CBC_SEGLEN like so..
Code: [Select]
(defun CBC_SEGLEN (PLIST / P0 P1 B ATANB D/2 R)
      (setq P0 (caar PLIST) B (cdar PLIST) P1 (caadr PLIST))
      (cond
         ((null P1) 0)
         ((zerop B) (distance P0 P1))
         (t
            (setq
               ATANB (atan B)
               D/2   (* 0.5 (distance P0 P1))
               R     (/ D/2 (sin (* 2.0 ATANB)))
            )
            (abs (* R 4.0 ATANB))
         )
      )
   )

you the man !!
Can't remember what I'm supposed to forget.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: lisp not working in AC2008
« Reply #4 on: November 30, 2008, 04:56:25 PM »
Welcome to the Swamp Steve.

Here is an alternate routine I updated to include 3dpolylines.
Code: [Select]
;;;=======================[ LengthByLayer.lsp ]=========================
;;; Author: Copyright© 2007 Charles Alan Butler
;;; Version:  1.0 Dec. 26, 2007
;;; Version:  1.1 Nov. 28, 2008 Added 3dPline
;;; Purpose: display the length of objects on layer(s)
;;; Object Types allowed are LINE LWPOLYLINE POLYLINE SPLINE ARC CIRCLE
;;; Returns: -NA 
;;;==============================================================

(defun c:LBL()(c:LengthByLayer))
(defun c:LengthByLayer (/ cur_opt entlst ent_allowed filter layfilter len
                        mode ss tmp total_len txt_opt typ OutStr)
  (vl-load-com)
  ;|
     mode
   An integer specifying the linear units mode. The mode corresponds to the
     values allowed for the AutoCAD system variable lunits and can be one of
     the following numbers:
   1  Scientific
   2  Decimal
   3  Engineering (feet and decimal inches)
   4  Architectural (feet and fractional inches)
   5  Fractional
   nil  default to DWG settings
  |;
  (setq mode 4)
 
  (defun put_txt (txt / pt th)
    ;;  Check if the drawing height is set to 0:
    (if (setq pt (getpoint "\nPick Text Location..."))
     (progn
      (if (= 0 (setq th (cdr (assoc 40 (tblsearch "style"  (getvar "textstyle"))))))
        (setq th (getvar "textsize"))
      )
      (entmake (list (cons 0 "TEXT")
               (cons 1 txt)
               (cons 7 (getvar "textstyle"))
               (cons 10 pt)
               (cons 40 th)
      ))
     )
      (prompt "\n***  Text Insert skipped  ***")
    )
  )

  (initget "Yes No" )
  (setq txt_opt (getkword "\nPut text total in drawing [Yes/No]. <No>"))
  (or txt_opt (setq txt_opt "No"))

  (initget "Yes No" )
  (setq cur_opt (getkword "\nCurrent Space Only? [Yes/No] No for entire DWG. <Yes>"))
  (or cur_opt (setq cur_opt "Yes"))

  (prompt "\nSelect object(s) for layer filter.")
  (if (setq ss (ssget))
    (progn
      (setq tmp (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
            tmp (mapcar '(lambda(x) (cdr(assoc 8 (entget x)))) tmp)
            layFilter "")
      (mapcar '(lambda(x) (setq layFilter (strcat x "," layFilter))) tmp)
      (setq ent_allowed '("LINE" "LWPOLYLINE" "POLYLINE" "SPLINE" "ARC" "CIRCLE"))
       (setq Filter
        '((-4 . "<or") (0 . "LINE") (0 . "CIRCLE") (0 . "ARC")
                  (-4 . "<and") (0 . "*POLYLINE") ; include LWPolylines CAB 11.28.08
                    (-4 . "<not") (-4 . "&") (70 . 80) ; exclude mesh
                    (-4 . "not>")
                  (-4 . "and>")
               (-4 . "or>")
             )
      )
      (setq Filter (append Filter (list(cons 8 layFilter))))
      (if (= cur_opt "Yes")
        (setq Filter (cons (cons 410 (getvar "ctab")) Filter))
      )
      (if (setq ss (ssget "_X" Filter))
        (progn
          (setq entlst (mapcar 'cadr (ssnamex ss))
                total_len 0)
          (foreach en entlst
            (if (vl-position (setq typ (cdr (assoc 0 (entget en)))) ent_allowed)
              (setq len (vlax-curve-getdistatparam en (vlax-curve-getendparam en))
                    total_len (+ len total_len))
            )
          )
        )
        (prompt "\n***  Nothing on that layer with a length.  ***")
      )
    )
  )
  (and total_len (not (zerop total_len))
       (setq OutStr (strcat "Total length is " (if mode (rtos total_len mode)(rtos total_len))))
       (princ (strcat "\n" OutStr)) ; display on command line
       (if (= txt_opt "Yes") (put_txt OutStr))
  )
  (princ)
)
(prompt "\nGet Length By Layer loaded, Enter LBL to run")
(princ)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

stevesfr

  • Newt
  • Posts: 54
Re: lisp not working in AC2008
« Reply #5 on: November 30, 2008, 06:18:51 PM »
Welcome to the Swamp Steve.

Here is an alternate routine I updated to include 3dpolylines.
Code: [Select]
;;;=======================[ LengthByLayer.lsp ]=========================
;;; Author: Copyright© 2007 Charles Alan Butler
;;; Version:  1.0 Dec. 26, 2007
;;; Version:  1.1 Nov. 28, 2008 Added 3dPline
;;; Purpose: display the length of objects on layer(s)
;;; Object Types allowed are LINE LWPOLYLINE POLYLINE SPLINE ARC CIRCLE
;;; Returns: -NA 
;;;==============================================================

(defun c:LBL()(c:LengthByLayer))
(defun c:LengthByLayer (/ cur_opt entlst ent_allowed filter layfilter len
                        mode ss tmp total_len txt_opt typ OutStr)
  (vl-load-com)
  ;|
     mode
   An integer specifying the linear units mode. The mode corresponds to the
     values allowed for the AutoCAD system variable lunits and can be one of
     the following numbers:
   1  Scientific
   2  Decimal
   3  Engineering (feet and decimal inches)
   4  Architectural (feet and fractional inches)
   5  Fractional
   nil  default to DWG settings
  |;
  (setq mode 4)
 
  (defun put_txt (txt / pt th)
    ;;  Check if the drawing height is set to 0:
    (if (setq pt (getpoint "\nPick Text Location..."))
     (progn
      (if (= 0 (setq th (cdr (assoc 40 (tblsearch "style"  (getvar "textstyle"))))))
        (setq th (getvar "textsize"))
      )
      (entmake (list (cons 0 "TEXT")
               (cons 1 txt)
               (cons 7 (getvar "textstyle"))
               (cons 10 pt)
               (cons 40 th)
      ))
     )
      (prompt "\n***  Text Insert skipped  ***")
    )
  )

  (initget "Yes No" )
  (setq txt_opt (getkword "\nPut text total in drawing [Yes/No]. <No>"))
  (or txt_opt (setq txt_opt "No"))

  (initget "Yes No" )
  (setq cur_opt (getkword "\nCurrent Space Only? [Yes/No] No for entire DWG. <Yes>"))
  (or cur_opt (setq cur_opt "Yes"))

  (prompt "\nSelect object(s) for layer filter.")
  (if (setq ss (ssget))
    (progn
      (setq tmp (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
            tmp (mapcar '(lambda(x) (cdr(assoc 8 (entget x)))) tmp)
            layFilter "")
      (mapcar '(lambda(x) (setq layFilter (strcat x "," layFilter))) tmp)
      (setq ent_allowed '("LINE" "LWPOLYLINE" "POLYLINE" "SPLINE" "ARC" "CIRCLE"))
       (setq Filter
        '((-4 . "<or") (0 . "LINE") (0 . "CIRCLE") (0 . "ARC")
                  (-4 . "<and") (0 . "*POLYLINE") ; include LWPolylines CAB 11.28.08
                    (-4 . "<not") (-4 . "&") (70 . 80) ; exclude mesh
                    (-4 . "not>")
                  (-4 . "and>")
               (-4 . "or>")
             )
      )
      (setq Filter (append Filter (list(cons 8 layFilter))))
      (if (= cur_opt "Yes")
        (setq Filter (cons (cons 410 (getvar "ctab")) Filter))
      )
      (if (setq ss (ssget "_X" Filter))
        (progn
          (setq entlst (mapcar 'cadr (ssnamex ss))
                total_len 0)
          (foreach en entlst
            (if (vl-position (setq typ (cdr (assoc 0 (entget en)))) ent_allowed)
              (setq len (vlax-curve-getdistatparam en (vlax-curve-getendparam en))
                    total_len (+ len total_len))
            )
          )
        )
        (prompt "\n***  Nothing on that layer with a length.  ***")
      )
    )
  )
  (and total_len (not (zerop total_len))
       (setq OutStr (strcat "Total length is " (if mode (rtos total_len mode)(rtos total_len))))
       (princ (strcat "\n" OutStr)) ; display on command line
       (if (= txt_opt "Yes") (put_txt OutStr))
  )
  (princ)
)
(prompt "\nGet Length By Layer loaded, Enter LBL to run")
(princ)

Neat but, Suggestions: 1) how does one indicate what layer the length total is needed? 2)  Maybe a "switch" indicating which lunit the user prefers, right now the answer is Arch (lunit 3),  we use lunit of 2, 99% of time.
thx, steveo
Can't remember what I'm supposed to forget.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: lisp not working in AC2008
« Reply #6 on: November 30, 2008, 06:48:21 PM »
To change the units, change this line:
Code: [Select]
(setq mode 4)to this
Code: [Select]
(setq mode 2)on second thought change it to this:
Code: [Select]
(setq mode (getvar "LUNITS"))
At this prompt:
Quote
Select object(s) for layer filter.
The layer of anything you select will be used as the layer filter.

If you answered Yes to this prompt:
Quote
Current Space Only?
All objects in the current space matching the layer filter are used to get the total length.

This version will get current space objects or entire DWG objects on matching layer.
Perhaps I should modify the interface to allow user selected or all in current space or all in DWG.
« Last Edit: November 30, 2008, 06:54:09 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

stevesfr

  • Newt
  • Posts: 54
Re: lisp not working in AC2008
« Reply #7 on: November 30, 2008, 07:37:34 PM »
To change the units, change this line:
Code: [Select]
(setq mode 4)to this
Code: [Select]
(setq mode 2)on second thought change it to this:
Code: [Select]
(setq mode (getvar "LUNITS"))
At this prompt:
Quote
Select object(s) for layer filter.
The layer of anything you select will be used as the layer filter.

At the moment, this is true for those who know what they are doing, I think it would be better if you forced the user to input the layer which they need the "length totals" from.  Confusion could arise when two or more colors are used on one layer (for whatever reason).  Some "newbees" think you can't do anything unless the layer in question is current.  Just more of my two cents. 

If you answered Yes to this prompt:
Quote
Current Space Only?
All objects in the current space matching the layer filter are used to get the total length.

This version will get current space objects or entire DWG objects on matching layer.
Perhaps I should modify the interface to allow user selected or all in current space or all in DWG.

Can't remember what I'm supposed to forget.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: lisp not working in AC2008
« Reply #8 on: November 30, 2008, 07:51:54 PM »
At the moment, this is true for those who know what they are doing, I think it would be better if you forced the user to input the layer which they need the "length totals" from.  Confusion could arise when two or more colors are used on one layer (for whatever reason).  Some "newbees" think you can't do anything unless the layer in question is current.  Just more of my two cents. 
The routine was for a particular user & it fit there needs.
I agree that the user should also be able to enter the layer names with wild card characters too.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

stevesfr

  • Newt
  • Posts: 54
Re: lisp not working in AC2008
« Reply #9 on: November 30, 2008, 08:40:20 PM »
At the moment, this is true for those who know what they are doing, I think it would be better if you forced the user to input the layer which they need the "length totals" from.  Confusion could arise when two or more colors are used on one layer (for whatever reason).  Some "newbees" think you can't do anything unless the layer in question is current.  Just more of my two cents. 
The routine was for a particular user & it fit there needs.
I agree that the user should also be able to enter the layer names with wild card characters too.

So Be It.  Thanks for all....
Can't remember what I'm supposed to forget.