ALFEZ Posted December 18, 2019 Posted December 18, 2019 (edited) I have a lisp that I us to fill data into a block by getting the user select two other blocks. One of the blocks the user selects is often used in combination with multiple other blocks. I.E. blk1 with blk2 = final1 blk1 with blk3 = final2 blk1 with blkn = finaln Is there a way to hold the data I need so that the user can load the info for blk1 the first time. Then when I run the function a second time, it prompts the user to hit enter if the desired block is already in memory. Or lets the user select a new point if desired? I will keep looking as always but I am posting cause thus far nothing I have found fits that bill and what I have program to date seems to fall into a loop that crashes autocad. All help is welcome. Edited December 18, 2019 by ALFEZ Quote
BIGAL Posted December 18, 2019 Posted December 18, 2019 The idea would be to save global variables the 1st question is how many blocks ? The solution for that is that it is possible to create variables on the fly, as many as required, so your not sure you will have blocks blk1, blk2 - blkX what is x so you would make global variables blk+x where x increments all the time. Its done using READ. : FOO2 Enter custom variable name: asdf Enter an integer value: 23 Enter block number eg 1 4 : !asdf4 23 (defun c:FOO2 (/ var val x) (setq x 4) (if (and (setq var (getstring "\nEnter custom variable name: ")) ; eg Blk (setq val (getint "\nEnter an integer value: ")) ; this goes into variable number string etc (setq x (getint "\nEnter block number eg 1 ")) ; increment variable number ) (progn (setq var (strcat var (rtos x 2 0))) (set (read var) val) ) ) (princ) ) Quote
rlx Posted December 18, 2019 Posted December 18, 2019 (edited) Without example of block & data its hard for Bigal or any of us to give working solution. Store the data in custom variables as Bigal suggest is one way , storing them in a list is another way. Then you would only need one variable name and store the rest in an association list like (setq lst '(("bolds" . 15) ("nuts" . 12) ("crystal-balls" . 0))). If data has to be used across drawings you would best write the data to disk. Edited December 18, 2019 by rlx Quote
ALFEZ Posted December 18, 2019 Author Posted December 18, 2019 Thank you for your help thus far. So to give more context I am making wire tags. I have information in my blocks that I am extracting and putting in a third block not shown in the example drawing. I already have the lisp that dose this but the problem is more the repeat selection on of the one block that is the origin. The other block can be far from the origin block (1000 feet away relatively speaking) that is why I want the memory. The value I would like to keep in the memory would be the block entity and it would only be keep when the drawing is open. If ever the drawing is closed the value could go to nil. From there i can process the data to get the information from the block. Thank you again. example_usm.dwg Quote
BIGAL Posted December 19, 2019 Posted December 19, 2019 (edited) Using a combination of what rlx has suggested and what I suggested you could create lists that take the block name as the variable name, and add the second pick block. ((blk6-blk3)(blk6-blk4)…..) Had a quick look and may be easy, but need to read the attribute for block name, so I am only going to read the 1st att for a go at this. If picking other blocks etc may not work. Try this it will save a variable the attribute value of the 1st block. You only get one picking blocks, adding more blocks after running will require a version 2 to add to the variable maybe a rewrite of this checking if variable exists. ; Block list one blk to multi blks ; By Alan H Dec 2019 ; updates required ; check is block ; check has-attributes (vl-load-com) (defun c:makeblklst ( / ent att txt1 txt txt2) (setq ent (car (entsel "\npick block 1 "))) ; pick master block (setq att (nth 0 (vlax-invoke (vlax-ename->vla-object ent) 'getattributes))) ; get the 1st attribute (setq txt1 (vla-get-textstring att)) ; get textstring from attribute (setq txt txt1) ; need to keep text string (set (read txt1) "") ; makes varaible from att with nil string (setq txt1 '()) ; reset txt1 to a list (while (setq ent (car (entsel "\npick blocks etc Enter to exit "))) (setq att (nth 0 (vlax-invoke (vlax-ename->vla-object ent) 'getattributes))) (setq txt2 (vla-get-textstring att)) (setq txt1 (cons (list txt txt2) txt1)) ; make a list ) (princ txt1) (princ) ) (c:makeblklst) Edited December 19, 2019 by BIGAL 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.