Shimatta Posted July 30, 2022 Posted July 30, 2022 Hi everyone I'm new to lisp. I'm using Quick Block by Tharwat and works great but I'm trying to automate it more. The pink circles are the base point of each individual block at some point at block 10 the distance between base points change (this doesn't really matter I can make them all equal distance if needed). There are a total 117 blocks each row and I have many rows but a row is just fine since i need to change the block name each row and start to create blocks counting from 1 to 117 again. So i need to choose the base point and has to be at those exactly magenta coordinates at bottom left of each individual block I need it to be fully automated from block 1 to 117 after giving the first block instruction is that possible? Quick Block ; Creates a block instantly out of the objects that you select ; Found at http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Quick-block/td-p/3454228 (defun c:QB (/ selectionset insertionpoint number Blockname) ;;; Tharwat 11. May. 2012 ;; (if (and (setq selectionset (ssget "_:L")) (setq insertionpoint (getpoint "\n Specificare primo punto :")) ) (progn (setq number 1 Blockname (strcat "firstrow" (itoa number)) ) (while (tblsearch "BLOCK" Blockname) (setq Blockname (strcat "firstrow" (itoa (setq number (1+ number)))) ) ) (command "_.-Block" Blockname insertionpoint selectionset "") (command "_.-insert" Blockname insertionpoint "" "" "") ) (princ) ) (princ) ) EXAMPLE FOR QUICK BLOCK LISP_.dwg Quote
BIGAL Posted July 31, 2022 Posted July 31, 2022 I am confused yes make a block from objects as you have already, using Array and the Last object picking the spacing of the array and a start point calculated as a offset from point 1. There are a total 117 blocks each row where are the 117 can not see that ? Quote
mhupp Posted July 31, 2022 Posted July 31, 2022 (edited) I think he wants them named different like "firstrow1 - firstrow117" and their are different spaces between. Not as automatic but http://www.lee-mac.com/copyblock.html Was trying to come up with copy and then rename like this post https://www.cadtutor.net/forum/topic/75385-increment-number/page/2/ but its not as easy to do with entmod because you cant change the block names that way. probably could copy and explode then rejoin with new name but that seems messy. That way you don't have to keep selecting whats in each block and then the base point. You would just have to pick the new base point. Edited July 31, 2022 by mhupp Quote
BIGAL Posted July 31, 2022 Posted July 31, 2022 I think we need more info. Re new block name if copy the entities in a selection set to somewhere 0,0 reselect as a temp selection set copy again make block at 0,0 etc should be able to repeat numerous times and have different block names. Quote
Shimatta Posted July 31, 2022 Author Posted July 31, 2022 Thank you. Sorry english is not my first language I tried to answer the questions as best as I can so I tried to add more info and showing the resulting blocks EXAMPLE FOR QUICK BLOCK LISP V2.dwg Quote
mhupp Posted July 31, 2022 Posted July 31, 2022 (edited) Not the best code, but it gets the job done. IMPORTANT NOTES Your block names will need to have a number in them Also making general block names like block1 block2 you can get into trouble if you ever need to swap block between drawings. If a block name exists in the drawing. it will pop up an error message saying saying so and will insert that block at the location. --Edit Didn't see your last post till I posted mine. make the first block for the row then use CB to copy and rename for the other 116. they will all have the default attribute. so use ATTOUT & ATTIN to update them (defun C:CB (/ ss blk nxtp Lastpt) (if (setq ss (ssget "_+.:E:S" '((0 . "INSERT")))) (progn (setq blk (vlax-ename->vla-object (setq x (ssname ss 0)))) (command "_.Copy" x "" "_non" (vlax-get blk 'InsertionPoint) pause) (setq nxtp (getvar 'lastpoint)) (NEWBLOCK (entlast)) (while (not (equal Lastpt nxtp 0.001)) (setq Lastpt (getvar 'lastpoint)) (command "_.Copy" (entlast) "" "_non" nxtp pause) (if (equal nxtp (getvar 'lastpoint) 0.001) (entdel (entlast)) (progn (setq nxtp (getvar 'lastpoint)) (NEWBLOCK (entlast)) ) ) ) ) (princ "Block Not Selected") ) (princ) ) (defun NEWBLOCK (x / ss blk OldName num NewName poly) (setq ss (ssadd)) (setq blk (vlax-ename->vla-object x)) (setq OldName (vla-get-name blk)) (setq num (read (wcfilter OldName "[0-9 .]"))) (setq blkname (vl-string-subst (itoa (1+ num)) (itoa num) OldName)) (setvar 'cmdecho 0) (if (tblsearch "block" blkname) (progn (alert (strcat blkname " is existing")) (entdel x) (vl-cmdf "_.Insert" blkname "_non" nxtp 1 1 0 "" "") ; after 0 "" for how many attributes ) (progn (setq itms (vlax-invoke blk 'explode)) (vla-delete blk) (foreach ent itms (ssadd (vlax-vla-object->ename ent) ss) ) (vl-cmdf "_.Block" blkname "_non" nxtp SS "") (vl-cmdf "_.Insert" blkname "_non" nxtp 1 1 0 "" "") ; after 0 "" for how many attributes ) ) (setvar 'cmdecho 0) ) Edited July 31, 2022 by mhupp Quote
BIGAL Posted July 31, 2022 Posted July 31, 2022 I don't see why you would just not make a new block of circle, rectang, ploygon with 2 attributes it is very easy to copy and increase the attribute values. A1.1 A1.2 and so on. It would just ask for prefix and start number, next group B1, next group C1. If happy me or some one here will provide some code to add numbers when copying. aaa.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.