Jump to content

How to count blocks within a viewport through paperspace environment


Recommended Posts

Posted

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"))))
		)
	)

 

Posted

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.

Posted

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.

Posted (edited)

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
  • Like 1
Posted

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?

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