DVDM Posted September 11, 2008 Share Posted September 11, 2008 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) (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) ) '() ) Thanks for reading Quote Link to comment Share on other sites More sharing options...
CarlB Posted September 13, 2008 Share Posted September 13, 2008 Try this: ;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) ) ) Quote Link to comment Share on other sites More sharing options...
DVDM Posted September 15, 2008 Author Share Posted September 15, 2008 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. Quote Link to comment Share on other sites More sharing options...
DVDM Posted September 15, 2008 Author Share Posted September 15, 2008 *duplicate entry removed* Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.