kycu Posted July 12, 2012 Posted July 12, 2012 Hi there! I need a LISP that will select all elements on all layers that are on the drawing. Can you help me guys? Robert Quote
MSasu Posted July 12, 2012 Posted July 12, 2012 Please check the SSGET function: (cdr (sssetfirst nil (ssget "_X"))) Quote
kycu Posted July 12, 2012 Author Posted July 12, 2012 I made something like this: (defun select ( / a) (setq a (ssget "X")) (princ) );defun but doesn't work. Could you write me what is wrong with this code? Robert Quote
MSasu Posted July 12, 2012 Posted July 12, 2012 What do you intend to achieve by that? Your code will just create a selection set and assign it to a variable named a. You may add further code to process that selection set. You want to have all the items highlighted on screen? Then check the example I gave you. Also, are you using a localized version of AutoCAD? In this case, please check carefully the way I noted the selection method. Another comment, please edit your post and add the required code tags. Thank you. Quote
MSasu Posted July 12, 2012 Posted July 12, 2012 Just noticed - how did you call that code? It should be used as: (select) If you intend to use it as a command directly on prompter, then please pay attention to the way you defined it (as a function, not as a command) and most important that there is already a build-in command named SELECT. Quote
kycu Posted July 12, 2012 Author Posted July 12, 2012 Thanks for hint What i want to do is to move all elements, including border of a drawing, to the correct possition (bottom left corner of a border should cover point (0, 0, 0)). Border is a block so i believe it is possible to catch the corner of it and move to point (0, 0, 0). That is why i started with selecting all elements. Everyday i need to do this manually, so would be great to do all this things by one macro (one button). Robert Quote
MSasu Posted July 12, 2012 Posted July 12, 2012 Border is a block so i believe it is possible to catch the corner of it and move to point (0, 0, 0). Robert, the insertion point of said border block is the lower-left corner? Then will be easy to retrieve it and use as base for movement operation. Please check the ENTGET function; the insertion point for block entities is stored on DXF code 10. Quote
BlackBox Posted July 12, 2012 Posted July 12, 2012 (defun c:FOO (/ ss pt) (if (and (setq ss (ssget "_x" (list (cons 410 (getvar 'ctab))))) (setq pt (getpoint "\nSpecify the bottom left point to move from: ") ) ) (command "._move" ss "" pt '(0 0 0)) (cond (ss (prompt "\n** No point specified ** ")) ((prompt "\n** Nothing selected ** ")) ) ) (princ) ) Quote
MSasu Posted July 12, 2012 Posted July 12, 2012 For a more automated solution will be interesting to know if the items are in Model or in a Layout, the name of the border block and if in unique on that tab and if there are items placed in locked layers. If you are willing to write this routine by yourself, I will try to assist you. Quote
kycu Posted July 12, 2012 Author Posted July 12, 2012 Woooow ! You are really good! But one more question. If we know the name of that block (let say "robert") is it possible to write the code which wont aske me about selecting the point to move, but just move it? will select lower-left point by itself? Robert Quote
MSasu Posted July 12, 2012 Posted July 12, 2012 This will select all instances of said border block. Is it unique in the current tab? (ssget "_X" (list '(0 . "INSERT") (cons 410 (getvar "CTAB")) '(2 . "ROBERT"))) Next look to SSNAME, ENTGET and ASSOC functions. Quote
irneb Posted July 14, 2012 Posted July 14, 2012 Well, seeing a you already selected all (and with RenderMan's sample: all on current tab), then you could step through each item in the selection set (ssname), then get its ActiveX object (vlax-ename->vla-object) and check if it's a block reference (vla-get-ObjectName should equal "AcDbBlockReference"). Then you can check if the block's effective name equals "robert" (vla-get-EffectiveName). Then the block's insertion point would be available through vla-get-InsertionPoint (only you'd need to convert the variant-safearray to a list of reals for the point, or use vlax-get with 'InsertionPoint). Or of the InsertionPoint's not on the bottom-left you could use vla-GetBoundingBox. That way it should work for even a dynamic block. If not a DB, then what Mircea shown should be fine. The reason he's asked about it being unique is that it's possible to place a 2nd copy (or more) of the block on the same tab. In such case which one should be used as the source point for the move? The 1st one, or the lowest & leftmost, or some other criteria? Quote
kycu Posted July 18, 2012 Author Posted July 18, 2012 Hi, This is not a dynamic block, and for sure there is only one block on each sheet with this name. The code that RenderMan sent works great. The only thing that i would like to add is not to choose manually left-lower corner as a point to move. Would be great if the program chooses it by himself. Robert Quote
BlackBox Posted July 18, 2012 Posted July 18, 2012 (edited) This is not a dynamic block, and for sure there is only one block on each sheet with this name. Given these parameters: ;; Load Visual LISP extensions (vl-load-com) (defun c:FOO2 (/ ss1 tab mn mx) ;; If there is a vlaid selection set of block(s) named "ROBERT" (if (setq ss1 (ssget "_x" (list '(0 . "INSERT") '(2 . "ROBERT") (setq tab (cons 410 (getvar 'ctab))) ) ) ) ;; Then (progn ;; Extract the bounding box (vla-getboundingbox ;; From the Vla-Object of the first item in the selection set (vlax-ename->vla-object (ssname ss1 0)) 'mn 'mx ) ;; Move (command "._move" ;; A selection set of all objects on the current tab (ssget "_x" (list tab)) "" ;; Convert the lower left point of the bounding box ;; from a safearray to a list (vlax-safearray->list mn) '(0 0 0) ) ) (prompt "\n** Nothing selected ** ") ) (princ) ) Edited July 18, 2012 by BlackBox Code revised Quote
kycu Posted July 18, 2012 Author Posted July 18, 2012 Beautifull! This is exactly what i need Now i need to study each line to understand the code ... for sure it wont be easy ... Regards, Robert Quote
BlackBox Posted July 18, 2012 Posted July 18, 2012 Beautifull! This is exactly what i need No worries; happy to help. Now i need to study each line to understand the code ... for sure it wont be easy ... Code revised here, and I've added some comments. Quote
kycu Posted July 18, 2012 Author Posted July 18, 2012 Thank you very much! Could you recomend any tutorial (beginners level) for Autolisp that i could learn step by step about Autolisp? Quote
BlackBox Posted July 18, 2012 Posted July 18, 2012 Twice in one day.... There are tons of resources to learn from for free such as forums like these, AfraLisp, etc., however, if you want a good book I'd recommend (image is linked): The Visual LISP Developer's Bible [/url] 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.