TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Methodman on February 13, 2020, 05:57:20 AM
-
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/8337483 (https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/export-to-excel-table-all-objects-from-specific-layer/td-p/8337483)
Originally, 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)
-
If you stick with using mapcar try this (vl-remove 'nil )
'nil
(if (setq ss
(ssget "_X" ;(list '(0 . "*LINE") (cons 6 lineStyle)) (list '
(0 .
"LWPOLYLINE") (cons 8 layer
)) )
)
totalobj 0
)
(setq totalobj
(+ totalobj
(getcurvelength
(ssname ss index
)))) )
(list layer
(rtos totalobj
2)) ;(list linestyle (rtos totalObj 2)) )
)
)
linelist
)
)
)
-
Another one code:
(defun t1
(/ linelist selset layer
) (if (and (setq linelist '
("PIPE LENGTHS - PVC-100 DW" "PIPE LENGTHS - PVC-150 DW" "PIPE LENGTHS - PVC-225 DW")) ) ;_ end of strcat
) ;_ end of cons
) ;_ end of list
) ;_ end of ssget
) ;_ end of setq
) ;_ end setq
) ;_ end of repeat
) ;_ end of lambda
)
) ;_ end of setq
) ;_ end of and
(t 0.)
) ;_ end of cond
) ;_ end of +
) ;_ end of cons
linelist
) ;_ end of subst
) ;_ end of setq
) ;_ end of foreach
) ;_ end of apply
) ;_ end of princ
) ;_ end of progn
) ;_ end of if
) ;_ end of defun
-
I tried the first suggestion by ronjonp and it worked great!
Thank you very much for the help and the fast response. Perfect.
-
I tried the first suggestion by ronjonp and it worked great!
Thank you very much for the help and the fast response. Perfect.
Glad to help. :-)