Jump to content

select texts within a viewport ....question...


leonucadomi

Recommended Posts

hello all:

 

is it possible to do the following?

 

 

select a viewport from paperspace

 

and automatically select all the texts included within that viewport 

 

that they will be in modelspace?

Link to comment
Share on other sites

Hello

Try this (roughly tested)

 

(vl-load-com)
(defun l-coor2l-pt (lst flag / )
    (if lst
        (cons (list (car lst) (cadr lst) (if flag (caddr lst) 0.0))
            (l-coor2l-pt (if flag (cdddr lst) (cddr lst)) flag)
        )
    )
)
(defun c:SelTextByViewPort ( / AcDoc Space js pt_v id_vp l h lst_pt js_obj UCS save_ucs WSC nw_pl ob_lst_pt)
  (setvar "CMDECHO" 0)
  (setq
    AcDoc (vla-get-ActiveDocument (vlax-get-acad-object))
    Space (vla-get-PaperSpace AcDoc)
  )
  (vla-StartUndoMark AcDoc)
  (if (eq (getvar "CTAB") "Model") (setvar "TILEMODE" 0))
  (command "_.PSPACE")
  (princ "\nSelect a viewport: ")
  (while
    (null
      (setq js
        (ssget "_+.:E:S:L"
          (list
            '(0 . "VIEWPORT")
            '(67 . 1)
            (cons 410 (getvar "CTAB"))
            '(-4 . "!=")
            '(69 . 1)
          )
        )
      )
    )
  )
  (setq
    pt_v (cdr (assoc 10 (setq dxf_ent (entget (setq ent (ssname js 0))))))
    id_vp (cdr (assoc 69 dxf_ent))
    l (cdr (assoc 40 dxf_ent))
    h (cdr (assoc 41 dxf_ent))
    lst_pt
    (list
      (list (- (car pt_v) (* 0.5 l)) (- (cadr pt_v) (* 0.5 h)) 0.0)
      (list (+ (car pt_v) (* 0.5 l)) (- (cadr pt_v) (* 0.5 h)) 0.0)
      (list (+ (car pt_v) (* 0.5 l)) (+ (cadr pt_v) (* 0.5 h)) 0.0)
      (list (- (car pt_v) (* 0.5 l)) (+ (cadr pt_v) (* 0.5 h)) 0.0)
    )
    js_obj (ssadd)
  )
  (entmakex
    (vl-list*
      (cons 0 "LWPOLYLINE")
      (cons 100 "AcDbEntity")
      (cons 67 1)
      (cons 100 "AcDbPolyline")
      (cons 90 (length lst_pt))
      (cons 70 1)
      (mapcar '(lambda (p) (cons 10 p)) lst_pt)
    )
  )
  (ssadd (setq nw_pl (entlast)) js_obj)
  (command "_.MSPACE")
  (setvar "CVPORT" id_vp)
  (command "_.PSPACE")
  (command "_.CHSPACE" js_obj "" (if (> id_vp 2) ""))
  (command "_.MSPACE")
  (setq
    Space
    (if (eq (getvar "CVPORT") 1)
      (vla-get-PaperSpace AcDoc)
      (vla-get-ModelSpace AcDoc)
    )
    UCS (vla-get-UserCoordinateSystems AcDoc)
    save_ucs
    (vla-add UCS
      (vlax-3d-point '(0.0 0.0 0.0))
      (vlax-3d-point (getvar "UCSXDIR"))
      (vlax-3d-point (getvar "UCSYDIR"))
      "CURRENT_UCS"
    )
  )
  (vla-put-Origin save_ucs (vlax-3d-point (getvar "UCSORG")))
  (setq WCS (vla-add UCS (vlax-3d-Point '(0.0 0.0 0.0)) (vlax-3d-Point '(1.0 0.0 0.0)) (vlax-3d-Point '(0.0 1.0 0.0)) "TEMP_WCS"))
  (vla-put-activeUCS AcDoc WCS)
  (setq
    nw_pl (vlax-ename->vla-object nw_pl)
    ob_lst_pt (l-coor2l-pt (vlax-get nw_pl 'coordinates) nil)
  )
  (vla-put-layer nw_pl "0")
  (vla-delete nw_pl)
  (sssetfirst nil (ssget "_WP" ob_lst_pt '((0 . "*TEXT"))))
  (and save_ucs (vla-put-activeUCS AcDoc save_ucs))
  (and WCS (vla-delete WCS) (setq WCS nil))
  (vla-EndUndoMark AcDoc)
  (setvar "CMDECHO" 1)
  (prin1)
)

0

  • Like 2
Link to comment
Share on other sites

Maybe a simpler way you get the 4 points of the viewport then use a trans to convert the 4 points to mspace points you can then use a ssget "WP" pts. Remember to add the 1st point as last point so box closes. ie 5 points.

 

You want the opposite of this, this takes a point in mspace with a twist viewport etc and converts it to a Pspace point. 

(setq psnewcen (trans (trans newcen 1 2) 2 3))

Sorry dont have the right way at my finger tips.

 

Trying to remember if chspace works for pspace point converted to mspace I think it does. Tried this picked 4 corners of viewport and made a POINT.

image.png.bf06a4f2f492f8fa1564cedb2f65e753.png

 

You can see the points in model, the red rectangles are the viewport windows seperate code.

image.thumb.png.0ab7973737787a4c848f9407634a29b5.png

Edited by BIGAL
  • Agree 1
Link to comment
Share on other sites

Tsuky   it's great:

 

But how can I put in a variable the entire selection set of all the selected items?

 

It is to be able to delete it or change the size from paperspace.

 

17 hours ago, Tsuky said:

Hello

Try this (roughly tested)

 

(vl-load-com)
(defun l-coor2l-pt (lst flag / )
    (if lst
        (cons (list (car lst) (cadr lst) (if flag (caddr lst) 0.0))
            (l-coor2l-pt (if flag (cdddr lst) (cddr lst)) flag)
        )
    )
)
(defun c:SelTextByViewPort ( / AcDoc Space js pt_v id_vp l h lst_pt js_obj UCS save_ucs WSC nw_pl ob_lst_pt)
  (setvar "CMDECHO" 0)
  (setq
    AcDoc (vla-get-ActiveDocument (vlax-get-acad-object))
    Space (vla-get-PaperSpace AcDoc)
  )
  (vla-StartUndoMark AcDoc)
  (if (eq (getvar "CTAB") "Model") (setvar "TILEMODE" 0))
  (command "_.PSPACE")
  (princ "\nSelect a viewport: ")
  (while
    (null
      (setq js
        (ssget "_+.:E:S:L"
          (list
            '(0 . "VIEWPORT")
            '(67 . 1)
            (cons 410 (getvar "CTAB"))
            '(-4 . "!=")
            '(69 . 1)
          )
        )
      )
    )
  )
  (setq
    pt_v (cdr (assoc 10 (setq dxf_ent (entget (setq ent (ssname js 0))))))
    id_vp (cdr (assoc 69 dxf_ent))
    l (cdr (assoc 40 dxf_ent))
    h (cdr (assoc 41 dxf_ent))
    lst_pt
    (list
      (list (- (car pt_v) (* 0.5 l)) (- (cadr pt_v) (* 0.5 h)) 0.0)
      (list (+ (car pt_v) (* 0.5 l)) (- (cadr pt_v) (* 0.5 h)) 0.0)
      (list (+ (car pt_v) (* 0.5 l)) (+ (cadr pt_v) (* 0.5 h)) 0.0)
      (list (- (car pt_v) (* 0.5 l)) (+ (cadr pt_v) (* 0.5 h)) 0.0)
    )
    js_obj (ssadd)
  )
  (entmakex
    (vl-list*
      (cons 0 "LWPOLYLINE")
      (cons 100 "AcDbEntity")
      (cons 67 1)
      (cons 100 "AcDbPolyline")
      (cons 90 (length lst_pt))
      (cons 70 1)
      (mapcar '(lambda (p) (cons 10 p)) lst_pt)
    )
  )
  (ssadd (setq nw_pl (entlast)) js_obj)
  (command "_.MSPACE")
  (setvar "CVPORT" id_vp)
  (command "_.PSPACE")
  (command "_.CHSPACE" js_obj "" (if (> id_vp 2) ""))
  (command "_.MSPACE")
  (setq
    Space
    (if (eq (getvar "CVPORT") 1)
      (vla-get-PaperSpace AcDoc)
      (vla-get-ModelSpace AcDoc)
    )
    UCS (vla-get-UserCoordinateSystems AcDoc)
    save_ucs
    (vla-add UCS
      (vlax-3d-point '(0.0 0.0 0.0))
      (vlax-3d-point (getvar "UCSXDIR"))
      (vlax-3d-point (getvar "UCSYDIR"))
      "CURRENT_UCS"
    )
  )
  (vla-put-Origin save_ucs (vlax-3d-point (getvar "UCSORG")))
  (setq WCS (vla-add UCS (vlax-3d-Point '(0.0 0.0 0.0)) (vlax-3d-Point '(1.0 0.0 0.0)) (vlax-3d-Point '(0.0 1.0 0.0)) "TEMP_WCS"))
  (vla-put-activeUCS AcDoc WCS)
  (setq
    nw_pl (vlax-ename->vla-object nw_pl)
    ob_lst_pt (l-coor2l-pt (vlax-get nw_pl 'coordinates) nil)
  )
  (vla-put-layer nw_pl "0")
  (vla-delete nw_pl)
  (sssetfirst nil (ssget "_WP" ob_lst_pt '((0 . "*TEXT"))))
  (and save_ucs (vla-put-activeUCS AcDoc save_ucs))
  (and WCS (vla-delete WCS) (setq WCS nil))
  (vla-EndUndoMark AcDoc)
  (setvar "CMDECHO" 1)
  (prin1)
)

0

 

Link to comment
Share on other sites

Quote

ACCOMPLISHED... THANK YOU

However, I answer...

 

Many solutions:

1 Without modifying the code, do the command line immediately after use:

(setq my_set (command "_.PSELECT" "_Previous" ""))


Will assign to the my_set variable the selection set made.

 

2 By modifying line 88 in the code (without declaring my_set as a local variable in the code):

(sssetfirst nil (ssget "_WP" ob_lst_pt '((0 . "*TEXT"))))


by
 

(sssetfirst nil (setq my_set (ssget "_WP" ob_lst_pt '((0 . "*TEXT")))))

 

3 By modifying the code like this:
Delete line 88 and replace the line at the end:

(prin1)


by
 

(ssget "_WP" ob_lst_pt '((0 . "*TEXT")))

This last solution will allow for example to include it in another lisp (after loading) by the following syntax:
 

(setq my_set (C:seltextbyviewport))

 

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