Document.ActivePViewport = ViewPort_Name

Document.ActivePViewport = ViewPort_Name

rmcefr
Enthusiast Enthusiast
3,462 Views
7 Replies
Message 1 of 8

Document.ActivePViewport = ViewPort_Name

rmcefr
Enthusiast
Enthusiast

Hi everyone,

 

I added many PViewports to PaperSpace, all of them work fine except 3  PViewports return errors, as follow:-

"error setting current veiwport"

 

simply using this code:

Dim My_PViewPort As AcadPViewport
My_PViewPort = My_PViewPort = ThisDrawing.PaperSpace.AddPViewport(Viewport_CP, ViewPort_Width, ViewPort_Height)
My_PViewPort.Display(True)
ThisDrawing.MSpace = True
ThisDrawing.ActivePViewport = My_PViewPort

 

 on last line getting the error, 

but the code using to add many of Pviewports, and work well, only parameters change of width, height, center point

 

it get stacked with some of them!! 

is there any explanation for that case?

 

many thanks 

0 Likes
Accepted solutions (1)
3,463 Views
7 Replies
Replies (7)
Message 2 of 8

ntclmain
Advocate
Advocate

As I remember, a very old thread has mentioned this.
I save the link (http://forums.autodesk.com/t5/Visual-Basic-Customization/Error-setting-the-current-viewport/td-p/34...), but it is now archived

*
Try to zoom before set current PViewport:

 

Application.ZoomCenter My_PViewPort.Center, 7
ThisDrawing.MSpace = True
ThisDrawing.ActivePViewport = My_PViewPort

*
My advice: You should turn off your PViewport after creation, a lot of Display ON pviewport may critically slow down Autocad.

 

 

Message 3 of 8

rmcefr
Enthusiast
Enthusiast
Thanks ntclmain for reply

I try that but still get same error,
I tried stopped all other pviewports and keep only that one have error, and still got error, it doesn't make a sense to me while all setups similar,
0 Likes
Message 4 of 8

ntclmain
Advocate
Advocate
Accepted solution
Application.ZoomCenter My_PViewPort.Center, 7

The magnify value in the above command is 7. That zoomcenter command work in layout (Thisdrawing.MSSpace=False)

*

The meaning behind this Zoomcenter command is: sometimes cad cannot select/ set active objects... properly if it can't "see" the object.  By zoom in, you make that objects "big enough" to be seen.
I work in metric system, typical viewport scale varies from 0.1 to 5, the magnify value x7 works.

0 Likes
Message 5 of 8

rmcefr
Enthusiast
Enthusiast

Hello Friend;

 

Many thanks for help ..

 

it solved by increasing the Pviewport width and height,

 

 

 

 

 

0 Likes
Message 6 of 8

ntclmain
Advocate
Advocate

Forgive me, since I already read your draft code before you removing it (^_^)

It is not really look like VBA (VB.net interop, perhaps I guess)
*

Here is your VBA code with some changes & comments by me.  I only edit codes for the first 2 PViewports, some variables  declaration must be changed for the code to work as expected.

Public Sub Add_PViewPort_Text()

        Dim My_Adding_Text As AcadMText
        Dim My_TextPoint(2) As Double
        Dim PViewPort_CP(0 To 2) As Double 'Explicitly declaration as array of double
        'Dim Object_ZP1(2) As Double
        'Dim Object_ZP2(2) As Double
        Dim Object_ZP1 As Variant '==> Changed to Variant
        Dim Object_ZP2 As Variant '==> Changed to Variant
        Dim PViewPort_Width As Double
        Dim PViewPort_Height As Double
        Dim My_PViewPort As AcadPViewport

        My_TextPoint(0) = 0
        My_TextPoint(1) = 0
        
        ' Revision  ViewPort
        My_TextPoint(0) = -3895
        My_TextPoint(1) = 500: My_TextPoint(2) = 0
        Set My_Adding_Text = ThisDrawing.ModelSpace.AddMText(My_TextPoint, 500, "My_Rev")
        My_Adding_Text.Height = 50
        My_Adding_Text.color = acBlue
        My_Adding_Text.GetBoundingBox Object_ZP1, Object_ZP2

        PViewPort_CP(0) = 10
        PViewPort_CP(1) = 15
        PViewPort_CP(2) = 0
        
        PViewPort_Width = 28.73
        PViewPort_Height = 11.56
    
        ThisDrawing.ActiveLayout = ThisDrawing.Layouts.Item(0) '==> Move to Layout to process PViewport
        
        Set My_PViewPort = ThisDrawing.PaperSpace.AddPViewport(PViewPort_CP, PViewPort_Width, PViewPort_Height)
         My_PViewPort.Display (True)
         My_PViewPort.CustomScale = 0.01 '==> Set PViewport scale, manually
        Application.ZoomCenter My_PViewPort.Center, 5 '==> In Layout, zoom to that PViewport
        
        ThisDrawing.MSpace = True
        ThisDrawing.ActivePViewport = My_PViewPort '==>Set active PViewport before zoom, must come after ThisDrawing.MSpace = True
        
        ThisDrawing.Application.ZoomWindow Object_ZP1, Object_ZP2 '==> Zoom the active PViewport
        
        ThisDrawing.ActivePViewport.DisplayLocked = True
        My_PViewPort.Layer = "0"
        ThisDrawing.MSpace = False '==> Must Return to Layout (paper space) before processing next PViewport.
                                                            'Otherwise, the next command "Application.ZoomCenter My_PViewPort.Center, 5 " will not work in layout


        ' User  ViewPort
        
        My_TextPoint(0) = -3895
        My_TextPoint(1) = 300: My_TextPoint(2) = 0

        Set My_Adding_Text = ThisDrawing.ModelSpace.AddMText(My_TextPoint, 500, "CurrentUser")
        My_Adding_Text.Height = 50
        My_Adding_Text.color = acBlue
        My_Adding_Text.GetBoundingBox Object_ZP1, Object_ZP2

        PViewPort_CP(0) = 50
        PViewPort_CP(1) = 15
        PViewPort_CP(2) = 0
        PViewPort_Width = 25 '28.11
        PViewPort_Height = 10.55

        Set My_PViewPort = ThisDrawing.PaperSpace.AddPViewport(PViewPort_CP, PViewPort_Width, PViewPort_Height)
        My_PViewPort.Display (True)
        My_PViewPort.CustomScale = 0.01 '==> Set PViewport scale, manually
        Application.ZoomCenter My_PViewPort.Center, 5 '==> In Layout, zoom to that Viewport
        ThisDrawing.MSpace = True
        ThisDrawing.ActivePViewport = My_PViewPort
        
        ThisDrawing.Application.ZoomWindow Object_ZP1, Object_ZP2 '==> Zoom the active PViewport
        ThisDrawing.ActivePViewport.DisplayLocked = True
        My_PViewPort.Layer = "0"
        ThisDrawing.MSpace = False '==> Must Return to Layout (paper space) before processing next PViewport

End sub

 

0 Likes
Message 7 of 8

rmcefr
Enthusiast
Enthusiast

Dear Friend,

 

yes you right, it is VB.net interop, and i am using Visual Studio,

many thanks again of code updating,

 

one more point if can pls advise about it,

if we add AcadBlockReference object to ModalSpace, then we use (AcadBlockReference .GetBoundingBox(P1,P2))

 

the P1,P2 return Whole Modal Space size,!!

Is there an option to Get Bound Box for only Block Width and Height Coordinates?

 

regards

 

 

 

0 Likes
Message 8 of 8

ntclmain
Advocate
Advocate

I don't understand your situation, I only show my case for reference:
To determine the block ref lower left & upper right corner in model space:

- The block shape is rectangle whose size (Width, Height) are fixed by user input

- Lower left corner = insertion point

- upper right corner is calculated from: Lower left corner & rotation angle

0 Likes