View Full Version : Use refedit in a LISP routine
ccowgill
2007-05-30, 04:28 PM
Maybe I have the wrong approach, but I am trying to use a lisp routine to ref edit a block the routine works well except it requires the user to select the block, I want to use a selection set to accomplish this. Here is my code:
(defun c:TBLKREA (/)
(command "-refedit" pause "o" "a" "y")
(command "regenall")
(command "refclose" "s")
) ;_ end of defun
I would prefer to have the selection set be automatically selected, but when I use the set, i get this error
*Invalid selection*
Expects a single object.
and I know that there is only one object in the selection set. the program is meant to be used to automatically update fields that are in text objects linked to a sheet set.
framedNlv
2007-05-30, 04:44 PM
If you select the block first it almost works.
Chris
ccowgill
2007-05-30, 04:47 PM
If you select the block first it almost works.
ChrisI would like to use
(setq ss (ssget "_X" '((-4 . "<and")(0 . "INSERT")(2 . "TBL*")(-4 . "and>"))))
or similar
if at all possible
watsonlisp
2007-05-30, 08:28 PM
I haven't tested this because I don't have the block you are using.
(defun c:TBLKREA (/)
(setq ss (ssget "_X" '((-4 . "<and")(0 . "INSERT")(2 . "TBL*")(-4 . "and>"))))
(setq ssl (sslength ss))
(setq ct (- ssl 1))
(setq lp 1)
(while lp
(setq entn (ssname ss ct))
(setq ct (- ct 1))
(if (/= entn nil)
(progn
(command "-refedit" entn "o" "a" "y")
(command "regenall")
(command "refclose" "s")
));end progn/if entn
(if (< ct 0) (setq lp nil))
);end lp
) ;_ end of defun
tyshofner
2007-05-30, 09:40 PM
The "refedit" command is very picky!! I tried all the methods I would normally use to specify an object inside LISP (entity name, selection set, etc.) and none of them seemed to work. Finally I remebered this happening before (for another command). It has to do with how ACAD wants you (the user) to specify the selection. I think the refedit select object prompt requires a return value similar to what you get when you use an "entsel" (which returns a list containing the entity name as well as the point used to select the object). I tried passing a similar list to the prompt but it didn't like that either. So finally I decided just to pass the select object prompt a point (specifically the inserion point of the block) and VOILA!!!!
Here is the code:
(defun c:TBLKREA ( / o_osmode blk_lst blk pnt)
(setq o_osmode (getvar "osmode")) ;save osnap
(setq blk_lst (mapcar 'cadr (ssnamex (ssget "_X" '((0 . "INSERT") (2 . "TBL*")))))) ;create list of block entity names
(setvar "osmode" 0) ;turn osnap off
(foreach blk blk_lst ;iterate through list
(setq pnt (cdr (assoc 10 (entget blk)))) ;grab block insertion point
(command "-refedit" pnt "o" "a" "y") ;use the point to select the object
(command "regenall")
(command "refclose" "s")
)
(setvar "osmode" o_osmode);reset osnaps
(princ)
);_ end of defun
Ty :mrgreen:
ccowgill
2007-05-31, 11:15 AM
it's amazing what you learn about your title block when you try such things, I think the reason it might still not be working is that the block doesn't actually have anything that passes through the insertion point, it is off by 0.00000398 units is there a way to get a point that is not exact, or allow it to round?
Even when selecting a point that I know is in the linework, it still doesnt appear to work, I get the same error message
tyshofner
2007-05-31, 07:57 PM
Yes the point probably needs to be on an "object" inside the block. Such was the block I used to test. If the point is only off by that much you could try playing with your pickbox size. Even though you are specifying a specific point ACAD should select the object based on the current pickbox size.
Try this out (not tested):
(defun c:TBLKREA ( / o_osmode blk_lst blk pnt)
(setq o_osmode (getvar "osmode")) ;save osnap
(setq o_pickbox (getvar "pickbox")) ;save pickbox
(setq blk_lst (mapcar 'cadr (ssnamex (ssget "_X" '((0 . "INSERT") (2 . "TBL*")))))) ;create list of block entity names
(setvar "osmode" 0) ;turn osnap off
(setvar "pickbox" 10) ;change pickbox size
(foreach blk blk_lst ;iterate through list
(setq pnt (cdr (assoc 10 (entget blk)))) ;grab block insertion point
(command "-refedit" pnt "o" "a" "y") ;use the point to select the object
(command "regenall")
(command "refclose" "s")
)
(setvar "osmode" o_osmode) ;reset osnaps
(setvar "pickbox" o_pickbox) ;reset pickbox
(princ)
);_ end of defun
Ty :mrgreen:
ccowgill
2007-05-31, 08:01 PM
I got it to work, or at least in my test drawing. I just used the double click edit for the attributes in the title block and used the point that appeared on the command line. As long as the title block is always inserted at 0,0,0 it should work. There wouldn't happen to be anyway to get this to run whenever the Sheet Set Custom properties are modified, is there? I can set it up to run when the drawing is opened, and a button to run it manually, but automatic when changes are made would be nice.
tyshofner
2007-05-31, 08:07 PM
There wouldn't happen to be anyway to get this to run whenever the Sheet Set Custom properties are modified, is there? I can set it up to run when the drawing is opened, and a button to run it manually, but automatic when changes are made would be nice.
Look into "reactors". I never really use them so I don't know to much about them. I don't think they are very hard to get going though and they would be exactly what you are looking for. Search the forum, I'm sure you'll find plenty of info.
Ty :mrgreen:
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.