Jump to content

Collecting ViewPorts in a Drawing Using VB.NET


PellaCAD

Recommended Posts

SeanT...one additional question...

 

Once I find the widest viewport...how do I set it as the current active viewport?

 

Here's my current routine...it works nicely to move through all layouts and all viewports in each layout, reportingthe viewport centerpoint as it moves through the drawing...

 

But when it hits this line... objAcad.ActiveDocument.ActivePViewport = PVport ...everything comes to a screeching halt.

Here's my little routine...

 

Dim Entity As AcadEntity

Dim VPcenter AsObject

Dim PVport As AcadPViewport

Dim lngObjectID AsLong

Dim CurrentLayout As AcadLayout

Dim PageLayouts As AcadLayouts

PageLayouts = objAcad.ActiveDocument.Layouts

objAcad.ActiveDocument.ActiveSpace = AcActiveSpace.acPaperSpace

objAcad.ActiveDocument.MSpace = False

'For Each Item In Me.lbAutoCADTabs.SelectedItems 'layout tabs are collected and shown in a listbox

ForEach CurrentLayout In PageLayouts

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

lngObjectID = objAcad.ActiveDocument.ActivePViewport.ObjectID

ForEach Entity In objAcad.ActiveDocument.ActiveLayout.Block

IfTypeOf Entity Is AcadPViewport Then

PVport = Entity

If lngObjectID PVport.ObjectID Then

VPcenter = PVport.Center

MsgBox("The center of this viewport is " & VPcenter(0) & ", " & VPcenter(1), , "View Port Center Example")

objAcad.ActiveDocument.ActivePViewport = PVport 'fails miserably here

'objAcad.ActiveDocument.SendCommand("zoom extents ") '...I use this to test if focus has been given to the viewport

EndIf

EndIf

Next Entity

'Next Item

Next CurrentLayout

 

I need to focus on a specific viewport in order to begin working with the entities shown therein.

 

Thanks SeanT,

 

Pete

Link to comment
Share on other sites

  • Replies 26
  • Created
  • Last Reply

Top Posters In This Topic

  • SEANT

    15

  • PellaCAD

    10

  • Lee Mac

    2

Top Posters In This Topic

Posted Images

What if you placed this line just before that line:

 

objAcad.ActiveDocument.MSpace = [color="Blue"]True[/color]
objAcad.ActiveDocument.ActivePViewport = PVport

Link to comment
Share on other sites

One of the lines of code commented out in your example seems like it should cause trouble with this active line of code.

 

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

 

 

Edit: Must be a typo. The example at AUGI has that line commented out as well.

Link to comment
Share on other sites

Not a typo...(it works really nicely to move through all the layouts of a drawing)...

 

The line that is commented out is a For-Next loop...I use that to cycle through the members of a pre-populated listbox...

 

In my code above (in an effort to isolate the problem, I temporarily commented that For-Next loop out), I'm building a collection of all layouts and moving through each layout (except "Model")...then cycling through all the blocks on that layout, searching for the vPViewPort that matches my width criteria...

 

When it finds the correct PViewPort, it's time for the action to start.

 

Your suggestion to insert "objAcad.ActiveDocument.MSpace = True" seemed to work at first...but then when we moved to the next layout, the program failed at the same place as before..."objAcad.ActiveDocument.ActivePViewport = vp"

 

So my question remains...What is the correct way to assign the current ActivePViewPort?

 

(Thanks to both SeanT and the Editor for reviewing my situation...)

 

Here's the code I'm testing (it's using the pre-populated listbox)...

 

PrivateSub OK2()

Dim objLayout As AcadLayout

Dim layoutBlock As AcadBlock

Dim ent As AcadEntity

Dim vp As AcadPViewport

OriginalSpace = objAcad.ActiveDocument.ActiveSpace

objAcad.ActiveDocument.ActiveSpace = AcActiveSpace.acPaperSpace

objAcad.ActiveDocument.MSpace = False

ForEach Item InMe.lbAutoCADTabs.SelectedItems 'all the tabs are listed in this listbox

objAcad.ActiveDocument.ActiveLayout = objAcad.ActiveDocument.Layouts.Item(Item) 'this works nicely

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

'If objLayout.Name "Model" Then

If Item "Model"Then

layoutBlock = objLayout.Block

MsgBox("LayoutBlock.Count = " & layoutBlock.Count)

x = 0

DoUntil x = layoutBlock.Count

ent = layoutBlock.Item(x)

Debug.Print("x = " & x)

IfTypeOf ent Is AcadPViewport Then

'vp = CType(ent, AcadPViewport)

vp = ent

If vp.Width > 24 And vp.Width

[/color]MsgBox("vp.OwnerID = " & vp.OwnerID & vbCr & _

"vp.Width = " & vp.Width)

objAcad.ActiveDocument.MSpace = True 'line per CADTutor SeanT suggestion objAcad.ActiveDocument.ActivePViewport = vp 'error occurs here - do not know why - 25AUG2009

objAcad.ActiveDocument.SendCommand("zoom extents ") '...I use this to test if focus has been given to the viewport

EndIf

EndIf

x = x + 1

Loop

objAcad.ActiveDocument.ActiveSpace = OriginalSpace

EndIf

Next Item

ExitSub

 

OK...here's another ViewPort related question...

 

How do we determine the source layout of a viewport? (The layout upon which the object viewport resides.) What method tells us this info?

Link to comment
Share on other sites

As background information: Each layout has it’s own pviewport, active when in paperspace and MSpace = False. While in this “Main” layout pviewport the size and position of the other “floating” pviewports are accessible. This main vport is always the first object in a layout’s Block. This means it can easily be avoided while iterating a layoput’s block by starting at LayoutBlock.Item(1).

 

If the view of a “floating” pviewport requires modification then change MSpace = True and activate that viewport.

 

When switching to another layout it is probably advisable to first switch back to MSpace = False.

Link to comment
Share on other sites

  • 2 weeks later...

How can you activate a specific viewport??

 

I've isolated the item number of the viewport (based on the viewport width)...but how can the item number be used to specify the current active viewport?

Link to comment
Share on other sites

What is “item number”? Is it the ObjectID or the viewport’s identification number(as employed by the system variable CVPORT)?

 

I would have thought that the coordinated use of MSpace = True/ MSpace = False along with:

objAcad.ActiveDocument.ActivePViewport = vp

would allow for viewport activation.

 

I’ve seen your posts on other forums and imagine the lack of a “cut and dry” response to the question is a bit frustrating. The problem, I think, is that you are essentially using a mixed code base with INTEROP. There probably hasn’t been enough work in that area by enough people to easily elicit the answer.

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