Jump to content

[Help] How to check if entity lay in a Viewport


ketxu

Recommended Posts

Please help me, i've a problem :

How to check if entity be viewed in a Viewport ?

For Ex, how can i erase , or locked...or do sth.. all viewport that view into a Line ?

Srr for my poor English and Thanks all ^^

Link to comment
Share on other sites

You would need to translate the Viewport Boundary to Modelspace coordinates using the correct transformation matrix based on the scale/twist etc of the viewport (I think gile wrote a function to calculate this matrix), then check whether your objects lie within this point set.

Link to comment
Share on other sites

Thank you very much Lee :) I try it now ^^

 

You're welcome :)

 

P/s : i'm digging Theswamp and lisp..wow.. how a great data to learn and learn and learn...

 

TheSwamp is awesome - so many clever guys there.

Link to comment
Share on other sites

As an example for you, this quickly written code will use gile's PCS2WCS function to create an LWPolyline Viewport boundary in Modelspace:

 

(defun c:test ( / _lwvertices _lwpoly cen ent lst vp x )

   (defun _lwvertices ( e )
       (if (setq e (member (assoc 10 e) e))
           (cons (cons (cdr (assoc 10 e)) (assoc 42 e)) (_lwvertices (cdr e)))
       )
   )

   (defun _lwpoly ( l )
       (entmakex
           (append
               (list
                  '(0 . "LWPOLYLINE")
                  '(100 . "AcDbEntity")
                  '(100 . "AcDbPolyline")
                   (cons 90 (length l))
                  '(70 . 1)
                  '(410 . "Model")
               )
               (apply 'append l)
           )
       )
   )
   
   (if (setq vp (ssget "_+.:E:S" '((0 . "VIEWPORT"))))
       (progn
           (setq vp (entget (ssname vp 0)))
           (if (setq ent (cdr (assoc 340 vp)))
               (setq lst (_lwvertices (entget ent)))
               (setq cen (mapcar 'list (cdr (assoc 10 vp))
                             (list
                                 (/ (cdr (assoc 40 vp)) 2.0)
                                 (/ (cdr (assoc 41 vp)) 2.0)
                             )
                         )
                     lst (mapcar
                             (function
                                 (lambda ( a ) (cons (mapcar 'apply a cen) '(42 . 0.0)))
                             )
                            '((- -) (+ -) (+ +) (- +))
                         )
               )
           )
           (setq vp (cdr (assoc -1 vp)))
           (_lwpoly (mapcar '(lambda ( x ) (list (cons 10 (PCS2WCS (car x) vp)) (cdr x))) lst))
       )
   )
   (princ)
)

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