Invisibility

Invisibility

john.uhden
Mentor Mentor
945 Views
12 Replies
Message 1 of 13

Invisibility

john.uhden
Mentor
Mentor

Please correct me if I'm wrong, but after some investigation I think I've found that:

1.  All graphical vla-objects have a 'Visible property (0 = off, -1 = on)

2.  Entity data has a DXF 60 code only if an entity is invisible.

 

What this is about is that we did an updated topographic survey of two adjacent lots belonging to the same owner when we were to have updated only one of the lots (the improved one, the other one is vacant).

Rather than erasing the not-to-be-published-yet shots and features of the vacant lot, we wanted to "hide" them away since we know that one day the owner will want a survey of the vacant lot, and we will be able to use what we have instead of sending the crew out again and redrafting it all.  I considered using lots of wipeouts, but the visibility approach requires much less effort, so I came up with this...

(defun C:Visible ( / *error* vars vals ss E Obj i N)
  ;; v1.0 (8-31-21) John F. Uhden
  ;; Program makes each entity in a selection set invisible, or
  ;; Makes all invisible objects visible, and
  ;; Has a Report option to inform of the number of invisible objects.

  (gc)
  (prompt "\nVisible v1.0 (c)2021, John F. Uhden\n")
  (defun *error* (Error)
    (mapcar 'setvar vars vals)
    (vla-endundomark *doc*)
    (cond
      ((not Error))
      ((wcmatch (strcase Error) "*QUIT*,*CANCEL*")
         (vl-exit-with-error "\r                                              ")
      )
      ((wcmatch (strcase Error) "*CANCEL*,*QUIT*")
         (vl-exit-with-error (strcat "\r*ERROR*: " Error))
      )
    )
    (princ)
  )
  (or *acad* (setq *acad* (vlax-get-acad-object)))
  (or *doc* (setq *doc* (vla-get-ActiveDocument *acad*)))
  (vla-endundomark *doc*)
  (vla-startundomark *doc*)
  (setq vars '("cmdecho"))
  (setq vals (mapcar 'getvar vars))
  (mapcar 'setvar vars '(0))
  (command "_.expert" (getvar "expert")) ;; dummy command
  (initget 1 "INvisible iNvisible Report Visible")
  (setq ans (getkword "\nMake selected objects iNvisible/Visible/Report: "))
  (cond
    ((= ans "Report")
      (setq ss (ssget "x" '((60 . 1))))
      (setq N (sslength ss))
      (princ (strcat "\nFound " (itoa N) " invisible entities."))
      (sssetfirst nil ss)
    )
    ((= ans "Visible")
      (princ "\nAll invisible objects will be made visible.")
      (getstring "\nHit any key to continue, or Esc to stop.")
      (setq ss (ssget "x" '((60 . 1))))
      (repeat (setq i (sslength ss))
        (setq e (ssname ss (setq i (1- i)))
            obj (vlax-ename->vla-object e)
        )
        (vlax-put obj 'Visible -1)
      )
      (princ (strcat "\n  Made " (itoa (sslength ss)) " objects visible."))
    )
    (1
      (princ "\nSelect objects to make invisible.")
      (setq ss (ssget))
      (repeat (setq i (sslength ss))
        (setq e (ssname ss (setq i (1- i)))
            obj (vlax-ename->vla-object e)
        )
        (vlax-put obj 'Visible 0)
      )
      (princ (strcat "\n  Made " (itoa (sslength ss)) " objects invisible."))
    )
  )
  (*error* nil)
)
(defun c:VIS ()(c:Visible))

 

John F. Uhden

Accepted solutions (1)
946 Views
12 Replies
Replies (12)
Message 2 of 13

Anonymous
Not applicable

I normally use the :vlax-true and :vlax-false constants.  They're easier to spot in the code, and makes the program flow a little easier to follow.

0 Likes
Message 3 of 13

john.uhden
Mentor
Mentor
@Anonymous
Thanks for the pointer.
Having a paleolithic background, my vocabulary is mostly numeric.

John F. Uhden

0 Likes
Message 4 of 13

Kent1Cooper
Consultant
Consultant

@john.uhden wrote:

....

2.  Entity data has a DXF 60 code only if an entity is invisible.

....

....
    ((= ans "Visible")
      ....
      (setq ss (ssget "x" '((60 . 1))))
      (repeat (setq i (sslength ss))
        (setq e (ssname ss (setq i (1- i)))
            obj (vlax-ename->vla-object e)
        )
        (vlax-put obj 'Visible -1)
      )
      ....
    )
    (1
      (princ "\nSelect objects to make invisible.")
      (setq ss (ssget))
      (repeat (setq i (sslength ss))
        (setq e (ssname ss (setq i (1- i)))
            obj (vlax-ename->vla-object e)
        )
        (vlax-put obj 'Visible 0)
      )
      ....
    )
....

 


In cases where an entity data list would have only one entry for a given DXF code number [if any], an entity data entry tacked onto the end of the list will override an earlier entry of the same DXF code number if it's there.  So it's not necessary to care whether or not such an entry exists in the entity data already.  You can work with it anyway, using (append) whether or not there's an entry that you could replace with (subst).  This can spare you a little code in the above-quoted conditions, mainly the need to convert to a VLA object:

....
    ((= ans "Visible")
    .... 
     (setq ss (ssget "x" '((60 . 1))))
      (repeat (setq i (sslength ss))
        (setq edata (entget (ssname ss (setq i (1- i)))))
        (entmod (append edata '((60 . 0))))
      )
....
    )
    (1
      (princ "\nSelect objects to make invisible.")
      (setq ss (ssget))
      (repeat (setq i (sslength ss))
        (setq edata (entget (ssname ss (setq i (1- i)))))
        (entmod (append edata '((60 . 1))))
      )
    ....
    )
....

 

Kent Cooper, AIA
0 Likes
Message 5 of 13

john.uhden
Mentor
Mentor

@Kent1Cooper 

I don't see how an entmod and an entget and an append is an improvement, but it's nice to know there are alternative methods.  Thanks.

John F. Uhden

0 Likes
Message 6 of 13

martti.halminen
Collaborator
Collaborator

Note that any native Lisp command considers :vlax-false as True, nil is the only thing that is considered false.

 

_$ (null :vlax-false) -> nil

_$ (null nil)               -> T

 

So if you use these, you always need to assign those to some variable and compare:

 

(if (null var) ...) vs. (if (eq var :vlax-false) ...)

 

also no non-vla function returns those. (stringp 'foo) -> nil

 

The canonical true value in Lisp culture is T if needed explicitly, but anything non-nil works.

 

So in your own programs you are free to use anything you like, but anybody else reading that would find it unfamiliar.

0 Likes
Message 7 of 13

john.uhden
Mentor
Mentor
@Anonymous
You are reminding me of the occasion years ago in the Compuserve days when
I posted something and Tony T called me a pea-brain because he said no one
could ever decipher my code, to which I responded that if a pea-brain could
figure it out then anyone could. 🤐

John F. Uhden

0 Likes
Message 8 of 13

martti.halminen
Collaborator
Collaborator
Accepted solution

 

The basic idea with style beyond the minimal syntactic correctness is that you would not need figuring out, the program should be readable as is.

 

Programming is communication, with several partners:

 

A) the compiler/interpreter

B) yourself

C) yourself, five years away

D) anybody else needing to read the program

 

A) is the easy one, anything syntactically correct is OK, even if totally unreadable for humans.

      For example, writing the whole program on the same line is not a problem.

 

For most practical purposes, C and D are the same. Occasionally even half a year is sufficient to make me wonder about the sanity of the writer.

 

If you are the only one ever reading the program, you can get away with a private style, but anybody else is screwed.

When I came to my current job, almost the first thing I did (after searching for and finding the source code and storing it to a version control system) was re-indenting everything my predecessor had written in the previous 11 years.

 

As I come from the mainstream Lisp culture, I prefer the style used there, i.e. the style used in (almost) all Common Lisp textbooks and the standard document.

 

AutoLISP is a bit ill served there, as plenty of Autodesk documentation examples are contradictory, and at least the older ones often are better as examples of how not to do things.

 

-- 

 

0 Likes
Message 9 of 13

john.uhden
Mentor
Mentor
Indentation is my foremost requirement.
When I look at my old code I am either dismayed with its clumsiness or
amazed by its cleverness. Whatever, it's all fun.

John F. Uhden

0 Likes
Message 10 of 13

john.uhden
Mentor
Mentor

@Kent1Cooper wrote:

"So it's not necessary to care whether or not such an entry exists in the entity data already."

 

It matters for the Report option and for easily filtering for the selection of invisible entities.

John F. Uhden

0 Likes
Message 11 of 13

john.uhden
Mentor
Mentor

I got into the habit of using 1 instead of T for fear that some other program (though I don't use any) might (setq T nil).

To my knowledge you can't (setq 1 nil).

John F. Uhden

0 Likes
Message 12 of 13

martti.halminen
Collaborator
Collaborator

That is actually a rather good viewpoint. In AutoLISP the protection against assigning to T is weak enough to be almost nonexistent.

 

In most other Lisp implementations T and nil are defined as constants or otherwise protected so that you can't override it.

0 Likes
Message 13 of 13

john.uhden
Mentor
Mentor

@martti.halminen 

I think you are the first person ever to acknowledge that.  I very much appreciate it.

O course, right along with (vl-load-com), you could (setq T 'T), or even (setq T 1). 🤗

John F. Uhden

0 Likes