Jump to content
MJLM

How to count blocks within a viewport through paperspace environment

Recommended Posts

MJLM

I would like to count blocks of a drawing through a viewport in paperspace. I tried with the following but does not recognize any entities from the actual model within the viewport, only the viewport itself.

Any suggestions will be appreciated.

 

(if (setq layout (entget (car (entsel "\nSelect viewport: "))))
		(progn
			(setq vpcenter (cdr (assoc 10 layout)))
			(setq xlen (cdr (assoc 40 layout)))
			(setq ylen (cdr (assoc 41 layout)))
			(setq ptlowleft (mapcar '- vpcenter (list (/ xlen 2) (/ ylen 2) 0.0)))
			(setq pthighright (mapcar '+ vpcenter (list (/ xlen 2) (/ ylen 2) 0.0)))
			(setq sprsel (ssget "_W" ptlowleft pthighright '((0 . "INSERT"))))
		)
	)

 

Share this post


Link to post
Share on other sites
Lee Mac

Since you are using a graphical selection method, you will need to make the viewport active before issuing the ssget expression.

 

One method of activating a viewport is using the mspaceactivepviewport ActiveX properties of the Document object, e.g.:

(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(vla-put-mspace doc :vlax-true)
(vla-put-activepviewport doc (vlax-ename->vla-object <viewport-entity>))

Also note that you should test for null input before issuing the entget function, since this function will error when supplied with a nil value - as such, your if statement should become:

(if (setq vpentity (car (entsel "\nSelect viewport: ")))

You may also want to test whether the object selected is in fact a viewport.

Share this post


Link to post
Share on other sites
MJLM

I kinda did that already looking here and there using the

 

(command "_.mspace")

The problem is, the two points I calculate are part of the paper space, not the model space. Therefore the sprsel returns nil. Obviously this method does not work like that. Am I missing something or should I let go my hopes?

 

About the second part, my bad, I just wrote that quick. But thanks anyway.

Share this post


Link to post
Share on other sites
MJLM

ok it is done. I should have respected the trans command more.

 

(defun c:test (/ layout vpcenter xlen ylen ptlowleft pthighright vpentity sprsel)

	; *acDoc* is global

	(if (not (eq (getvar 'CTAB) "Model"))
		(if (and
				(setq vpentity (car (entsel "\nSelect viewport: ")))
				(eq (cdr (assoc 0 (setq layout (entget vpentity)))) "VIEWPORT")
			)
			(progn
                		(setq vpcenter (cdr (assoc 10 layout)))
               			(setq xlen (cdr (assoc 40 layout)))
               			(setq ylen (cdr (assoc 41 layout)))
               			(setq ptlowleft (trans (mapcar '- vpcenter (list (/ xlen 2) (/ ylen 2) 0.0)) 3 2))
                        (setq pthighright (trans (mapcar '+ vpcenter (list (/ xlen 2) (/ ylen 2) 0.0)) 3 2))
                        (vla-put-mspace *acDoc* :vlax-true)
                        (vla-put-activepviewport *acDoc* (vlax-ename->vla-object vpentity))
                        (setq sprsel (ssget "_W" ptlowleft pthighright '((0 . "INSERT"))))
                        (vla-put-mspace *acDoc* :vlax-false)
                        (if sprsel (alert (itoa (sslength sprsel))))
			)
		)
		(prompt "\nCommand cannot be invoked in model space.")
	)

(princ)

)

 

 

Edited by MJLM

Share this post


Link to post
Share on other sites
MJLM

OK, so it works now. The files I am working on is 3D which spans also in z axis and I would like to clip it in specific Z values, say from +6.00m to +9.00m and showing this portion in the viewport. Tried using the 3Dclip command but then the ssget gives wrong selection. I found out that the trans command (see code above) does not work properly now and giving wrong coordinates. Anyone has an idea what is going on?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×