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

Switching to paperspace when using side database

0 REPLIES 0
Reply
Message 1 of 1
mangesh_dhadveUXWFD
100 Views, 0 Replies

Switching to paperspace when using side database

I am creating multiple layouts using side database. This is the overview of the code

 dynamic preferences = Autodesk.AutoCAD.ApplicationServices.Application.Preferences;
 string templatePath = preferences.Files.TemplateDWGPath;
 for (int i = 0; i < count; i++)
 {
     Database database = AutoCADUtilities.Instance.OpenSideDatabase(templatePath + "\\acad.dwt", false);
     HostApplicationServices.WorkingDatabase = database;

     //Attach XREF based on UserInput

     //Update Layers

     //CreateViewport

     //Save
 }
            using (Viewport viewPort = new Viewport())
            {
                viewPort.SetDatabaseDefaults();
                viewPort.CenterPoint = new Point3d(x, y, 0);
                viewPort.Width = width/ scale;
                viewPort.Height = height/ scale;

                // Add the new object to the block table record and the transaction
                blockTableRecord.AppendEntity(viewPort);
                transaction.AddNewlyCreatedDBObject(viewPort, true);

                // Enable the viewport
                viewPort.On = true;


                viewPort.StandardScale = vpScale;


                // Change the view direction
                viewPort.ViewDirection = new Vector3d(0, 0, 1);

                //Assign the view location
                viewPort.ViewTarget = pt3GridCenter;

                //Rotate the view within viewport to match the rotation of Grid Block   (out of phase by 180 deg)
                viewPort.TwistAngle = dblRotation;

                //Set viewport layer to defpoints
                viewPort.Layer = AssignLayer("Defpoints", database, transaction);

                //Set shade plot to legacy hidden for the conveyor and catwalk sheets
               
                //lock viewport
                viewPort.Locked = true;

            }


This works perfectly fine.

Issues comes up when I try to change current layout. When I open file, modelspace is accessible through viewport(please see image), viewport scale change 1:1 and viewport dimensions are completely different. 

I tried to call this method in two different ways with same outcome
1) SwitchToPaperSpace after creating viewport. 
2) Save and close drawing, then reopen drawing in side database and call SwitchToPaper space

 internal void SwitchToPaperSpace(Database database, Transaction transaction)
 {
     HostApplicationServices.WorkingDatabase = database;
     BlockTable blockTable = transaction.GetObject(database.BlockTableId, OpenMode.ForRead) as BlockTable;
     // Open the Block table record Paper space for write
     BlockTableRecord blockTableRecord = transaction.GetObject(blockTable[BlockTableRecord.PaperSpace], OpenMode.ForWrite) as BlockTableRecord;
     //Set current Layout
     Layout layout = (Layout)transaction.GetObject(blockTableRecord.LayoutId, OpenMode.ForRead);
     LayoutManager.Current.CurrentLayout = layout.LayoutName;
 }

 Thank you.image.png

Tags (3)
0 REPLIES 0

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

Post to forums  

Forma Design Contest


Autodesk Design & Make Report