Jump to content

Creating multiple viewports issue


danglar

Recommended Posts

This subroutine can create ONE rectangular viewport (as a part of other main routine)


(Defun VportRET (/ Ang Diag Pt1 Pt2 Pt2Lay Ptmed)
(setvar "clayer" LayFIN)
(setq Pt1 (getpoint "\nSpecify first window corner: "))
(setq Pt2 (getcorner pt1 "\nSpecify opposite corner: "))
(setq Ang (angle pt1 pt2))
(setq Diag (distance pt1 pt2))
(setq PtMed (polar Pt1 Ang (/ Diag 2)))
(setvar "CTAB" Lay)
(if (/= 1 (getvar "cvport"))(command "_.Pspace"))
  (if (/= SCA "Add")
      (progn
        (setq Pt2Lay (polar '(0 0) Ang (* Diag (atof FattZoom))))
        (command "_.dragmode" "_auto")
        (setvar "osmode" 0)
        (command "_.-vports" "0,0" Pt2Lay)
        (setq Ent (entget (entlast)))
        (setq Entname (cdr (assoc -1 Ent)))
        (setq NumVP (cdr (assoc 69 Ent)))
        (command "_.zoom" "_w" "0,0" Pt2Lay)
        (command "_.mspace")
        (setvar "cvport" NumVP)
        
        (command "_.zoom" "_c" Ptmed ScXP)
        (command "_.pspace")
        (Command "zoom" "_all")
        (setvar "osmode" oldsnap)
        (princ "\nSpecify insertion point of viewport in Layout: ")(princ)
        (command "_.move" Entname "" "0,0" pause )
        (command "_.mview" "_l" "_on" Entname "")
       )
  )    
  (if (= SCA "Add")
      (progn
        (setq Wc1 (getpoint "\nSpecify first window corner: "))
        (princ "\nSpecify opposite corner: ")
        (command "_.-vports" Wc1 pause)
        (setq Ent (entget (entlast)))
        (setq Entname (cdr (assoc -1 Ent)))
        (setq NumVP (cdr (assoc 69 Ent)))
        (command "_.mspace")
        (setvar "cvport" NumVP)
       
        (command "_.zoom" "_w" Pt1 Pt2)
        (command "_.pspace")
        (Command "zoom" "_all")
        (command "_.mview" "_l" "_on" Entname "")
        (setq WriteScala "0")
      )
  )
) 

 need to add option to create multiple viewports (more than one) depend of number given by user like it shown in a different subroutine (also a part of other main routine)

 

                 (setq lpno 2) ; Loop counter for making separate viewports
                  (setq vpno (getint "\nNumber of separate viewports to make from this viewport <1>: ")) ; Will divide single viewport into separate viewports for othagonal views of 2D part
                  (if (>= vpno 2) ; Proceed to copy current viewport if 2 or more separate viewports desired
                    (progn
                      (while (<= lpno vpno) ; Check if viewport loop counter less than number of viewports desired
                        (command "copy" ssvp "" "0,0" "@0,0") ; Make copy of new viewport laying exactly on top of first viewport
                        (setq lpno (1+ lpno)) ; Increment viewport loop counter
			(ssadd (entlast) ssvp1) ; Add viewport copy to selection set
		      )
		    )
		  )
                  (setq ssnum 0) ; Loop counter for fine-tuning separate viewports
                  (while (< ssnum (sslength ssvp1)) ; Opportunity to fine-tune each separate viewport border
		    (setq vpent (ssname ssvp1 ssnum)) ; Get entity name of next viewport in selection set
		    (if (>= vpno 2) ; Check for multiple viewports
		      (setq clt (strcat " #" (rtos (+ ssnum 1) 2 0))) ; Make command prompt string if using multiple viewports
		      (setq clt "") ; Make command prompt string if using single viewport
		    )
                    (initget 128) ; Enable string responses from point prompt
(setvar "osmode" 32)
		    (setq nvpc1 (getpoint (strcat "\nSpecify first corner of viewport" clt " window area: "))) ; Pick actual part corner, program will apply offset
		    (if nvpc1 ; Will repeat asking for first corner if none specified
		                
			  (progn
			    (setq nvpc2 (getcorner nvpc1 (strcat "\nSpecify opposite corner of viewport" clt " window area: "))) ; Window rectangle can be designated in any direction, pick actual part corner, program will apply offset
			    (if nvpc2 ; Will repeat asking for first corner if none specified
			      (progn
                                (setq nvpc1x (car nvpc1)) ; Find X portion of first corner
                                (setq nvpc1y (cadr nvpc1)) ; Find Y portion of first corner
	                        (setq nvpc2x (car nvpc2)) ; Find X portion of second corner
                                (setq nvpc2y (cadr nvpc2)) ; Find Y portion of second corner
			        (if (> nvpc2x nvpc1x) ; Determine horizontal direction of viewport window rectangle
  			          (progn
			            (setq nvpc2x (+ nvpc2x ofs)) ; Add horizontal offset to right of specified left-to-right window rectangle
			            (setq nvpc1x (- nvpc1x ofs)) ; Add horizontal offset to left of specified left-to-right window rectangle
			          )
			          (progn
  			            (setq nvpc2x (- nvpc2x ofs)) ; Add horizontal offset to left of specified right-to-left window rectangle
			            (setq nvpc1x (+ nvpc1x ofs)) ; Add horizontal offset to right of specified right-to-left window rectangle
			          )
			        )
			        (if (> nvpc2y nvpc1y) ; Determine vertical direction of viewport window rectangle
 			          (progn
			            (setq nvpc2y (+ nvpc2y ofs)) ; Add vertical offset to top of specified lower-to-upper window rectangle
			            (setq nvpc1y (- nvpc1y ofs)) ; Add vertical offset to bottom of specified lower-to-upper window rectangle
			          )
			          (progn
			            (setq nvpc2y (- nvpc2y ofs)) ; Add vertical offset to bottom of specified upper-to-lower window rectangle
			            (setq nvpc1y (+ nvpc1y ofs)) ; Add vertical offset to top of specified upper-to-lower window rectangle
			          )
			        )
			        (setvar "osmode" 0) ; Turn osnap off
			        (command "rectang" (list nvpc1x nvpc1y) (list nvpc2x nvpc2y)) ; Make rectangle with offset to clip existing viewport
			        (setvar "osmode" 2559) ; Turn osnap on
			        (setq ssvp (ssget "L")) ; Select last rectange
			        (command "vpclip" vpent ssvp) ; Clip existing viewport to rectangle
                                (command "vpclip" ssvp "d" ) ; Convert Polygonal Vport to Rectangular
			        (setq ssnum (1+ ssnum)) ; Increment fine-tuned viewport loop counter
			      )
			    )
			  )
			)
	              
		    )
		  )
                )  
              )
            )
	  )
	)
      )
    )

On this stage It's very complicated for me to do it because of different combinations of variables in these 2 subroutines

 

Can somebody help me to do it and add necessary addition to the first subroutine?

Any help will be very appreciated  

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