Hide Selected Blocks LISP not working. Help?

Hide Selected Blocks LISP not working. Help?

david.faunce
Enthusiast Enthusiast
836 Views
1 Reply
Message 1 of 2

Hide Selected Blocks LISP not working. Help?

david.faunce
Enthusiast
Enthusiast

I wrote a quick LISP function to have the user select the blocks they want to hide. The process should be that they keep selecting the blocks - when they are finished they hit enter and the blocks are hidden.

 

This function partially works. At first, when I select a block it throws an error: 

      ; error: bad argument value: AutoCAD Command: #<VLA-OBJECT IAcadBlockReference 0000...>

 

But then the command line prompts me to select another block, so I do and it works from there.

 

How do I get rid of the initial error?

 

(defun hide ( / sset)
    (vl-load-com)
    (while
          (setq sset (car (entsel)))
          (setq sset (vlax-ename->vla-object sset))
           (command "._HIDEOBJECTS" sset "")
     ) ;while
) ;defun

 

 

0 Likes
837 Views
1 Reply
Reply (1)
Message 2 of 2

Kent1Cooper
Consultant
Consultant

@david.faunce wrote:

... have the user select the blocks they want to hide. The process should be that they keep selecting the blocks - when they are finished they hit enter and the blocks are hidden.  .... 



For the way you describe it [after you've picked them all, they all hide], I see no reason to have a custom function or command -- plain old HIDEOBJECTS works in just that way.

 

But if you have some reason to need it to operate as a function instead of a command, such as within a longer routine, HIDEOBJECTS wants entities/objects, not conversions of them to VLA objects.  And you can use the more generic select-objects function, without the (while), which will also allow de-selecting, windowing, etc.:

(defun HideM (); = Hide Multiple
  (command "_.hideobjects" (ssget) "")
)

 

Or, you can have it Hide each thing as you pick it, one at a time, until you stop picking, which it looks like your code is intended to do:

 

(defun Hide1 (/ ent); = Hide 1-at-a-time as picked
  (while (setq ent (car (entsel "\nSelect object to hide or <exit>: ")))
    (command "._HIDEOBJECTS" ent "")
  ) ;while
) ;defun

 

And I added something to  the word "Hide" in each, because it's a bad idea to use a name that's the same as an AutoCAD command name, even as a function rather than a (defun C:...) command  name.  If you do it in the latter way instead, don't call it HIDE unless you Undefine the native command first.

 

Also, of course, those are not [nor was your original code] restricted to Blocks, but work on any selectable objects.

Kent Cooper, AIA
0 Likes