jjatho Posted May 2, 2013 Posted May 2, 2013 I'm not sure why, but cond is being ignored in this code. The idea is to make all sheet numbers three digits, so 001, 020, 100, etc. (setq sheetnumber 1) (foreach tab (_layoutlist) (setq row 0) (setq column (+ column 1)) (princ "Test 1\n") (cond (> sheetnumber 99)( (setq sheetnumber (itoa sheetnumber))) (> sheetnumber 9)( (setq sheetnumber (itoa (strcat "0" (itoa sheetnumber))))) (> sheetnumber 0)( (setq sheetnumber (itoa (strcat "00" (itoa sheetnumber))))) ) (setq sheetnumber (itoa sheetnumber));Remove this when possible. (vla-setCellValue table column row sheetnumber) (setq newname (strcat sheetnumber "-" (substr tab 5 50))) (setq sheetnumber (atoi sheetnumber)) (setq sheetnumber (+ sheetnumber 1)) (setq row 1) (setvar 'ctab tab) (setq tab (substr tab 5 50)) (vla-setCellValue table column row tab) (command "-layout" "R" "" newname) ) Quote
MSasu Posted May 2, 2013 Posted May 2, 2013 I made some corrections to your syntax: (cond [color=red]([/color](> sheetnumber 99)[color=red][s]([/s][/color] (setq sheetnumber (itoa sheetnumber))) [color=red]([/color](> sheetnumber 9)[color=red][s]([/s][/color] (setq sheetnumber [color=red][s](itoa[/s][/color] (strcat "0" (itoa sheetnumber))[color=red][s])[/s][/color])) [color=red]([/color](> sheetnumber 0)[color=red][s]([/s][/color] (setq sheetnumber [color=red][s](itoa[/s][/color] (strcat "00" (itoa sheetnumber))[color=red][s])[/s][/color])) ) Quote
Lee Mac Posted May 2, 2013 Posted May 2, 2013 If you aren't already doing so, I would strongly recommend that you refer to the AutoLISP Developer Documentation to understand the correct syntax, arguments and returns for AutoLISP functions. Here is the documentation for the cond function: http://exchange.autodesk.com/autocad/enu/online-help/browse#WS1a9193826455f5ff1a32d8d10ebc6b7ccc-6a7a.htm Here is a link to the main documentation: http://exchange.autodesk.com/autocad/enu/online-help/browse#WS73099cc142f48755a52158612bd434e551-7fe9.htm Here is a tutorial explaining how to access this documentation from within the Visual LISP IDE (VLIDE): http://lee-mac.com/functioninfo.html Quote
jjatho Posted May 2, 2013 Author Posted May 2, 2013 To MSasu: Lee Mac, I'm gradually learning but I seem to learn programming languages much better from actual books rather than online tutorials. Not sure why. Can you recommend a good book? Quote
MSasu Posted May 2, 2013 Posted May 2, 2013 Jjatho, we are all here to learn, so it would be more interesting to know if the changes I proposed to your code are what you were looking for and if you understood them. Quote
jjatho Posted May 2, 2013 Author Posted May 2, 2013 It sure did. Here's the full code from what I was working on today. Your help put the finishing touch on the behavior I was looking for. (defun _layoutlist (/ layouts) ;; List of layouts (VLA-Objects) in drawing (in correct order) ;; Alan J. Thompson, 10.05.09 (setq layouts (vla-get-layouts (cond (*AcadDoc*) ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object)))) ) ) ) (vl-sort (layoutlist) (function (lambda (a b) (< (vla-get-taborder (vla-item layouts a)) (vla-get-taborder (vla-item layouts b)) ) ) ) ) ) (defun C:DIRECTORY() (setq sheetcount (length (layoutlist))) ;Gives count of paper space sheets (setq directorysheetcount (itoa sheetcount)) (setq location (list -1.75 ) (command "-table" "2" sheetcount location) ;Creates table. ; Note that the variable sheetcount corresponds with the number of data rows ; a title and header row will be created above the data rows. (setq EN (entlast)) (setq table (vlax-ename->vla-object EN)) (setq column 0) (setq row 0) (vla-setCellValue table column row "Contents") (setq column 1) (setq row 0) (vla-setCellValue table column row "Sheet") (setq column 1) (setq row 1) (vla-setCellValue table column row "Description") (setq sheetnumber 1) (foreach tab (_layoutlist) (setq row 0) (setq column (+ column 1)) (princ "Test 1\n") (cond ((> sheetnumber 99) (setq sheetnumber (itoa sheetnumber))) ((> sheetnumber 9) (setq sheetnumber (strcat "0" (itoa sheetnumber)))) ((> sheetnumber 0) (setq sheetnumber (strcat "00" (itoa sheetnumber)))) ) (vla-setCellValue table column row sheetnumber) (setq newname (strcat sheetnumber "-" (substr tab 5 50))) (setq sheetnumber (atoi sheetnumber)) (setq sheetnumber (+ sheetnumber 1)) (setq row 1) (setvar 'ctab tab) (setq tab (substr tab 5 50)) (vla-setCellValue table column row tab) (command "-layout" "R" "" newname) ) (setq titlepage (car (_layoutlist))) (setvar 'ctab (car (_layoutlist))) (princ) ) ;End defun DIRECTORY Quote
neophoible Posted May 3, 2013 Posted May 3, 2013 Lee Mac, I'm gradually learning but I seem to learn programming languages much better from actual books rather than online tutorials. Not sure why. Can you recommend a good book?You should really take a look at and bookmark Lee Mac's links. The tutorial is just on how to access another way. The links are mainly for quick reference. If you have them, then you can quickly check the syntax of a function. In the case of LISP, you will definitely want to look at how your parentheses are arranged. It is essential if you want your program to work. Quote
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.