Jump to content

how to programmatically show/hide blocks using their name


nik600

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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))

Link to comment
Share on other sites

@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! :beer:

Edited by BlackBox
Link to comment
Share on other sites

@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. :)

Link to comment
Share on other sites

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. :beer:

 

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.

Link to comment
Share on other sites

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. :geek:

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)
)

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...