caxtin Posted April 11, 2013 Posted April 11, 2013 I have spent the past three and quarter hours searching, finding, trying, modifying lisps and still not successful. Now I need some help! - I have this file 'EDL.DWG" located at "L:/AutoCAD/Template/EDL.dwg". - I have created a button in my personal toolbar. GOAL: 1. Pick the created toolbar button, 2. Pick desired insertion point, 3. That's it! After #2 level, the function escapes and back to where I was before. Thanks in advance Quote
Lee Mac Posted April 11, 2013 Posted April 11, 2013 Welcome to CADTutor caxtin Here is a very simple example for you: (defun c:myinsert ( / att blk ) (if (setq blk (findfile "L:/AutoCAD/Template/EDL.dwg")) (progn (setq att (getvar 'attreq)) (setvar 'attreq 0) (while (vl-cmdf "_.-insert" blk "_S" 1.0 "_R" 0.0 "\\")) (setvar 'attreq att) ) (princ "\nEDL.dwg not found.") ) (princ) ) Quote
caxtin Posted April 11, 2013 Author Posted April 11, 2013 Welcome to CADTutor caxtin Here is a very simple example for you: (defun c:myinsert ( / att blk ) (if (setq blk (findfile "L:/AutoCAD/Template/EDL.dwg")) (progn (setq att (getvar 'attreq)) (setvar 'attreq 0) (while (vl-cmdf "_.-insert" blk "_S" 1.0 "_R" 0.0 "\\")) (setvar 'attreq att) ) (princ "\nEDL.dwg not found.") ) (princ) ) Thanks for the code. Just one little thing. After running the code and selecting an insertion point, the block is still hanging on for me to re-insert it on another location. I would like the code to terminate/escape after the first insertion point is picked. Thanks for your time here, I sure apreciate it. Quote
Lee Mac Posted April 11, 2013 Posted April 11, 2013 After running the code and selecting an insertion point, the block is still hanging on for me to re-insert it on another location. I would like the code to terminate/escape after the first insertion point is picked. By using the while loop, the current code will continuously prompt for a block insertion point until the user presses Esc to exit the program (none too elegant, but I did say the program was simple); for a single insertion, you can simply remove the while expression, e.g.: (defun c:myinsert ( / att blk ) (if (setq blk (findfile "L:/AutoCAD/Template/EDL.dwg")) (progn (setq att (getvar 'attreq)) (setvar 'attreq 0) (vl-cmdf "_.-insert" blk "_S" 1.0 "_R" 0.0 "\\") (setvar 'attreq att) ) (princ "\nEDL.dwg not found.") ) (princ) ) Note that the above also disables the attribute prompts during block insertion and uses a fixed scale of 1.0 and rotation of 0.0. Thanks for your time here, I sure apreciate it. You're welcome. Quote
caxtin Posted April 11, 2013 Author Posted April 11, 2013 Yes, the scaling and rotation is not an issue for this block, so in that aspect, am fine. If I can just have it to escape after the first insertion, that sure will be great. After inserting the block, the block still hang on for another insertions. Just realized when I opened an existing file (DWG), and call up the code, it says _EDL Unknown command "EDL" But for a new file, the code functions. In my search path (L:/AutoCAD/Template), I have the EDL.DWG file. In my toolbar button, I have the command as ^C^C_EDL. Also, I have the EDL.LSP in my CUI's LISP folder. Sorry for bothering you much on this. Thanks. Quote
Lee Mac Posted April 11, 2013 Posted April 11, 2013 If I can just have it to escape after the first insertion, that sure will be great. After inserting the block, the block still hang on for another insertions. Are you certain that you are loading & running the updated code posted above? (Reply#4) Just realized when I opened an existing file (DWG), and call up the code, it says _EDL Unknown command "EDL"But for a new file, the code functions. The command to evaluate the posted program is 'myinsert'; in general, the command to evaluate a program at the AutoCAD command-line is the string immediately following the 'c:' in the defun expression. In my search path (L:/AutoCAD/Template), I have the EDL.DWG file.In my toolbar button, I have the command as ^C^C_EDL. Also, I have the EDL.LSP in my CUI's LISP folder. How are you loading the AutoLISP (.lsp) file into the drawing session? AppLoad/Startup Suite/ACADDOC/MNL? Quote
welldriller Posted April 12, 2013 Posted April 12, 2013 Not familiar with AutoCad 2013 but can you not click on the insert block button, choose the block that you want to insert, pick the place to insert in and than click enter to finish the process? NOTE: I am assuming that you already have the block made. Quote
caxtin Posted April 12, 2013 Author Posted April 12, 2013 can you not click on the insert block button, choose the block that you want to insert The quoted part is what I am trying to avoid. - Go to Menu, find Insert - Go to the folder, search for the sub-folder, then sub-sub folder - Search for the file (if the file starts with a letter that I have to page down, then I start over looking for the file etc - Deal with Insert Dialog Box Don't you think it would be much better to just pick an icon button on my toobar, select the intertion point? Just like a one-stop shopping. Sorry, I am the very laazy time. Quote
caxtin Posted April 12, 2013 Author Posted April 12, 2013 How are you loading the AutoLISP (.lsp) file into the drawing session? AppLoad/Startup Suite/ACADDOC/MNL? First and foremost, the code works well with the one I should have used (#4 Post). Thanks for that. I changed "myinsert" to what I would like to use, and it works fine. I renamed it "defun c:edl", and all went well with the code. The third part is where I need to change my AutoCAD practices. I don't use the ACADDOC file; by now, I should be using it. I will work on that and get it working right. But you have done the part I need help on and I sure appreciate this. This is gonna cut lots of work time for me. Thanks again. Quote
Lee Mac Posted April 13, 2013 Posted April 13, 2013 You're very welcome caxtin, I'm glad the program is working as required. There are several threads on here regarding the use (and misuse) of the ACADDOC.lsp, but ask if you are unsure how to proceed. For your task however, I would strongly recommend that you look into using Tool Palettes. In my opinion, Tool Palettes are absolutely ideal for any block library: you can have multiple palette tabs, each with a designated category of blocks, and within each palette the blocks can either all be sourced from a single 'template' drawing, or each individually sourced from multiple drawings residing in any location. Every button also includes an automatically generated image of the block to be inserted, and furthermore you can set the scale, rotation, colour, layer, linetype, plot style, transparency & lineweight properties for the block that is to be inserted, with all settings automatically applied to the block reference upon insertion (with the necessary layers automatically created if necessary). Migration is also smooth, as Tool Palettes can be easily exported and imported between AutoCAD environments. And all of this functionality is already built-in and available (and is hence compatible) in most versions of AutoCAD, without the need for any custom programming. 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.