Agent 31 Posted October 13, 2010 Posted October 13, 2010 Hey all, I have a quick question. I apologize if this has already been asked, but I can not find it myself. I have searched other spots, but its hard if the thread does not specifically deal with your question. My problem is, we have a LISP routine at my company. After you get all of the information from the user, it will insert a block in a specific arrangement in a specific amount. Like, insert blah blah blah 3 times downward 1 inch apart. Everything works fine, but the problem is is that the block HAS to be in the drawing, otherwise the routine fails. If you run it while the block is IN the drawing, it runs fine, no problems. Help?! I have scoured different ways to have it insert the blocks, but no combination seems to work. Here is the line for inserting the block, any ideas? (command "insert" "terminal" (polar #pt1 1.570796327 0.125) "" "" "") Quote
asos2000 Posted October 13, 2010 Posted October 13, 2010 Up to my knowladge You have 2 solutions - Create the block itself (to be a subroutine in the lisp) - Insert the block then use the lisp * Add a code to insert the block * Using Design Center * Creating a bottun and using macro Quote
Agent 31 Posted October 13, 2010 Author Posted October 13, 2010 Thank you for your reply, I appreciate the effort. I have a couple of quick questions in regards to your information. How would you insert the block using the LISP? Would you be able to insert the block, use the rest of the lisp, then delete the first block that was inserted so you do not have extras. That may be an option I suppose. As for the rest, the problem is is that it will not work WITHOUT having the block in the drawing. I want to avoid this, however, and be able to run the LISP routine in a brand new drawing without having to open an existing file. Does that make sense? I do like the option of inserting the block, running the lisp, then deleting the block. Any ideas how to automate this? Quote
asos2000 Posted October 13, 2010 Posted October 13, 2010 Could I ask Why do you use a lisp to insert the block You can do this using macro its easyer and better (at least for me) this is the macro what im using ^C^Cinsunits;4;-insert;C:/Blocks/Block.dwg;\\;0;explode;last;ddedit;last; [b]insunits;4 [/b] to be sure the unites in both drawings is the same [b]-insert;[/b] using insert command [b]C:/Blocks/Block.dwg;[/b][url="file://;0; %20arrangement/"][b][color=black]\\;0;[/color][/b][/url] The path and file [b]explode;last;[/b] explode the origen file to be able to insert again [b]ddedit;last;[/b] edit in case of the block has an attribute Quote
Agent 31 Posted October 13, 2010 Author Posted October 13, 2010 Well at the company I work for, we manufacture electrical equipment. 2/3rds of the drawings we create deal with wiring diagrams and schematics. A large chunk of that is in the form of terminal blocks. We have a set of 8 different LISP routines that all play nice together. The first of these is to create a set of these terminals so we can work off of. The terminals are pretty much a set of boxes, each containing a number. A round hatched circle is placed on each side and this acts as the connection point containing the xdata information for the rest of the routines we use. Example: You want 2 terminals. It creates 2 boxes, 1 and 2, and places 4 of the round blocks to the side of each one. Problem: This ONLY runs if you have the block in the drawing already. I need it to insert the drawing as a block in a stand alone drawing, and NOT have to have it previously in there. Usually what we do is take an older drawing, delete what we dont need then work from there. The concern is though, that if you want to create a brand new diagram from scratch, you can't. I am trying to figure out how to fix this. Does that make sense? Quote
David Bethel Posted October 13, 2010 Posted October 13, 2010 (command "insert" "terminal" (polar #pt1 1.570796327 0.125) "" "" "") If the block is a dwg file in the search path, then you can make the block table definition like this: (command "insert" "terminal") (command) If the block is simply defined in another drawing, the substitute the main dwg file name. -David Quote
David Bethel Posted October 13, 2010 Posted October 13, 2010 Well at the company I work for, we manufacture electrical equipment. 2/3rds of the drawings we create deal with wiring diagrams and schematics. A large chunk of that is in the form of terminal blocks. We have a set of 8 different LISP routines that all play nice together. The first of these is to create a set of these terminals so we can work off of. The terminals are pretty much a set of boxes, each containing a number. A round hatched circle is placed on each side and this acts as the connection point containing the xdata information for the rest of the routines we use. Example: You want 2 terminals. It creates 2 boxes, 1 and 2, and places 4 of the round blocks to the side of each one. Problem: This ONLY runs if you have the block in the drawing already. I need it to insert the drawing as a block in a stand alone drawing, and NOT have to have it previously in there. Usually what we do is take an older drawing, delete what we dont need then work from there. The concern is though, that if you want to create a brand new diagram from scratch, you can't. I am trying to figure out how to fix this. Does that make sense? Now that doesn't make sense....... Quote
alanjt Posted October 13, 2010 Posted October 13, 2010 If the block is a dwg file in the search path, then you can make the block table definition like this: (command "insert" "terminal") (command) If the block is simply defined in another drawing, the substitute the main dwg file name. -David or this: (command "insert" "terminal" nil) Quote
Lee Mac Posted October 13, 2010 Posted October 13, 2010 (edited) This is what I use to 'Force' a block definition: ;;---------------=={ Force Block Definition }==---------------;; ;; ;; ;; Ensures, if possible, that a block definition is present ;; ;; in a drawing. ;; ;;------------------------------------------------------------;; ;; Author: Lee McDonnell, June 2010 ;; ;; ;; ;; Copyright © 2010 by Lee McDonnell, All Rights Reserved. ;; ;; Contact: Lee Mac @ TheSwamp.org, CADTutor.net ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; block - block name or filename ;; ;;------------------------------------------------------------;; ;; Returns: Block name, else nil ;; ;;------------------------------------------------------------;; (defun LM:ForceBlockDefinition ( block / path ext base ) ;; © Lee Mac 2010 (setq path (vl-filename-directory block) ext (vl-filename-extension block) base (vl-filename-base block)) (or ext (setq ext ".dwg")) (or (eq "" path) (setq path (strcat path "\\"))) (cond ( (tblsearch "BLOCK" base) base ) ( (setq block (findfile (strcat path base ext))) (command "_.-insert" block) (command) base ) ) ) Can be supplied with block name, block name with extension, or full block filename. Edited October 14, 2010 by Lee Mac Quote
Agent 31 Posted October 13, 2010 Author Posted October 13, 2010 If anyone wants the full LISP I will be happy to send. There are 3 files, and they are all kept in the support directory of AutoCAD. The .lsp, the .dwg and the .dcl.... I was just wondering, David, but what doesnt make sense? I am including an image of what this LISP routine creates exactly, and a zoomed out version of just how extensively we use them. The yellow dots are the blocks I am trying to insert as a stand alone instead of having one already in the drawing. The point is, I can not get it to insert the yellow dot. While this is easy to correct, just copy one over to the drawing, run the lisp then delete it, I am looking for a way to do this in an automated fashion. This is to make it error proof so if someone who does not know the system is using the program, they will not have to worry about the ins and outs, they can just "click it and forget it". Quote
asos2000 Posted October 13, 2010 Posted October 13, 2010 Could you please upload these lisps And the blocks too to include these blocks in the lisp and upload for you again. Quote
Agent 31 Posted October 13, 2010 Author Posted October 13, 2010 Here are the 3 files (XBlock.lsp, ddxblock.dcl, terminal.dwg). Like I mentioned, I keep them ALL in the support directory. After you get everything set up, a few things to remember. The name is arbitrary. Keep it "CC" for all purposes. You CAN name it ABCDEFGHIJK..... if you so chose, but it does not matter. The default start is at 1, just enter 2 as the end. Again, this is arbitrary as long as the end is higher than the start. 1-10, 11-12, 22-99, does not matter. To review my problem, open the file "terminal.dwg", run the LISP and VIOLA! Now open a blank drawing and try it . . . Good luck. I am not used to these forums quite yet, as in I am still a newbie poster, so let me know if this does not upload. Cheers! XBLOCK.LSP TERMINAL.DWG ddxblock.dcl Quote
Lee Mac Posted October 13, 2010 Posted October 13, 2010 Hi Agent, A quick way to get the existing code to work would be to make sure that all the blocks it uses (i.e. Terminal.dwg) are in an AutoCAD Support Path. Support Paths can be found by typing 'Options' at the command line, then going to the 'Files' tab. Lee Quote
Agent 31 Posted October 14, 2010 Author Posted October 14, 2010 Thank you Lee, but they are... See first line of my last post... Quote
Lee Mac Posted October 14, 2010 Posted October 14, 2010 Hi Agent, I had a look over your posted code and rewrote it to hopefully function more robustly for you (it should also run a ton quicker). Let me know if you have any issues with it. Lee xblock-LM.lsp ddxblock-LM.dcl Quote
Se7en Posted October 14, 2010 Posted October 14, 2010 Lee, i believe your routine will toss a wobbly if the block can not be found. This is about as elaborate as i get when i am not intending for user interaction (allow the user to select folder, file, etc.) in my routines (and even this, i consider overkill most times --i.e. I usually fail the routine as fast as i can. Like in the last example below). However when i do design an app for user interaction you can count on having at least another hundred lines or so just to keep it somewhat bomb-proof. (defun blockp ( bn ) ;; ;; blockp ;; return ``location'' for a block search. ;; ;; if block is in dwg. returns ``dwg'' ;; if block is found in paths returns ;; ``path to dwg'' ;; if not found, returns ``nil'' (cond ((tblsearch "BLOCK" bn) 'dwg) ((findfile (strcat bn ".dwg")))) ) ( (lambda ( block-to-insert file-to-get-block-from ) (cond ( (or (tblsearch "BLOCK" block-to-insert) (ObjectDBX-copyblockfromdrawing file-to-get-block-from block-to-insert) ) (command "insert" block-to-insert PAUSE "" "") (while (eq (logand (getvar "CMDACTIVE")) 1) (command PAUSE)) ) ( T (princ "\n\nUnable to locate block")))) "BlockThatDoesntExistInDrawing" "c:\\Drawing.dwg") Quote
Se7en Posted October 14, 2010 Posted October 14, 2010 *whoa* You guys added a few more posts (or i didnt see the second page) on me while i was typing that ( ^^ )...sorry if im out of context now. Quote
Lee Mac Posted October 14, 2010 Posted October 14, 2010 *whoa* You guys added a few more posts (or i didnt see the second page) on me while i was typing that ( ^^ )...sorry if im out of context now. No worries, you are right though - there was a typo in my function posted earlier, I assumed vl-filename-extension returned "" for no extension (as vl-filename-directory does for no directory), but in fact it returns nil. Code updated. Lee Quote
Grant Posted October 15, 2010 Posted October 15, 2010 I am assuming the block is not in a Autocad search path so it cannot find it. I think all you need to do is to write block out the block to an Autocad search path (or make your own in options, Files tab, search file support path). This will make autocad search your drawing and when it does not find it there it should look in the search paths for Autocad and the ones you can create. Hope this helps Quote
Agent 31 Posted October 15, 2010 Author Posted October 15, 2010 Thank you all for the help. I will be away most of the day working on some other diagrams for work. I just wanted to let you know I have received everything. I have a quick question though, am I supposed to put that other code into Lee's? Just curious. But I will try and get around to trying these out sometime today and I will post a reply back. Thanks again for the help and I will see everyone later! 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.