Link Polyline in model space to viewport in paper space

Link Polyline in model space to viewport in paper space

jwright1962
Advocate Advocate
869 Views
3 Replies
Message 1 of 4

Link Polyline in model space to viewport in paper space

jwright1962
Advocate
Advocate

Suppose I have a viewport in paperspace at some defined predefined scale drawn around a detail of something.  Is it possible to link (via ARX) a rectangular polyline in  modelspace to that paperspace viewport?   When the modelspace polyline is stretched, scaled or the corners change then have the ARX update the 4 corners of the "linked" paperspace viewport accordingly.  Someone posted "VP-OUTLINE" that creates a polyline in modelspace  at the corners of a paperspace viewport.  It seems that'd be a great start and seems like it wouldn't be a "heavy lift" to link that polyline to the viewport.   The only issue, my lisp skills aren't quite to that level, but, I do have some abilities if there was some "starter" code on the "linking" portion, i might be able to finish it.

 

The concept is that I spend a "goodly" amount of time resizing viewports.   Sometimes when a model space detail gets "larger" i miss/forget stretching the viewport to accommodate the new detail and text or dimensions get "cut off", however, if i had a polyline on a nonplot layer in modelspace as a visual que around the detail i'd "always" know the viewport was proper size to the detail if they were ARX linked.    Any help appreciated!!  thank you forum for any reply.

0 Likes
870 Views
3 Replies
Replies (3)
Message 2 of 4

Sea-Haven
Mentor
Mentor

If you do a shape in modelspace for every viewport can just erase all existing and create new ones there is no problems looping through layouts and getting the viewports, will run pretty quick. Much easier than making reactor.

0 Likes
Message 3 of 4

jwright1962
Advocate
Advocate

Thanks for the reply...  wasn't sure i was gonna get one... 🙂   Not exactly sure what you mean...  a shape in modelspace?   i guess you mean a polyline that's linked to the viewport and then "beforeplot" check/resize the viewports accordingly?

0 Likes
Message 4 of 4

Moshe-A
Mentor
Mentor

@jwright1962 hi,



Check this DPVP (Duplicate Viewports) command. it requires you to lay the viewports on agreed target layer:

CL#5: (setq VPLAY "vp") 

 

by default it is set to "vp" layer. you can change it here (code line #5) to any other you like. there is no link between the viewport and pline (on model) instead each time you modify the viewport (or plan to plot) run DPVP.

 

Note:

if you forget to lay all viewports on target layer, you will be alert. viewports that are not on target layer are filtered out and you will not be alert.

 

the command starts with deleting all old plines on target layer in model space (if they are exist?!) than select all viewports on target layer in current layout.

 

Nice feature 🤣

the drawing state is saved before process and puts you back where you were (e.g in mspace or pspace). 

 

enjoy

Moshe

 

 

 

(vl-load-com) ; load activex support

; Duplicate  viewports
(defun c:DPVP (/ VPLAY adoc savTM sav CVPort ss ename0 ename1 elist0 AcDbPline0 AcDbPline1 sa wht hgt c0 p0 p1 clone)
 (setq VPLAY "vp") ; const, target layer

 (setvar "cmdecho" 0)
 (command "._undo" "_begin")
  
 (setq adoc (vla-get-activedocument (vlax-get-acad-object)))

 ; save drawing state 
 (setq savTM     (getvar "tilemode"))
 (setq savCVPort (getvar "cvport"  ))

 (setvar "tilemode" 0) ; switch to layout
 (command "._pspace")    ; move to pspace 
  
 ; delete previous polylines but first make sure layer is on and unlocked
 (command "._layer" "_thaw" VPLAY "_unlock" VPLAY "")
 (if (setq ss (ssget "_x" (list '(0 . "*polyline") (cons '8 VPLAY) '(410 . "Model"))))
  (foreach ename0 (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
   (entdel ename0) 
  )
 ); if

  
 ; Select all viewports on target layer in current layout
 (if (not (setq ss (ssget "_x" (list '(0 . "viewport") (cons '8 VPLAY) (cons '410 (getvar "ctab"))))))
  (progn
   (vlr-beep-reaction)
   (alert (strcat "No viewports found on layer \"" VPLAY "\" in current layout"))
  ); progn
  (progn
   (foreach ename0 (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))   
    (setq elist0 (entget ename0))

    (cond
     ((setq ename1 (cdr (assoc '340 elist0))) 		; has linked pline?
      (setq AcDbPline1 (vlax-ename->vla-object ename1))	; get it

      ; get viewport center point
      (setq AcDbPline0 (vlax-ename->vla-object ename0))
      (setq c0 (vlax-safearray->list (vlax-variant-value (vla-get-center AcDbPline0))))
      (vlax-release-object AcDbPline0)
				       
      (setq sa (vlax-make-safearray vlax-vbObject '(0 . 0)))
      (vlax-safearray-put-element sa 0 AcDbPline1)
      (setq clones (vla-copyObjects adoc sa)) ; duplicate linked pline

      (foreach obj (vlax-safearray->list (vlax-variant-value clones))
       (vlax-release-object obj) ; ; dispose memory
      )
	
      (vlax-release-object AcDbPline1) ; dispose memory
     ); case
     ( t
      (setq c0  (cdr (assoc '10 elist0)))
      (setq wht (cdr (assoc '40 elist0)))
      (setq hgt (cdr (assoc '41 elist0)))

      (setq p0 (list (- (car c0) (/ wht 2)) (- (cadr c0) (/ hgt 2))))
      (setq p1 (list (+ (car c0) (/ wht 2)) (+ (cadr c0) (/ hgt 2))))

      (command "._rectangle" "_None" p0 "_None" p1)
     ); case
    ); cond

    ; send it to target layer
    (command "._chprop"  "_si" (entlast) "_Layer" VPLAY "")
     
    (command ".mspace") 		       ; switch mspace
    (setvar "cvport" (cdr (assoc '69 elist0))) ; make it current viewport
    (command "._pspace")		       ; back to pspace	

    ; send it to mspace
    (if (= (sslength ss) 1)
     (command "._chspace" "_si" (entlast))
     ; else, there are more than 1 viewport on layout
     (command "._chspace" "_si" (entlast) c0 "")
    ); if
    (command "._pspace"); back to pspace
   ); foreach

  ); progn
 ); if

 ; restore drawing state
 (if (> savCVPort 1)
  (progn 
   (command "._mspace")
   (setvar "cvport"   savCVPort)
  ); progn
 ); if
 (setvar "tilemode" savTM)
  
 (vlax-release-object adoc) ; dispose memory

 (command "._undo" "_end") 
 (setvar "cmdecho" 1)  

 (princ)
); c:DPVP

 

 

0 Likes