wannabe Posted December 24, 2008 Posted December 24, 2008 It's telling me the four blocks have inserted, but I can't see them. If the code works then it looks like I've incorrectly supplied the file location of my block. I tell you what though, mate. If you could make the block selectable via the dialog menu in the same way the text file is selected that would enhance this routine immensely. If you could also tell me how I need to correctly format the line where my block's file location goes that would be great, too. (defun c:ITREE (/ *error* file1 blk pts) (defun *error* (msg) (setvar "cmdecho" 1) (if (= msg "") (princ (strcat (itoa blk) " Blocks Inserted.")) (princ "\nError or Esc Pressed.") ) ;_ end if ) ;_ end defun (selfile) (setvar "cmdecho" 0) (setq file1 (open file "r") blk 0 ) ;_ end setq (while (/= (setq pts (read-line file1)) nil) (command "-insert" "C:Documents and Settings\39925nt\My Documents\Nick's CAD\Blocks" pts "" "" "0") ;_ end command (setq blk (1+ blk)) ) ;_ end while (*error* "") (close file1) (princ) ) ;_ end defun (defun selfile () (setq file (getfiled "Select a Text File" "C:\\" "txt" 9 ) ;_ end getfiled ) ;_ end setq ) ;_ end defunRemember to Insert the Quote
wannabe Posted December 24, 2008 Posted December 24, 2008 I can see my own problem. I didn't actually specify the full file location to the block itself. Quote
wannabe Posted December 24, 2008 Posted December 24, 2008 Well my block is called North1. When I suffixed that onto the file location in the above code it said invalid block name. Quote
Lee Mac Posted December 24, 2008 Posted December 24, 2008 When you specify a filepath, you will need to fomat it like the example below: C:\\Users\\Lee Mac\\Documents\\Block1.dwg Using the double backslashes and also specifying the filepath all the way down to the block name. I'll have a work on it and see if I can work it with the dialog box Quote
Lee Mac Posted December 24, 2008 Posted December 24, 2008 That should work for now: (defun c:ITREE (/ *error* file1 blk pts) (defun *error* (msg) (setvar "cmdecho" 1) (if (= msg "") (princ (strcat (itoa blk) " Blocks Inserted.")) (princ "\nError or Esc Pressed.") ) ;_ end if ) ;_ end defun (selfile) (setvar "cmdecho" 0) (setq file1 (open file "r") blk 0 ) ;_ end setq (while (/= (setq pts (read-line file1)) nil) (command "-insert" "C:\\Documents and Settings\\39925nt\\My Documents\\Nick's CAD\\Blocks\\North1.dwg" pts "" "" "0") ;_ end command (setq blk (1+ blk)) ) ;_ end while (*error* "") (close file1) (princ) ) ;_ end defun (defun selfile () (setq file (getfiled "Select a Text File" "C:\\" "txt" 9 ) ;_ end getfiled ) ;_ end setq ) ;_ end defun Quote
wannabe Posted December 24, 2008 Posted December 24, 2008 Excellent job, mate. Have yourself a mince pie and a pork sandwich (only when the block is selectable via dialog box, mind ). No, that's great as it is. Maybe I can return the favour when I'm upto speed with .NET. Quote
Lee Mac Posted December 24, 2008 Posted December 24, 2008 Ok, try this: (defun c:ITREE (/ *error* file1 blk blkfile pts) (defun *error* (msg) (setvar "cmdecho" 1) (if (= msg "") (princ (strcat (itoa blk) " Blocks Inserted.")) (princ "\nError or Esc Pressed.") ) ;_ end if ) ;_ end defun (selfile) (blocksel) (setvar "cmdecho" 0) (setq file1 (open file "r") blk 0 ) ;_ end setq (while (/= (setq pts (read-line file1)) nil) (command "-insert" blkfile pts "1" "1" "0") ;_ end command (setq blk (1+ blk)) ) ;_ end while (*error* "") (close file1) (princ) ) ;_ end defun (defun selfile () (setq file (getfiled "Select a Text File" "C:\\Documents and Settings\\39925nt\\My Documents\\Nick's CAD" "txt" 8 ) ;_ end getfiled ) ;_ end setq ) ;_ end defun (defun blocksel () (setq blkfile (getfiled "Select a Block" "C:\\Documents and Settings\\39925nt\\My Documents\\Nick's CAD\\Blocks" "dwg" 8 ) ;_ end getfiled ) ;_ end setq ) ;_ end defun Quote
wannabe Posted December 24, 2008 Posted December 24, 2008 Nice work again. I hope Santa gives you a nice new Ferrari. Quote
Lee Mac Posted December 24, 2008 Posted December 24, 2008 Nice work again. I hope Santa gives you a nice new Ferrari. Haha that'll be the day Merry Christmas to you too Quote
ScribbleJ Posted December 30, 2008 Author Posted December 30, 2008 Ok Lee I had some time to give this Lisp a test run. I ran the very last one shown and here is the results. Block Tree references itself *Invalid* Just wanted to give you an update. I am going to try to figure out the problem myself but if you do squash this bug I would be very interested to see the solution. I'm really getting a handle on Lisp now. I'm starting to feel somewhat smarter now. What I don't understand is why it references itself. It is not in the dwg file. I'm starting it from scratch. Quote
Lee Mac Posted December 30, 2008 Posted December 30, 2008 Hi Scribs does the tree block have any attributes? Cheers Lee EDIT: Only reason I put this point forward is that Wannabe could make the LISP function correctly with his blocks, therefore it leads me to think that there is something inherent in your block to cause the error - usually another block combined with itself to form the final block - or a dodgy attribute. Quote
Lee Mac Posted December 31, 2008 Posted December 31, 2008 Final Update: (Updated the Error Handler) (defun c:ITREE (/ *error* file file1 blk blkfile pts) (defun *error* (msg) (setvar "cmdecho" 1) (if (= msg "") (princ (strcat (itoa blk) " Blocks Inserted.")) (princ (strcat "\n" (strcase msg))) ) ;_ end if ) ;_ end defun (selfile) (blocksel) (setvar "cmdecho" 0) (setq file1 (open file "r") blk 0 ) ;_ end setq (while (/= (setq pts (read-line file1)) nil) (command "-insert" blkfile pts "1" "1" "0") (setq blk (1+ blk)) ) ;_ end while (*error* "") (close file1) (princ) ) ;_ end defun (defun selfile () (setq file (getfiled "Select a Text File" "C:\\" "txt" 8 ) ;_ end getfiled ) ;_ end setq ) ;_ end defun (defun blocksel () (setq blkfile (getfiled "Select a Block" "C:\\" "dwg" 8 ) ;_ end getfiled ) ;_ end setq ) ;_ end defun Quote
ScribbleJ Posted January 2, 2009 Author Posted January 2, 2009 Hi Scribs does the tree block have any attributes? Cheers Lee EDIT: Only reason I put this point forward is that Wannabe could make the LISP function correctly with his blocks, therefore it leads me to think that there is something inherent in your block to cause the error - usually another block combined with itself to form the final block - or a dodgy attribute. I will check this out. I thought I had a vanilla tasting block but I'm not 100% certain. Time: 20:10 Just checked (15 minutes after the original post). It is a plain 'ole vanilla tasting block. I'm running some more test at the time of this posting. Gotta love VPN. Time: 20:36 Ok I did another test run and it worked perfectly. Thank you billionz of times over. EUREKA! Quote
Lee Mac Posted January 2, 2009 Posted January 2, 2009 Excellent! Glad you got it working Scribs - Enjoy your day Quote
wannabe Posted January 5, 2009 Posted January 5, 2009 Lee Mac, or anyone else, what do you think about this?: Is there any way that we can add one more function to this routine? Basically I am delighted that I can specify a block, point to an excel list of coordinates and then my job is done.... But, my job isn't exactly done. What would be amazing, is, if the lisp would also look at the coordinate list and notice that before the actual coordinates is a text string that represents the identification number for that block. If the identification could then populate an attribute in my block called I.D, that would be immense and save me a lot of time. Not a problem if it can't be done. But a big help if it can. Cheers. Quote
Lee Mac Posted January 5, 2009 Posted January 5, 2009 I suppose it would be easier if you had the attribute on either the line above or below the coordinates - then you could just perform the read-line alternately and read coordinate then attribute and so on so on.. Quote
Lee Mac Posted January 5, 2009 Posted January 5, 2009 If it was indeed the case that the attribute was on a new line, and was prompted for when the block was inserted, this may work (defun c:ITREE (/ *error* file file1 blk blkfile pts) (defun *error* (msg) (setvar "cmdecho" 1) (if (= msg "") (princ (strcat (itoa blk) " Blocks Inserted.")) (princ (strcat "\n" (strcase msg))) ) ;_ end if ) ;_ end defun (selfile) (blocksel) (setvar "cmdecho" 0) (setq file1 (open file "r") blk 0 ) ;_ end setq (while (or (/= (setq pts (read-line file1)) nil) (/= (setq atrib (read-line file1)) nil) ) ;_ end or (command "-insert" blkfile pts "1" "1" "0" atrib) (setq blk (1+ blk)) ) ;_ end while (*error* "") (close file1) (princ) ) ;_ end defun (defun selfile () (setq file (getfiled "Select a Text File" "C:\\" "txt" 8 ) ;_ end getfiled ) ;_ end setq ) ;_ end defun (defun blocksel () (setq blkfile (getfiled "Select a Block" "C:\\" "dwg" 8 ) ;_ end getfiled ) ;_ end setq ) ;_ end defun Only a quick work-around - haven't thought about this one much. Quote
wannabe Posted January 5, 2009 Posted January 5, 2009 A few bites to eat and I'll let you know. Either way, thanks for taking the time, Lee. Quote
Lee Mac Posted January 5, 2009 Posted January 5, 2009 No probs, I'd be intrigued to hear the results Quote
wannabe Posted January 5, 2009 Posted January 5, 2009 It came up with a function cancelled error message and then acted in the normal block insertion manner (via the command line). Attached are the text file and one of the blocks I would be using with the previously mentioned I.D attributes, incase this helps anyone to solve the problems. samppy.txt Proposed Borehole - Red10.dwg 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.