Jump to content

Inverse selectionset on a "x" statement


halam

Recommended Posts

Thanks, once again Tharwat! Always learning something new from you bit by bit.

You are very welcome.

 

Would like to see your modification on the codes specially the part we were talking about.

Furthermore you can build a filter in the last ssget function to select only the objects that are invisible.

Difficult? I don't think so. :)

Link to comment
Share on other sites

  • Replies 28
  • Created
  • Last Reply

Top Posters In This Topic

  • Grrr

    11

  • Tharwat

    8

  • halam

    8

  • Lee Mac

    2

Top Posters In This Topic

So here is it, with non-VLA approach on the visibility part:

; Original code by Lee Mac
(setq acadobject (vlax-get-Acad-Object))
(setq acdoc (vla-get-activedocument acadobject))

(setq VisReact:reactorid "VisReact:reactor")

(defun c:VisReactOn nil
   (VisReact:toggle VisReact:reactorid)
   (vlr-miscellaneous-reactor VisReact:reactorid '((:vlr-pickfirstmodified . VisReact:callback))) ; reactor type: miscellaneous, reactor event: pickfirstmodified
   (princ "\nReactor enabled.")
   (princ)
)
(defun c:VisReactOff nil
   (VisReact:toggle VisReact:reactorid)
   (princ "\nReactor disabled.")
   (princ)
)
(defun VisReact:toggle ( key )
   (foreach rtr (cdar (vlr-reactors :vlr-miscellaneous-reactor))
       (if (= key (vlr-data rtr)) (vlr-remove rtr))
)
)
(defun VisReact:callback ( rtr arg )
   (if
	(and 
		(setq SS (cadr (ssgetfirst)))
		(setq sel (ssget "_X" (list (cons 60 0)(cons 410 (getvar 'ctab)))))
	)
	(progn
		(repeat (setq i (sslength sel)) 
			(setq ent (ssname sel (setq i (1- i)))) 
			(cond 
				((ssmemb ent SS)
					(PutEntInvisible ent nil) 
				)
				(T
					(PutEntInvisible ent T) 
				)
			)
		);repeat
		(vla-Regen acdoc :vlax-true)
	)
	(progn
		(repeat (setq i (sslength sel)) ; iterate trought selection
			(setq ent (ssname sel (setq i (1- i)))) ; current entity
			(PutEntInvisible ent nil)
		);repeat
		(vla-Regen acdoc :vlax-true)
	)
)
   (princ)
) ; end of reactor callback

(vl-load-com) (princ)

(defun PutEntInvisible ( ent vs / i k)
(setq k (if vs 1 0))
(entmod (append (entget ent) (list (cons 60 k))))
(entupd ent)
)

 

I like this ssmemb function, and it answers OP's main question I mean by this example:

(although he got the code he needed)

(defun C:test ( / SSL SSX SSL-Inverse ent)
(if
	(and
		(setq SSL (ssget "_:L"))
		(setq SSX (ssget "_X"))
		(setq SSL-Inverse (ssadd))
	)
	(progn
		(repeat (setq i (sslength SSX)) 
			(setq ent (ssname SSX (setq i (1- i)))) 
			(cond
				((ssmemb ent SSL)
					nil
				)
				(T
					(ssadd ent SSL-Inverse)
				)
			)	
		)	
		(princ "\nSelected the opposite objects!") (sssetfirst nil SSL-Inverse) 
	)
)
(princ)
)

Link to comment
Share on other sites

(cond ((ssmemb ent SS) (PutEntInvisible ent nil) )
(T (PutEntInvisible ent T) )
)

This is enough:

(PutEntInvisible ent (if (ssmemb ent SS) nil t))

 

Regarding to function vla-regen that you use it two times just move it out of the function if codes and use it once.

Link to comment
Share on other sites

Regarding to function vla-regen that you use it two times just move it out of the function if codes and use it once.

Woops! Alright, I was just afraid to mess up something as I'm dealing with a reactor.

Thanks for the correction, seems more like we're playing a game "lets shorten the code" :D

Link to comment
Share on other sites

I am trying to work out a way to change the display ground to show that you are in a other visibility state.

Is there a way to store the variabele 'currGraphicsWinModelBackgrndColor' properly global in order that the other functions (later) can use this value?

In my example descriped above the inverse command should switch to the old setting with the black background.

The code beneith i found in the help files but i have no clue how i can use it in a decent matter..

 

 

 

(setq acadObj (vlax-get-acad-object))

(setq doc (vla-get-ActiveDocument acadObj))

(setq preferences (vla-get-Preferences acadObj))

 

;; Retrieve the current GraphicsWinModelBackgrndColor value

(setq currGraphicsWinModelBackgrndColor (vlax-variant-change-type (vla-get-GraphicsWinModelBackgrndColor (vla-get-Display preferences)) vlax-vbLong))

(alert (strcat "The current value for GraphicsWinModelBackgrndColor is " (itoa (vlax-variant-value currGraphicsWinModelBackgrndColor))))

 

;; Change the value for GraphicsWinModelBackgrndColor

(vla-put-GraphicsWinModelBackgrndColor ACADPref (vlax-make-variant 127 19))

(setq newValue (vlax-variant-change-type (vla-get-GraphicsWinModelBackgrndColor ACADPref) vlax-vbLong))

(alert (strcat "The new value for GraphicsWinModelBackgrndColor is " (itoa (vlax-variant-value newValue))))

 

;; Reset GraphicsWinModelBackgrndColor to its original value

(vla-put-GraphicsWinModelBackgrndColor ACADPref currGraphicsWinModelBackgrndColor)

(alert (strcat "The GraphicsWinModelBackgrndColor value is reset to " (itoa (vlax-variant-value currGraphicsWinModelBackgrndColor))))

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