Author Topic: I butchered another one  (Read 2757 times)

0 Members and 1 Guest are viewing this topic.

Biscuits

  • Swamp Rat
  • Posts: 502
I butchered another one
« on: January 04, 2007, 01:20:05 PM »
Still using ACAD2002...should be getting ACAD2007....probably in 2009

Here's my next lame attempt to modify a lisp file.
This routine asks the user to select a part, select any holes, oblongs, or cutouts, and provide the gauge used for the metal blank. The routine does all the math and posts the results to the command line in the form of area, laser (perimeter), and weight.
Been working great until I got ahold of it.
Now that we have begun to cut text (polylines... not real text or font) into our parts, I've been asked to modify this file to allow the user to make an additional selection for the laser-cut-text which would then be added to perimeter value with no change to area.

It worked fine until I got ahold of it.
Here's the error message I get:

Select objects:
; error: bad argument type: lselsetp 0


My major changes fall between the ";-----------------------"


Quote

(defun C:wla (/ HA HP THA THP PA PP TPA TPP GA W CIR SSL NSSET TEMP CTR ENT LZRA LZRP)

(setvar "cmdecho" 0)

; Isolates the DWG layer
  (princ)
  (command "layer" "off" "*" "y" "")
  (command "layer" "on" "dwg" "")
  (command "layer" "on" "cnc" "")

; The following clears all previous variables

(setq HA 0.00)     ; Hole area
(setq HP 0.00)     ; Hole perimeter
(setq THA 0.00)   ; Total hole area
(setq THP 0.00)   ; Total hole perimeter
(setq PA 0.00)     ; Part area
(setq PP 0.00)     ; Part perimeter
(setq TPA 0.00)   ; Total part area
(setq TPP 0.00)   ; Total part perimeter
(setq GA 0.00)     ; Gauge of the part
(setq W 0.00)      ; Weight of the part
(setq LZRA 0.00) ; Laser Text Area
(setq LZRP 0.00) ; Laser Text Perimeter


; Gets the parts area and perimeter

    (princ "\n\n Select the part: ")
    (command "area" "o" pause)
  (setq PA (getvar "area"))
  (setq PP (getvar "perimeter"))

   (princ)
     (princ "\n\n Part Area = ")(princ PA)
     (princ "\t Part Perimeter = ")(princ PP)
   (princ)


; Selects the holes in the part and calculates the area and perimeter

  (prompt "\n\n Select all holes on the part:")
  (setq CIR (ssget))

 (if CIR
 (progn
  (setq SSL   (sslength CIR)
        NSSET (ssadd)
  ) ;_ end of setq

  (while (> SSL 0.00)
    (setq TEMP (ssname CIR (setq SSL (1- SSL))))
      (ssadd TEMP NSSET)
  ) ;_ end of while

  (setq SSL (sslength NSSET)
        CIR NSSET
  ) ;_ end of setq

  (setq CTR 0)

  (while
    (setq ENT (ssname CIR CTR))
      (command "area" "o" ENT)
    (setq HA (getvar "area"))
    (setq HP (getvar "perimeter"))
     (setq THA (+ THA HA))
     (setq THP (+ THP HP))
     (setq CTR (+ 1 CTR))
  ) ;_ end of while

 (princ"   Done...  ")) ;_end of progn
(princ"    Nothing selected.  ")) ;_end of if

  (princ)
     (princ "\n\n Hole Area = ")(princ THA)
     (princ "\t Hole Perimeter = ")(princ THP)
     (print SSL)
     (princ "hole entities found. ")
  (princ)
;---------------------------------------------------------------------------------------------------------------

  (prompt "\n\n Select all Laser Text:")
  (setq LZRTXT (ssget))

 (if LZRTXT
 (progn
  (setq SSLL   (sslength LZRTXT)
        NNSSET (ssadd)
  ) ;_ end of setq

  (while (> SSLL 0.00)
    (setq TTEMP (ssname LZRTXT (setq SSLL (1- SSLL))))
      (ssadd TTEMP NNSSET)
  ) ;_ end of while

  (setq SSLL (sslength NNSSET)
        LZRTXT NNSSET
  ) ;_ end of setq

  (setq LZRTXT 0)

  (while
    (setq ENTT (ssname LZRTXT CTRR))
      (command "area" "o" ENTT)
 
    (setq LZRP (getvar "perimeter"))
     
     (setq LZRP (+ TLZRP LZRP))
     (setq CTRR (+ 1 CTRR))
  ) ;_ end of while

 (princ"   Done...  ")) ;_end of progn
(princ"    Nothing selected.  ")) ;_end of if

  (princ)
   
     (princ "\t Laser Text Perimeter = ")(princ TLZRP)
     (print SSLL)
     (princ "Laser Text entities found. ")
  (princ)

;----------------------------------------------------------------------------------------------------------------
; The following takes the total hole area and subtracts from the part area then
; calculates the total part area. Also takes the total hole perimeter and adds to
; the part perimeter then calculates the total part perimeter.

  (setq TPA (- PA THA))
  (setq TPP (+ PP THP TLZRP))


; Turns all the layers back on

  (command "layer" "on" "*" "")
  (command "layer" "u" "*" "")
  (command "layer" "t" "*" "")

; The following gets the gauge of the part and sets it to decimal thickness

    (initget (+ 1 2 4))
    (setq GA (getint "\n\n What is the gauge of the part?: "))

        (IF
     (= GA 10)
     (setq GA 0.1345)
     (setq GA GA)
        )
        (IF
     (= GA 11)
       (setq GA 0.1196)
          (setq GA GA)
   )
   (IF
     (= GA 12)
     (setq GA 0.1046)
     (setq GA GA)
   )
   (IF
     (= GA 13)
       (setq GA 0.0897)
     (setq GA GA)
   )
   (IF
     (= GA 14)
     (setq GA 0.0747)
     (setq GA GA)
   )
   (IF
     (= GA 15)
     (setq GA 0.0673)
     (setq GA GA)
   )
   (IF
     (= GA 16)
     (setq GA 0.0598)
     (setq GA GA)
   )
   (IF
     (= GA 17)
     (setq GA 0.0538)
     (setq GA GA)
   )
   (IF
     (= GA 18)
     (setq GA 0.0478)
     (setq GA GA)
   )
   (IF
     (= GA 19)
     (setq GA 0.0418)
     (setq GA GA)
   )
   (IF
     (= GA 20)
     (setq GA 0.0359)
     (setq GA GA)
   )
   (IF
     (= GA 21)
     (setq GA 0.0329)
     (setq GA GA)
   )
   (IF
     (= GA 22)
     (setq GA 0.0299)
     (setq GA GA)
   )
   (IF
     (= GA 23)
     (setq GA 0.0269)
     (setq GA GA)
   )
   (IF
     (= GA 24)
     (setq GA 0.0239)
     (setq GA GA)
   )

; Calculates the weight of the part

   (setq W (* TPA GA 0.2833))
     (setq W (rtos W 2 4))
     (setq TPA (rtos TPA 2 4))
     (setq TPP (rtos TPP 2 4))

; The following prints answer to the command prompt

  (princ)
  (princ "\n\nWEIGHT: ")(princ W)
  (princ "\n\nLASER: ")(princ TPP)
  (princ "\nAREA: ")(princ TPA)
  (princ)


) ; end of program



Any help would be greatly appreciated

Jeff_M

  • King Gator
  • Posts: 4098
  • C3D user & customizer
Re: I butchered another one
« Reply #1 on: January 04, 2007, 01:52:51 PM »
I think this is your problem:
Code: [Select]
(setq LZRTXT 0)should be
Code: [Select]
(setq CTRR 0)

Biscuits

  • Swamp Rat
  • Posts: 502
Re: I butchered another one
« Reply #2 on: January 04, 2007, 02:07:43 PM »
Tried it Jeff.

Now I get:

; error: bad argument type: numberp: nil

Jeff_M

  • King Gator
  • Posts: 4098
  • C3D user & customizer
Re: I butchered another one
« Reply #3 on: January 04, 2007, 02:18:14 PM »
You intialized the Total Area & Total Perim. for the LZR cuts, but I think you used the wrong Variables. SO when this line:
(setq LZRP (+ TLZRP LZRP))
executes TLZRP is not set to anything which raises the error.

Arizona

  • Guest
Re: I butchered another one
« Reply #4 on: January 04, 2007, 02:48:23 PM »
Been working great until I got ahold of it.

Before you ever modify a program, form, etc... create a backup!!!
Give your self a way back to where you were... :-)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: I butchered another one
« Reply #5 on: January 04, 2007, 03:45:03 PM »
Here is a version for you to try.

You will need to updat to your layers here:
Code: [Select]
  ;;  Layers for filter
  (setq PartLayer  "cncPart"
        HolesLayer "Holes"
        LTextlayer "lazerText"
  )
« Last Edit: January 04, 2007, 03:46:26 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.

Biscuits

  • Swamp Rat
  • Posts: 502
Re: I butchered another one
« Reply #6 on: January 04, 2007, 03:46:07 PM »
Thanks Jeff. Not working just yet. Getting closer though. Gonna go get a good night sleep, step through it tomorrow, and see if I can figure out what else is wrong.

Arizona, I've got the original (always keep one). Just struggling to get it modified.

Probably bug you guys again tomorrow.

Thanks

Biscuits

  • Swamp Rat
  • Posts: 502
Re: I butchered another one
« Reply #7 on: January 05, 2007, 11:04:51 AM »
I just want to thank everyone for their input. I got this routine working. It's amazing what you can accomplish with a good night's sleep and a couple cups of coffee in the morning.

The problem was with one of the variables. I think I overlooked (setvar PEBKAC "off")

Thanks again