How to select only visible hatches

How to select only visible hatches

karpki
Advocate Advocate
1,756 Views
18 Replies
Message 1 of 19

How to select only visible hatches

karpki
Advocate
Advocate

Hi

these two codes below select all the hatches even from frozen and switched off layers

 

1.

(sssetfirst nil (ssget "X" '((0 . "HATCH"))))

2.

(ssget "X" (list (cons 0 "HATCH")))
(setq sset (ssget "_P"))
(sssetfirst nil sset)

 

What to add to the code/codes to select only visible hatches ?

 

Thanks in advance!

Best Regards!

K

0 Likes
Accepted solutions (1)
1,757 Views
18 Replies
Replies (18)
Message 2 of 19

ВeekeeCZ
Consultant
Consultant

Not that simple.

 

(defun :LayerListEditable (/ d l)
  (while (setq d (tblnext "layer" (null d)))
    (if (not (or (minusp (cdr (assoc 62 d)))		; on
		 (= 1 (logand (cdr (assoc 70 d)) 1))	; thawed
		 (= 4 (logand (cdr (assoc 70 d)) 4))	; unlocked
		 (wcmatch (cdr (assoc 2 d)) "*|*")))	; not in xref
      (setq l (cons (cdr (assoc 2 d)) l))))
  l)

(ssget "_X" (list '(0 . "HATCH")
		  (cons 8 (apply 'strcat (mapcar '(lambda (x) (strcat x ",")) (:LayerListEditable))))
		  (cons 410 (getvar 'ctab))))

 

0 Likes
Message 3 of 19

hak_vz
Advisor
Advisor

@karpkiSince you are learning list, instead providing you with solution, 

here is a link to @Lee_Mac  excellent  explanation of how ssget works and how to use selection

set filters. Try to write your own filter. Hint. Mode string "X" hast to be replaced with other combination.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 4 of 19

ВeekeeCZ
Consultant
Consultant

@hak_vz wrote:

@karpkiSince you are learning list, instead providing you with solution, 

here is a link to @Lee_Mac  excellent  explanation of how ssget works and how to use selection

set filters. Try to write your own filter. Hint. Mode string "X" hast to be replaced with other combination.


OK, we can use A or :L-. Then *|* filter of xrefs. There is nothing for On/Off. And over-all challenge?! Combine them all together. Am I missing something?

0 Likes
Message 5 of 19

hak_vz
Advisor
Advisor

@ВeekeeCZ 

 

Try this

 

 

 

(defun select_visible_hatches ( / p ss x1 y1 x2 y2)
(command "_zoom" "extents")
(setq p (mapcar (function getvar) '("EXTMIN" "EXTMAX")))
(setq x1 (caar p) y1 (cadar p) x2 (caadr p) y2 (cadadr p))
(setq ss (ssget "_CP" (list (list x1 y1) (list x2 y1) (list x2 y2) (list x1 y2)) '((0 . "HATCH"))))
(command "zoom" "previous")
ss
)

(setq ss (select_visible_hatches))

 

 

I hope you can get it from the code. I'm here if you need some further explanation.

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 6 of 19

ВeekeeCZ
Consultant
Consultant

Just wanted to point out that there is not a simple filter combination.

 

I would rather ZE first, then get extmin/max... if so. But newer versions might not need ZOOM at all.

 
0 Likes
Message 7 of 19

hak_vz
Advisor
Advisor

@ВeekeeCZI've changed code according to your suggestion regarding zoom. 

As you say solution is not simple but is doable by only using selection set filters.

There is no combination of filters that would remove non-visible entities from selection set.

We have filter modes for locked and thawed layers but not for hidden ones. I hope this can

reach to Autocad developers. 

_CP and F filter modes only work on visible entities and we can exploit it.

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 8 of 19

karpki
Advocate
Advocate

@hak_vz 

"Hint"

     Yes, I could use A (step 1)

"There is no combination of filters that would remove non-visible entities from selection set"

   And then deselect all around by pressing shift ( step 2)

It works quite good but looks not so elegant 🙂

 

Given code makes a selection set

karpki_0-1615751318865.png

but it is not highlighted in the drawing, how to f/e/ erase all selected ? or change layer or color

 

0 Likes
Message 9 of 19

hak_vz
Advisor
Advisor

@karpki wrote:

@hak_vz 

"Hint"

     Yes, I could use A (step 1)

"There is no combination of filters that would remove non-visible entities from selection set"

   And then deselect all around by pressing shift ( step 2)

It works quite good but looks not so elegant 🙂

 

Given code makes a selection set

karpki_0-1615751318865.png

but it is not highlighted in the drawing, how to f/e/ erase all selected ? or change layer or color

 


See my code posted at 5

 

Filters F and CP work only on visible entities. To avoid error with objects not visible on screen zoom is temporarily extended to drawing limits  

In my code selection set is retrieved from function  select_visible_hatches

If you want to use it in commands just use let say move !ss and all entities will be highlighted or you can

can use it in your code however you want.

(setq ss (select_visible_hatches))
(command "_.chprop" ss "" "Color" 1 ""); changes color to red

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 10 of 19

john.uhden
Mentor
Mentor

Add (60 . 0)

but if maybe the 60 doesn't exist, then

(-4 . "<NOT")(60 . 1)

John F. Uhden

0 Likes
Message 11 of 19

karpki
Advocate
Advocate

Hi

Seems like 60.0 doesn't affect the result - it is the same in test drawing as without it.

In this drawing 3 hatches visible, 1 is frozen, and the other one is out of the screen

the other code gives nil:

karpki_3-1615830173534.png

 

 

 

 

 

 

0 Likes
Message 12 of 19

karpki
Advocate
Advocate

 

The given code "select_visible_hatches" with the added command "chprop" gives selection of 4 objects.

There are 3 hatches visible, 1 is out of the screen (but was also selected) and 1 frozen (missed cause "A" instead of "X") at the drawing.

So result is similar like in case of simple (ssget "A" '((0 . "hatch")))

karpki_0-1615831198693.png

 

As I understood to use "C" "CP" or "F" is a bad idea in this situation.

 

So the issue how to select only objects visible at the screen is unsolved yet unfortunatelly

 

Even more I would say

"A" selects objects also at the switched off layers what is again bad solution.

 

BR

K

 

0 Likes
Message 13 of 19

Kent1Cooper
Consultant
Consultant

@karpki wrote:

Seems like 60.0 doesn't affect the result ....


I suspect the 60-code entry, which the DXF reference says is about "visibility," may be about Visibility State inside Block definitions, though I'm not sure.  It's certainly not about whether something is visible or not because the Layer it's on is off-or-on / frozen-or-thawed.  And my next guess -- that it's for things that are not visible because HIDEOBJECTS has been used on them -- didn't pan out; there's no 60-code entry to filter for, either way.  In fact the entity data list is identical throughout, so it's not some other DXF code, either.

 

HIDEOBJECTS appears to affect Extended Data, which for something hidden in that way contains this:

  ("ACAD" (1010 0.0 0.0 0.0)) ("ACAD" (1010 0.0 0.0 0.0))

whereas after UNhiding, or before ever Hiding, it has just one of those:

  ("ACAD" (1010 0.0 0.0 0.0))

 

In any case, you wouldn't be able to filter for that in (ssget) selection.

Kent Cooper, AIA
Message 14 of 19

john.uhden
Mentor
Mentor
Perhaps I misunderstood.
All objects have a visibility property that you can turn on/off, though
perhaps only programmatically. I think that maybe you are speaking of ones
that you can see vs. ones that may be frozen or offscreen or hidden behind
wipeouts or background fills or such.
If that's the case then use what (I forget... maybe Kent) suggested, which
I think was an ssget with filter and crossing with points computed from the
current view. I have that math somewhere. It involves "viewctr" and
"viewsize."
That way you will include ones that might just be hidden. There's no way
to filter for ones that are hidden, though you could use DRAWORDER to bring
them all to the front, if you wish.

John F. Uhden

0 Likes
Message 15 of 19

-didier-
Advisor
Advisor
Accepted solution

Bonjour @karpki 

 

I am not sure I understood but I propose a solution that will make a selection of hatches that are visible on the screen, without any notion of layer, it is a selection "window" top left of the screen bottom right of the screen.

as it is window the whole hatch must be visible

therefore the hatching must be separated when drawing

 

Amicalement

 

(defun c:H_Vert_Ecran ( / diago hd bd ss)
  (defun zone_ecran (/ A B C D X)
  (setq B (getvar "VIEWSIZE")
        A (* B (/ (car (getvar "SCREENSIZE")) (cadr (getvar "SCREENSIZE"))))
        X (trans (getvar "VIEWCTR") 1 2)
        C (trans (list (- (car X) (/ A 2.0)) (+ (cadr X) (/ B 2.0))) 2 1)
        D (trans (list (+ (car X) (/ A 2.0)) (- (cadr X) (/ B 2.0))) 2 1)
  )
  (list C D)
)  
(setq diago (zone_ecran)
      hg (car diago)
      bd (cadr diago)
      )
(setq ss (ssget  "_w" hg bd '((0 . "HATCH"))))
(command "_.chprop" ss "" "_Color" 3 "")
  )

 

Éternel débutant.. my site for learning : Programmer dans AutoCAD

DA

EESignature

0 Likes
Message 16 of 19

john.uhden
Mentor
Mentor
Bonjour aussi.
You've got all the corner math. Now just change it to WindowCrossing.
Good job!

John F. Uhden

0 Likes
Message 17 of 19

hak_vz
Advisor
Advisor

@karpki wrote:

 

The given code "select_visible_hatches" with the added command "chprop" gives selection of 4 objects.

There are 3 hatches visible, 1 is out of the screen (but was also selected) and 1 frozen (missed cause "A" i

 

As I understood to use "C" "CP" or "F" is a bad idea in this situation.

 

So the issue how to select only objects visible at the screen is unsolved yet unfortunatelly

 

 


Obviously you didn't understand. For an object to be hidden it has to be on a hidden layer i.e layer visibility turned off. Code works in a way that it temporarily zooms whole drawing through it limits and in that action it also selects entity that is being out of screen but on visible layer. If you want to select only entities that are currently visible on screen then remove parts of the code that are changing zoom.

 

Using C CP and F selection modes works really OK and its actually the fastest selection option when dealing with a lots of elements. For example my own code that I use for producing terrain sections has helped me today to produce some 50 sections over an area of 2×2 km with some 350 000 line objects in less then an hour (uses ssget F...) to separate only line objects on a crossing line. Imagine how long it would take to test all entities for possible intersection by using command inters or vla-intersectwith. Using F option filters out intersectiong object in a flick of second while testing whole set would take much longer and can even cause computer to halt.

IMOO, well written selection set filters are the best way to speed up code execution.

 

 

Zooming full extents is here just as an security that all visible objects (on visible layers) in whole drawing are selected. If you know how CP or F filter works,  zooming out is then actually not needed. So I don't use it in my sections code but instantly zoom out to make my whole drawing visible.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 18 of 19

john.uhden
Mentor
Mentor
@hak_vz
Are you saying that hidden objects are visible?
Yes, there is a huge difference between visible to the eye and visible to
ssget.
On this I think we would have to go with the OP's interpretation of visible.

John F. Uhden

0 Likes
Message 19 of 19

karpki
Advocate
Advocate

Thank you!

It works as I was thinking it should.

Now I can select different object which I see at the screen and everything else like switched off or frozen or out of the screen will be ignored!

That's fantastic!

 

Sorry All Involved to this discussion if I mixed up you.

Especcialy @hak_vz  Your power to help is incredible! Thank you !

 

I work only with 2-D drawings quite many years. That's probably the reason why I even couldn't imagine that visible or invisible mean something else except what I see or not at the screen.

Only yesterday I discovered that it can be understood differently! 

 

Best regards !!!!!

Kirill

0 Likes