ketxu 发表于 2022-7-6 08:42:10

[Help] How to check if entity

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

Lee Mac 发表于 2022-7-6 08:54:51

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.

Lee Mac 发表于 2022-7-6 09:01:52

 
Found it:

http://www.theswamp.org/index.php?topic=29231.msg347755#msg347755

ketxu 发表于 2022-7-6 09:10:40

Thank you very much LeeI try it now ^^
P/s : i'm digging Theswamp and lisp..wow.. how a great data to learn and learn and learn...

Lee Mac 发表于 2022-7-6 09:17:51

 
You're welcome
 
 
TheSwamp is awesome - so many clever guys there.

Lee Mac 发表于 2022-7-6 09:30:44

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

ketxu 发表于 2022-7-6 09:37:33

Thank you Lee, it gave me some new funny idea^^

Lee Mac 发表于 2022-7-6 09:45:21

.........
页: [1]
查看完整版本: [Help] How to check if entity