I have a routine for generating an excel list of pipe lengths for each pipe diameter. Pipe lengths are plines, arcs etc. and I differentiate pipe diameters by putting them in different layers.
I started with a code found here:
https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/export-to-excel-table-all-objects-from-specific-layer/td-p/8337483Originally, the code searched for a predefined linestyle and gave a length output.
I have adjusted to search for predefined layers and give a length output. This works ok.
Issue is as follows:
- The layer list in the code results in the following error if it can't find *all* of the layers in the drawing: Command: TEST ; error: bad argument type: stringp nil
I understand the code is searching for all of the layers, and when even 1 of the layers doesn't exist in the drawing (ie. nil), it crashes the program and refuses to continue.
How can I tell it to ignore this error and continue the program despite this? Most of my drawings will only have 1 or 2 pipe diameters, rather than the list of 20 or so I will list in the program.
Thanks,
MM
(defun GetCurveLength (ent /)
(setq ent (vlax-ename->vla-object ent))
(vlax-curve-getDistAtParam
ent
(vlax-curve-getEndParam ent)
)
)
(setq lineList '(
"PIPE LENGTHS - PVC-100 DW"
"PIPE LENGTHS - PVC-150 DW"
"PIPE LENGTHS - PVC-225 DW"
)
)
(setq lineList
(mapcar
'(lambda (layer)
(if (setq
ss (ssget "_X"
;(list '(0 . "*LINE") (cons 6 lineStyle))
(list '(0 . "LWPOLYLINE") (cons 8 layer))
)
)
(progn
(setq index 0
totalObj 0
)
(repeat (sslength ss)
(setq totalObj
(+ totalObj (GetCurveLength (ssname ss index)))
)
(setq index (1+ index))
)
(list layer (rtos totalObj 2))
;(list linestyle (rtos totalObj 2))
)
)
)
lineList
)
)
(setq lineList (LM:insertnth
(list "Line List" "------------------")
0
lineList
)
)
(setq bom lineList)