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