nik600 Posted November 27, 2011 Share Posted November 27, 2011 Dear all i'm trying to write a lisp function that allows me to show/hide a block using its name as a selector. I've found some examples on the web bu all the examples manually require the user to select the object, i want to select it using simpy the name of the block, and not what is selected in the window. i've tried this code: (defun c:test_show () (setq selezione (ssget "X" '((2 . "test1")))) (redraw selezione 1) (princ)) (defun c:test_hide () (setq selezione (ssget "X" '((2 . "test1")))) (redraw selezione 2) (princ)) but when i type "test_show" in the F2 console i get: Command: test_show ; error: argument type error: lentityp <Selection set: 80> i've seen that the redraw function requires an ENAME argument, so probably my problem is how to get the ENAME of a block having its name, anyone can help me? Thanks in Advance Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted November 27, 2011 Share Posted November 27, 2011 try : (tblobjname "block" "bname") type instead of "bname" - your "test1" block... Quote Link to comment Share on other sites More sharing options...
David Bethel Posted November 27, 2011 Share Posted November 27, 2011 You will need to step thru the PICKSET. There are many variations of the process: (and (setq ss (ssget "X" '((2 . "TEST1"))) (while (setq en (ssname ss 0)) (redraw en 2) (ssdel en ss))) HTH -David Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 27, 2011 Share Posted November 27, 2011 Here is how I might approach the task: ([color=BLUE]defun[/color] c:test_show ( ) (RedrawSelectionSet ([color=BLUE]ssget[/color] [color=MAROON]"_X"[/color] ([color=BLUE]list[/color] '(0 . [color=MAROON]"INSERT"[/color]) '(2 . [color=MAROON]"test1"[/color]) ([color=BLUE]cons[/color] 410 ([color=BLUE]if[/color] ([color=BLUE]=[/color] 1 ([color=BLUE]getvar[/color] 'CVPORT)) ([color=BLUE]getvar[/color] 'CTAB) [color=MAROON]"Model"[/color])) ) ) 1 ) ([color=BLUE]princ[/color]) ) ([color=BLUE]defun[/color] c:test_hide ( ) (RedrawSelectionSet ([color=BLUE]ssget[/color] [color=MAROON]"_X"[/color] ([color=BLUE]list[/color] '(0 . [color=MAROON]"INSERT"[/color]) '(2 . [color=MAROON]"test1"[/color]) ([color=BLUE]cons[/color] 410 ([color=BLUE]if[/color] ([color=BLUE]=[/color] 1 ([color=BLUE]getvar[/color] 'CVPORT)) ([color=BLUE]getvar[/color] 'CTAB) [color=MAROON]"Model"[/color])) ) ) 2 ) ([color=BLUE]princ[/color]) ) ([color=BLUE]defun[/color] RedrawSelectionSet ( ss mode [color=BLUE]/[/color] i ) ([color=BLUE]if[/color] ss ([color=BLUE]repeat[/color] ([color=BLUE]setq[/color] i ([color=BLUE]sslength[/color] ss)) ([color=BLUE]redraw[/color] ([color=BLUE]ssname[/color] ss ([color=BLUE]setq[/color] i ([color=BLUE]1-[/color] i))) mode) ) ) ) Both commands ('test_hide' and 'test_show') call the defined function 'RedrawSelectionSet', which requires a SelectionSet argument (ss) and integer argument (mode) for the redraw function. The 'RedrawSelectionSet' will then step through the supplied SelectionSet and redraw each entity. I have also restricted the SelectionSet filter to Blocks (Inserts) in the Active Space (Model / Layout / through VPort). Quote Link to comment Share on other sites More sharing options...
BlackBox Posted November 27, 2011 Share Posted November 27, 2011 For fun... (defun c:HIDE_TEST1 ( / ss i e) (if (and (setq ss (ssget "_X" '((0 . "INSERT") (2 . "TEST1")))) (setq i -1)) (while (setq e (ssname ss (setq i (1+ i)))) (redraw e 2)) (prompt "\n** Block not found ** ")) (princ)) (defun c:SHOW_TEST1 ( / ss i e) (if (and (setq ss (ssget "_X" '((0 . "INSERT") (2 . "TEST1")))) (setq i -1)) (while (setq e (ssname ss (setq i (1+ i)))) (redraw e 1)) (prompt "\n** Block not found ** ")) (princ)) Quote Link to comment Share on other sites More sharing options...
nik600 Posted November 27, 2011 Author Share Posted November 27, 2011 thanks a lot! Quote Link to comment Share on other sites More sharing options...
BlackBox Posted November 27, 2011 Share Posted November 27, 2011 (edited) @Lee - As a REGEN "forces the [hidden] entities to redisplay in their normal manor" is the 410 component of the filter necessary? Admittedly, it is more efficient to only modify those entities which reside on the active tab; I was just curious to know if there was another aspect that escaped me. Cheers! Edited November 27, 2011 by BlackBox Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 27, 2011 Share Posted November 27, 2011 @Lee - As a REGEN "forces the [hidden] entities to redisplay in their normal manor" is the 410 component of the filter necessary? Admittedly, it is more efficient to only modify those entities which reside on the active tab; I was just curious to know if there was another aspect that escaped me. I included it for the reason you state - I saw no reason to process (potentially 100's of) entities not in the current layout/space. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted November 27, 2011 Share Posted November 27, 2011 I included it for the reason you state - I saw no reason to process (potentially 100's of) entities not in the current layout/space. No worries, mate; I appreciate the clarification. I failed to consider that scenario as a result of our work flow(s) - We only work in ModelSpace - PaperSpace is relegated to Title Block, Viewport(s), etc.. Again, very succinct, and efficient code, my friend. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted November 27, 2011 Share Posted November 27, 2011 I failed to consider that scenario as a result of our work flow(s) - We only work in ModelSpace - PaperSpace is relegated to Title Block, Viewport(s), etc.. x2 http://forums.augi.com/showpost.php?p=1150829&postcount=13 Quote Link to comment Share on other sites More sharing options...
BlackBox Posted November 27, 2011 Share Posted November 27, 2011 I still believe that Lee's level of thoroughness is better suited for more situations, and users. Unfortunately, I am not employed to code (not that Lee is either, just saying). Instead, I code to benefit my work during my personal time (i.e., Lunches, after-hours, weekends, etc.) sparingly, and potentially at the cost of usability outside of my place of work... I'm working on it. Quote Link to comment Share on other sites More sharing options...
Organic Posted November 27, 2011 Share Posted November 27, 2011 Here is how I might approach the task: ([color=BLUE]defun[/color] c:test_show ( ) (RedrawSelectionSet ([color=BLUE]ssget[/color] [color=MAROON]"_X"[/color] ([color=BLUE]list[/color] '(0 . [color=MAROON]"INSERT"[/color]) '(2 . [color=MAROON]"test1"[/color]) ([color=BLUE]cons[/color] 410 ([color=BLUE]if[/color] ([color=BLUE]=[/color] 1 ([color=BLUE]getvar[/color] 'CVPORT)) ([color=BLUE]getvar[/color] 'CTAB) [color=MAROON]"Model"[/color])) ) ) 1 ) ([color=BLUE]princ[/color]) ) ([color=BLUE]defun[/color] c:test_hide ( ) (RedrawSelectionSet ([color=BLUE]ssget[/color] [color=MAROON]"_X"[/color] ([color=BLUE]list[/color] '(0 . [color=MAROON]"INSERT"[/color]) '(2 . [color=MAROON]"test1"[/color]) ([color=BLUE]cons[/color] 410 ([color=BLUE]if[/color] ([color=BLUE]=[/color] 1 ([color=BLUE]getvar[/color] 'CVPORT)) ([color=BLUE]getvar[/color] 'CTAB) [color=MAROON]"Model"[/color])) ) ) 2 ) ([color=BLUE]princ[/color]) ) ([color=BLUE]defun[/color] RedrawSelectionSet ( ss mode [color=BLUE]/[/color] i ) ([color=BLUE]if[/color] ss ([color=BLUE]repeat[/color] ([color=BLUE]setq[/color] i ([color=BLUE]sslength[/color] ss)) ([color=BLUE]redraw[/color] ([color=BLUE]ssname[/color] ss ([color=BLUE]setq[/color] i ([color=BLUE]1-[/color] i))) mode) ) ) ) Both commands ('test_hide' and 'test_show') call the defined function 'RedrawSelectionSet', which requires a SelectionSet argument (ss) and integer argument (mode) for the redraw function. The 'RedrawSelectionSet' will then step through the supplied SelectionSet and redraw each entity. I have also restricted the SelectionSet filter to Blocks (Inserts) in the Active Space (Model / Layout / through VPort). This looks useful thanks. I was looking for something exactly like this last week so will add it to my custom toolbars for future use now. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 27, 2011 Share Posted November 27, 2011 Cheers guys Quote Link to comment Share on other sites More sharing options...
alanjt Posted November 28, 2011 Share Posted November 28, 2011 I like the idea of a sub for redrawing an entire selectionset based on the specified redraw option. I've had these two in my toolbox for some time. I have access to the hide/isolate object commands (and use them quite a bit), but this can be so much quicker at times. (defun c:HH (/ ss i) ;; temporarily hide pesky objects (regen will bring them back) ;; Alan J. Thompson (if (setq ss (ssget)) (repeat (setq i (sslength ss)) (redraw (ssname ss (setq i (1- i))) 2)) ) (princ) ) (defun c:II (/ tab all ss i e) ;; temporarily isolate selected objects (regen will bring them back) ;; Alan J. Thompson (setq tab (if (eq (getvar 'CVPORT) 1) '(410 . "Model") (cons 410 (getvar 'CTAB)) ) all (ssget "_A" (list tab)) ) (if (setq ss (ssget (list tab))) (repeat (setq i (sslength all)) (redraw (setq e (ssname all (setq i (1- i)))) (if (ssmemb e ss) 1 2 ) ) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
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.