Try this:
Code:;The next 4 lines I want to bypass when number of rows is 1 (if (/= row 1) (if (= col 1) (command "array" sel "" "r" row 1 dy) (command "array" sel "" "r" row col dy dx) ) )


Registered forum members do not see this ad.
Hi all,
I've recently been asked to fix up some of our lisp routines that have been in use at my work for the past 10+ years. Problem is, my lisp knowledge is fairly limited, and while I've been able to touch up quite a few routines by trying to make sense of the code along with some trail and error, I've now come across a routine that no amount of tinkering on my behalf can fix.
It's a routine that creates a material list by asking the user for the number of columns (default 1), and number of rows (default 20), then constructs a table consisting of a header block (matlhd), a material disciption line block(matlitem), and a total mass block (matltot).
The problem occurs when you want to create a single line material list, it returns an error because of the way the table is constructed using an array. An array of 1 isn't an array obviously. That leaves you with an incomplete table without the total mass block.
I need to find a way to bypass the section of code where it creates an array for the rows when the user wants just one row, but I'm now lost as to how. If I remove this code, it actually works perfect for a 1 row table, but no longer works for multiline tables.
It has to be simple for someone with some more in depth lisp knowledge, so I thought I'd try my luck over here, as this forum has helped me on many previous occasions.
This is the code: (it's a 12 y/o file, and unfortunately there are no credits in the file)
Thanks for readingCode:(apply '(lambda (/ b c d dx dy cmd att lay col row pt1 ptx pty pt2 sel) (princ "\nInsert Material List") (setq cmd (getvar "cmdecho")) (setq att (getvar "attdia")) (setvar "cmdecho" 0) (setvar "attdia" 0) (setq lay (getvar "clayer")) (setvar "clayer" "0") (setq b (getvar "dimscale")) (setq c (getvar "tilemode")) (if (= c 1 )(setq d b)(setq d 1)) (setq col (getint "\nNumber of columns<1>: ")) (if (null col)(setq col 1)) (setq row (getint "\nNumber of rows<20>: ")) (if (null row)(setq row 20)) (setq pt1 (getpoint "\nInsertion point...")) (setq ptx (car pt1)) (setq pty (cadr pt1)) (setq dx (* d -200)) (setq dy (* d -7)) (setq pt2 (list (+ ptx dx)(+ pty dy))) (command "insert" "matlhd" pt1 d d "0") (setq sel (ssget "L")) (if (/= col 1) (command "array" sel "" "r" 1 col dx) ) (command "insert" "matlitem" pt2 d d "0") (setq sel (ssget "L")) ;The next 4 lines I want to bypass when number of rows is 1 (if (= col 1) (command "array" sel "" "r" row 1 dy) (command "array" sel "" "r" row col dy dx) ) (setq pt3 (list ptx (+ pty (* d (* -7 (+ 1 row)))))) (command "insert" "matltot" pt3 d d "0") (setvar "cmdecho" cmd) (setvar "clayer" lay) (setvar "attdia" att) (princ) ) '() )![]()




Try this:
Code:;The next 4 lines I want to bypass when number of rows is 1 (if (/= row 1) (if (= col 1) (command "array" sel "" "r" row 1 dy) (command "array" sel "" "r" row col dy dx) ) )


Thanks Carl, that works great.
I had previously made several attempts to insert a 'if (/= row 1)' line somewhere in the code, but I guess I got the placement wrong.


Registered forum members do not see this ad.
*duplicate entry removed*
Bookmarks