.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

create paper space viewport and show some model portion in view

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
spu
Advocate
3373 Views, 2 Replies

create paper space viewport and show some model portion in view

Hi,

 

We like to allow user to select a rectagular area in modal scpace. Then the code creates a paperscace viewport in a spcified layout. The viewport will show the selected area. Please find the old VBA code that achived this and the .net code I am trying with. .Net code always gives some exception.

 

VBA Code

--------------

 'Lets find the center of the viewport in paperspace.

    Dim center(0 To 2) As Double
    center(0) = newWidth / 2
    center(1) = newLength / 2
    center(2) = 0

    Dim lay As AcadLayout

    For Each ent In ThisDrawing.layouts
        If ent.Name = "Betsy" Then
            Set lay = ent
        End If
    Next

    ThisDrawing.ActiveLayout = lay
    ThisDrawing.ActiveSpace = acPaperSpace

    'Lets create the actual viewport

    Set newVport = ThisDrawing.PaperSpace.AddPViewport(center, newWidth, newLength)
    newVport.TrueColor = myclr
    ' Enable the viewport
    newVport.Display True
    ZoomExtents
    ' Turn on model space editing
    ThisDrawing.MSpace = True    'Here pls check

    ' Set newVport current
    ' (not always necessary but a good idea)
    ThisDrawing.ActivePViewport = newVport

    Dim ModalLeftLower(0 To 2) As Double
    Dim ModalRightUpper(0 To 2) As Double

    ModalLeftLower(0) = ModalLeftUpper(0)
    ModalLeftLower(1) = ModalRightBottom(1)
    ModalLeftLower(2) = 0

    ModalRightUpper(0) = ModalRightBottom(0)
    ModalRightUpper(1) = ModalLeftUpper(1)
    ModalRightUpper(2) = 0

    ' Zoom window in model space
    ZoomWindow ModalLeftLower, ModalRightUpper

    ' Turn model space editing off
    ThisDrawing.MSpace = False

--------------

More code

 

.Net Code

-------------------------------------

 Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;

      Autodesk.AutoCAD.DatabaseServices.Database db = doc.Database;

      Autodesk.AutoCAD.EditorInput.Editor ed = doc.Editor;

 

      // We're accessing drawing objects, so we need a transaction

 

      

      using (Autodesk.AutoCAD.DatabaseServices.Transaction tr = db.TransactionManager.StartTransaction())

      {

        // Get the primary paperspace from the block table

        Autodesk.AutoCAD.DatabaseServices.BlockTable bt =  (Autodesk.AutoCAD.DatabaseServices.BlockTable)tr.GetObject(db.BlockTableId,Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead);

        Autodesk.AutoCAD.DatabaseServices.BlockTableRecord ps =(Autodesk.AutoCAD.DatabaseServices.BlockTableRecord)tr.GetObject(bt[Autodesk.AutoCAD.DatabaseServices.BlockTableRecord.PaperSpace], Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite);

         // Create a variety of objects for our clip boundaries

 

           //Autodesk.AutoCAD.DatabaseServices.DBObjectCollection objs = new Autodesk.AutoCAD.DatabaseServices.DBObjectCollection();

           // Create our viewport, adding that also

           SwitchTo("Betsy");
          
           Autodesk.AutoCAD.DatabaseServices.Viewport vp = new Autodesk.AutoCAD.DatabaseServices.Viewport();
           vp.SetDatabaseDefaults();
           vp.CenterPoint = new Autodesk.AutoCAD.Geometry.Point3d(newWidth/2, newLength/2, 0);
           vp.Width = newWidth;
           vp.Height = newLength;

            ps.AppendEntity(vp);

            tr.AddNewlyCreatedDBObject(vp, true);
            doc.Editor.SwitchToPaperSpace();
           //vp.ViewDirection = new Autodesk.AutoCAD.Geometry.Vector3d(1, 1, 1);
          //  vp.On = true;
            
            // Set the new viewport current via an imported ObjectARX function
          //  acedSetCurrentVPort(vp.UnmanagedObject);
            doc.Editor.SwitchToModelSpace();
          //  tr.Commit();
           Autodesk.AutoCAD.Geometry.Point3d ptll = new Autodesk.AutoCAD.Geometry.Point3d(ModalLeftUpper.X, ModalRightBottom.Y, 0);
              Autodesk.AutoCAD.Geometry.Point3d ptur = new Autodesk.AutoCAD.Geometry.Point3d(ModalRightBottom.X, ModalLeftUpper.Y, 0);
             Zoom.ZoomWindow(ptll, ptur);
            //Autodesk.AutoCAD.Geometry.Point3d ptll = new Autodesk.AutoCAD.Geometry.Point3d(0, 0, 0);
            //Autodesk.AutoCAD.Geometry.Point3d ptur = new Autodesk.AutoCAD.Geometry.Point3d(100, 100, 0);

            //Autodesk.AutoCAD.Interop.AcadApplication pApp;
            //pApp = (Autodesk.AutoCAD.Interop.AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;

            //pApp.ZoomWindow(ptll.ToArray(), ptur.ToArray());
             doc.Editor.SwitchToPaperSpace();
             tr.Commit();
           
          }

 

 

Regards,

Shijith

 

 

 

 

 

2 REPLIES 2
Message 2 of 3
Balaji_Ram
in reply to: spu

Hi Shijith,

 

I dont have a ready code to do exactly the same steps.

 

But here is a Devblog post that can give you a start.

http://adndevblog.typepad.com/autocad/2012/08/changing-zoom-in-paperspace-viewport.html

 

It sets the paperspace viewport parameters based on the database extents. You can modify it to set the viewport parameters based on any other rectangle corner points. In the sample code from the blog post, the "x_Min" and "x_Max" are the database extent points but in your case it will represent the extents of the selected rectangle in model space.

 

This will allow you to set the paperspace viewport to show the model within the selected rectangle.

 

Hope this helps.

 



Balaji
Developer Technical Services
Autodesk Developer Network

Message 3 of 3
spu
Advocate
in reply to: Balaji_Ram

Hi,

 

Thanks Balaji. It worked like a charm....

 

Regards,

Shijith

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost