Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

get bounding box of entities on layer & use for ssget with filter

16 REPLIES 16
SOLVED
Reply
Message 1 of 17
mid-awe
1737 Views, 16 Replies

get bounding box of entities on layer & use for ssget with filter

Hi all,

 

I am attempting to make a selection-set of all entities within the bounding box of all entities on a specific layer.

 

I know that sounds confusing so I'll try to explain. I need to get the bounding box of my border & use it with ssget to select all blocks while ignoring all blocks outside of my border.

 

I have having trouble feeding the bounding box points to the ssget function. What am I doing wrong?

 

(AND (SETQ BLST	(LIST "BUZZTOP"	"CANISTER1" "FUSECANISTER2" "MDXR3" "NOZZLE" "P3" "PP" "StepNozzle" "VENTURISKIMMER2")
	   SS	(SSADD)
	   S	(SSGET "x" '((8 . "BORDER")))
     )
     (VLA-GETBOUNDINGBOX (VLAX-ENAME->VLA-OBJECT (SSNAME S 0)) 'LL 'UR)
     (SETQ LL  (VLAX-SAFEARRAY->LIST LL)
	   UR  (VLAX-SAFEARRAY->LIST UR)
	   SS1 (SSGET "B" 'LL 'UR (LIST '(0 . "insert") (CONS 2 (STRCAT "`*U*" BLST)) '(410 . "Model")))
     )
)

 Thanks in advance for any help.

16 REPLIES 16
Message 2 of 17
hmsilva
in reply to: mid-awe

Hi mid-awe,

perhaps something like this

 

(AND (SETQ BLST	 ",BUZZTOP,CANISTER1,FUSECANISTER2,MDXR3,NOZZLE,P3,PP,StepNozzle,VENTURISKIMMER2l"
	   SS	(SSADD)
	   S	(SSGET "x" '((8 . "BORDER") (410 . "Model")))
     )
     (VLA-GETBOUNDINGBOX (VLAX-ENAME->VLA-OBJECT (SSNAME S 0)) 'LL 'UR)
     (SETQ LL  (VLAX-SAFEARRAY->LIST LL)
	   UR  (VLAX-SAFEARRAY->LIST UR)
		   SS1 (SSGET "w" LL UR (LIST '(0 . "insert") (CONS 2 (STRCAT "`*U*" BLST)) '(410 . "Model")))
     )
)

 

Henrique

EESignature

Message 3 of 17
mid-awe
in reply to: hmsilva

Unfortunately that didn't work. I had thought it just might since I really don't know if the "B" box selection option still exists in AC2014 (I'm using).

My border is made of a single closed lwpolyline, if that makes any difference. The only other thing that I can think of is that my bounding box points return as:

((-1.0e-008 -1.00001e-008 -1.0e-008) (1584.0 996.0 1.0e-008))

It's unrecognizable to me, maybe someone can determine the issue. Is that point list good? I'm not sure what I'm looking at there.
Message 4 of 17
hmsilva
in reply to: mid-awe

Should work, I did change the "B" mode to "W"...

 

Try this one

 

(AND (SETQ BLST	 ",BUZZTOP,CANISTER1,FUSECANISTER2,MDXR3,NOZZLE,P3,PP,StepNozzle,VENTURISKIMMER2"
	   SS	(SSADD)
	   S	(SSGET "x" '((8 . "BORDER") (410 . "Model")))
     )
     (VLA-GETBOUNDINGBOX (VLAX-ENAME->VLA-OBJECT (SSNAME S 0)) 'LL 'UR)
     (SETQ LL  (VLAX-SAFEARRAY->LIST LL)
	   UR  (VLAX-SAFEARRAY->LIST UR))
     (vl-cmdf "_.zoom" "_W" LL UR)
     (setq SS1 (SSGET "_W" LL UR (LIST '(0 . "insert") (CONS 2 (STRCAT "`*U*" BLST)) '(410 . "Model"))))
     (vl-cmdf "_.zoom" "_P")
)

 

Henrique

EESignature

Message 5 of 17
Lee_Mac
in reply to: mid-awe

Hi mid-awe,

 

The following is untested, but may help:

 

(defun c:test ( / app bor llp lst sel str urp )
    (setq lst '("BUZZTOP" "CANISTER1" "FUSECANISTER2" "MDXR3" "NOZZLE" "P3" "PP" "StepNozzle" "VENTURISKIMMER2")
          str  (apply 'strcat (mapcar '(lambda ( x ) (strcat "," x)) lst))
          app  (vlax-get-acad-object)
    )
    (if (setq bor (ssget "_X" '((8 . "BORDER") (410 . "Model"))))
        (progn
            (vla-getboundingbox (vlax-ename->vla-object (ssname bor 0)) 'llp 'urp)
            (vla-zoomwindow app llp urp)
            (if (setq sel
                    (ssget "_C"
                        (trans (vlax-safearray->list urp) 0 1)
                        (trans (vlax-safearray->list llp) 0 1)
                        (list
                           '(0 . "INSERT")
                            (cons 2 (strcat "`*U*" str))
                           '(410 . "Model")
                        )
                    )
                )
                (sssetfirst nil sel)
                (princ "\nNo objects found within border.")
            )
            (vla-zoomprevious app)
        )
        (princ "\nBorder not found in Modelspace.")
    )
    (princ)
)
(vl-load-com) (princ)
Message 6 of 17
mid-awe
in reply to: Lee_Mac

Thank you Lee,
That did it. Please, help me understand why yours works and Henrique and I got nil. (that's not fair of me 😉 Henrique tried to fix my mess.)

 

As I work your sample into my main program, I found that I did not work without the: 

 

(vla-zoomwindow app llp urp)

 part. It seems that just makes sure that the border is entirely visible before selecting it. I still don't understand it because I was zoomed out a little more than necessary when running the junky version. Also, 

 

(TRANS (VLAX-SAFEARRAY->LIST URP) 0 1)

 Shouldn't make a difference, unless I'm not in WCS? Right?

 

 

Message 7 of 17
mid-awe
in reply to: hmsilva

Henrique, Thank you, but it still comes up nil. Lee's sample works, now I hope he has time to shed some light on it for me.

Thanks again.
Message 8 of 17
Kent1Cooper
in reply to: mid-awe


@mid-awe wrote:
... bounding box points return as:

((-1.0e-008 -1.00001e-008 -1.0e-008) (1584.0 996.0 1.0e-008))

It's unrecognizable to me, maybe someone can determine the issue. Is that point list good? I'm not sure what I'm looking at there.

Parts of that are in scientific notation.  The e stands for exponent, applied to 10.  So 1.0e-008 means 1 times 10 to the minus-8 power, which is pretty darned close to zero.  You sometimes get that kind of result with calculated points.  It shouldn't affect the working of the routine, unless you have some things mighty close to the edge of the border, so that parts of them fall within that tiny tolerance of difference between the bounding box window and the actual outline, which doesn't seem likely in any actual drawing situation.

Kent Cooper, AIA
Message 9 of 17
mid-awe
in reply to: mid-awe

Thank you Kent.

They are in 3D points so I expected 0.0 one for each list. That is what fooled me. For a 2D drawing it made no sense.
Message 10 of 17
hmsilva
in reply to: mid-awe


@mid-awe wrote:
Henrique, Thank you, but it still comes up nil. Lee's sample works, now I hope he has time to shed some light on it for me.
Hi mid-awe,
I did add a zoom window to ensure the blocks visibility before performing the selection window, so it should select all blocks inside the border...
Henrique

EESignature

Message 11 of 17
mid-awe
in reply to: mid-awe

That is strange, when tested it only returned nil. I can't say why.

I did nothing beyond plugging Lee's code and it worked.

Thank you for your help Henrique, I am grateful. Your suggestions usually work immediately.
Message 12 of 17
hmsilva
in reply to: mid-awe

mid-awe,
it will be possible for you to attach a sample dwg with the border and a few DynaBlocks, just for testing?

Henrique

EESignature

Message 13 of 17
mid-awe
in reply to: hmsilva

I tried this again. Apparently, I didn't copy it exactly. I must've been in a hurry and only amended my code with the differences and missed the:

(vl-cmdf "_.zoom" "_W" LL UR)

part. My apologies. This version works.

Thank you Henrique.
Message 14 of 17
hmsilva
in reply to: mid-awe

You're welcome, mid-awe
Glad it worked

Henrique

EESignature

Message 15 of 17
Lee_Mac
in reply to: mid-awe

mid-awe wrote:

Thank you Lee,
That did it. Please, help me understand why yours works and Henrique and I got nil. (that's not fair of me 😉 Henrique tried to fix my mess.)

 

As I work your sample into my main program, I found that I did not work without the: 

 

(vla-zoomwindow app llp urp)

 part. It seems that just makes sure that the border is entirely visible before selecting it. I still don't understand it because I was zoomed out a little more than necessary when running the junky version.

 

As you've probably gathered, the graphical selection methods will only select objects visible on screen - this even applies to block components, as the following animation demonstrates:

 

 

I have noted this subtle behaviour in my ssget function reference, where applicable.

 

mid-awe wrote:
Also, 

 

(TRANS (VLAX-SAFEARRAY->LIST URP) 0 1)

 Shouldn't make a difference, unless I'm not in WCS? Right?

 

Correct - ssget accepts UCS points, the getboundingbox method returns points in WCS.

Message 16 of 17
mid-awe
in reply to: Lee_Mac

Thank you again Lee. Sir, you are a gentleman and a scholar.
Message 17 of 17
Lee_Mac
in reply to: mid-awe

mid-awe wrote:
Thank you again Lee. Sir, you are a gentleman and a scholar.

 

You're most welcome mid-awe. Smiley Happy

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost