Jump to content

Recommended Posts

Posted

I've got an interesting project...(this is VB.NET)...

 

I need to move through each viewport on each layout tab in a drawing, doing a zoom-extents in each one.

 

I know it will entail a couple of loops, but I keep getting hung up on moving through all the viewports.

 

Here's some code...

****************************************

For Each Item In Me.lbSelectAnAutoCADLayout.SelectedItems

 

objAcad.ActiveDocument.ActiveLayout = objAcad.ActiveDocument.Layouts.Item(Item)

OriginalSpace = objAcad.ActiveDocument.ActiveSpace

 

objAcad.ActiveDocument.SendCommand("pspace" & vbCr)

objAcad.ActiveDocument.SendCommand("zoom extents ") objAcad.ActiveDocument.SendCommand("mspace" & vbCr)

objAcad.ActiveDocument.SendCommand("zoom extents ")

objAcad.ActiveDocument.ActiveSpace = OriginalSpace

 

Next

****************************************

 

Eventually I'll need to find and activate a specific viewport on a layout (based on viewport width). But for now, just moving through each viewport on each tab in a drawing will be sufficient.

 

Thanks in advance for your expert help!

 

Go CADTutor!

Posted

Function in lisp

(defun vpactivate ( width  / ss avp)
 ;;; width [real] - viewport width for activate
 ;;; Usage
 ;;; (VPACTIVATE 199)
 ;;; Activate VIEWPORT with width 199
 ;;; Return number (for CVPORT command) VIEWPORT in layout or nil
(vl-load-com)
(if (setq SS (ssget "_X" (list '(0 . "VIEWPORT") '(-4 . "/=") '(68 . 1)(cons 410 (getvar "ctab")))))
  (progn
    (foreach vp (vl-remove-if (function listp)
	 (mapcar (function cadr) (ssnamex ss)))
      (if (equal (cdr(assoc 40 ;_Width code. Height code - 41
                            (entget vp)
                            )
                     )
                 width
                 1e-6
                 )
        (progn
          (setq avp (cdr(assoc 68 (entget vp))))
          (command "_MSPACE" "_CVPORT" avp "_PSPACE")
          
          )
          )
      )
    )
  )
 avp
 )

Load this functions and use

objAcad.ActiveDocument.SendCommand("(VPACTIVATE 199)" & vbCr)

199 - width specific viewport

Posted

Thanks VVA!! Well done!

 

(I think I can use this as a temporary solution.)

 

I still need a VB dot NET solution...

 

(Thanks again VVA...your LISP solution is clean and elegant...and it works!)

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