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

Creating new Layout with A3 Paper Size

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

Creating new Layout with A3 Paper Size

Hi,

 

I want to add a new layout to drawing with paper size "A3". Please help me to do it properly. this is want i am trying with.  We had a VBA script before as shown bellow.

For Each tlAcadLayout In ThisDrawing.layouts
        If tlAcadLayout.Name = "A3" Then
            blnLayout = True
            tlCurMedia = tlAcadLayout.CanonicalMediaName
            tlConfig = tlAcadLayout.ConfigName
            oldOrg = tlAcadLayout.PlotOrigin
            Exit For
        End If
    Next
 
 With tlAcadLayout
        .RefreshPlotDeviceInfo
        .ConfigName = "None"
        .CanonicalMediaName = "ISO_A3_(420.00_x_297.00_MM)"
        .PlotRotation = ac0degrees
        .PaperUnits = acMillimeters
        .PlotOrigin = ptOrigin
        Call .GetPaperSize(wid, ht)

  End With

 

And I tried to write it to .Net as shown bellow.

 

name ="A3";
            Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
           Autodesk.AutoCAD.EditorInput.Editor ed = doc.Editor;
            Autodesk.AutoCAD.ApplicationServices.DocumentLock doclock = doc.LockDocument();
            Autodesk.AutoCAD.DatabaseServices.Database db = doc.Database;
            Autodesk.AutoCAD.DatabaseServices.TransactionManager trm = db.TransactionManager;
            Autodesk.AutoCAD.DatabaseServices.ObjectId oLayoutObjId;
            try
            {
                using (Autodesk.AutoCAD.DatabaseServices.Transaction tr = trm.StartTransaction())
                {

                    Autodesk.AutoCAD.DatabaseServices.LayoutManager  oLayoutManager = Autodesk.AutoCAD.DatabaseServices.LayoutManager.Current;
                    try
                    {

                        oLayoutObjId = oLayoutManager.CreateLayout(name);
                        Autodesk.AutoCAD.DatabaseServices.Layout oLayout = tr.GetObject(oLayoutObjId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite) as Autodesk.AutoCAD.DatabaseServices.Layout; 
                        oLayout.Initialize();
                        //ed.SwitchToPaperSpace(
                        // Get the PlotInfo from the layout
                        Autodesk.AutoCAD.PlottingServices.PlotInfo acPlInfo = new Autodesk.AutoCAD.PlottingServices.PlotInfo();
                        acPlInfo.Layout = oLayout.ObjectId;
                        // Get a copy of the PlotSettings from the layout
                        Autodesk.AutoCAD.DatabaseServices.PlotSettings acPlSet = new Autodesk.AutoCAD.DatabaseServices.PlotSettings(oLayout.ModelType);
                        acPlSet.CopyFrom(oLayout);
                        // Update the PlotConfigurationName property of the PlotSettings object
                        Autodesk.AutoCAD.DatabaseServices.PlotSettingsValidator acPlSetVdr = Autodesk.AutoCAD.DatabaseServices.PlotSettingsValidator.Current;


                        acPlSetVdr.SetPlotType(acPlSet,Autodesk.AutoCAD.DatabaseServices.PlotType.Extents);

                        acPlSetVdr.SetUseStandardScale(acPlSet, true);

                        acPlSetVdr.SetStdScaleType(acPlSet, Autodesk.AutoCAD.DatabaseServices.StdScaleType.ScaleToFit);

                        acPlSetVdr.SetPlotCentered(acPlSet, true);

                        acPlSetVdr.SetPlotPaperUnits(acPlSet, Autodesk.AutoCAD.DatabaseServices.PlotPaperUnit.Millimeters);

                      acPlSetVdr.SetPlotConfigurationName(acPlSet, "DWG To PDF.pc3", "ISO A3 (420.00 x 297.00 MM" );
                      acPlSetVdr.RefreshLists(acPlSet);
                                                   
                      oLayout.CopyFrom(acPlSet);
                        oLayout.CopyFrom(acPlSet);
                        tr.Commit();
                        // initialize the layout
                        ed.Regen();
                       
                    }
                    catch (Exception ex)
                    {
                        System.Windows.Forms.MessageBox.Show(name + " CreateNewLayout  Exception:" + ex.GetType() + "  Message:" + ex.Message);
                        tr.Abort();
                        ed.Regen();
                    }
                  
                }
               
                doclock.Dispose();

            }
            catch(Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(name +  " CreateNewLayout  Exception:" + ex.GetType() + "  Message:" + ex.Message);
            }

 It always throws exception einvalid input at acPlSetVdr.SetPlotConfigurationName(acPlSet, "DWG To PDF.pc3", "ISO A3 (420.00 x 297.00 MM" );

 

Please advice

Regards,

Shijith

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

Reading the source it looks you mixed the paper and modelspaces.

Layout== paperspace, therefore you have to define the new PlotSettings using

PlotSettings np = new PlotSettings(false);  //paperspace

You specified: Autodesk.AutoCAD.DatabaseServices.PlotSettings acPlSet =

new  Autodesk.AutoCAD.DatabaseServices.PlotSettings(oLayout.ModelType);

 

Switch to Layout using:

            db.TileMode = false;        //goto Paperspace if not already
            ed.SwitchToPaperSpace();    //turn PVP off

 

Don't you want to save the newly created NamedPlotStyle ?     //tr.Abort();

 

 

 

Message 3 of 3
spu
Advocate
in reply to: spu

Thanks man that worked perfectly for me. This is my code, though not final yet may be useful for somebody latter.

 private void CreateNewLayout(string name)
        {
            Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
           Autodesk.AutoCAD.EditorInput.Editor ed = doc.Editor;
            Autodesk.AutoCAD.ApplicationServices.DocumentLock doclock = doc.LockDocument();
            Autodesk.AutoCAD.DatabaseServices.Database db = doc.Database;
            Autodesk.AutoCAD.DatabaseServices.TransactionManager trm = db.TransactionManager;
            Autodesk.AutoCAD.DatabaseServices.ObjectId oLayoutObjId;
            try
            {
                using (Autodesk.AutoCAD.DatabaseServices.Transaction tr = trm.StartTransaction())
                {
                    Autodesk.AutoCAD.DatabaseServices.LayoutManager  oLayoutManager = Autodesk.AutoCAD.DatabaseServices.LayoutManager.Current;
                    try
                    {
                        oLayoutObjId = oLayoutManager.CreateLayout(name);
                        Autodesk.AutoCAD.DatabaseServices.Layout oLayout = tr.GetObject(oLayoutObjId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite) as Autodesk.AutoCAD.DatabaseServices.Layout; 
                        oLayout.Initialize();                     
                        Autodesk.AutoCAD.PlottingServices.PlotInfo acPlInfo = new Autodesk.AutoCAD.PlottingServices.PlotInfo();
                        acPlInfo.Layout = oLayout.ObjectId;
                        // Get a copy of the PlotSettings from the layout
                      
                     //   Autodesk.AutoCAD.DatabaseServices.PlotSettings acPlSet = new Autodesk.AutoCAD.DatabaseServices.PlotSettings(oLayout.ModelType);

                        Autodesk.AutoCAD.DatabaseServices.PlotSettings acPlSet = new Autodesk.AutoCAD.DatabaseServices.PlotSettings(false);  //paperspace
  



                        acPlSet.CopyFrom(oLayout);
                        // Update the PlotConfigurationName property of the PlotSettings object
                        Autodesk.AutoCAD.DatabaseServices.PlotSettingsValidator acPlSetVdr = Autodesk.AutoCAD.DatabaseServices.PlotSettingsValidator.Current;
                        acPlSetVdr.SetPlotConfigurationName(acPlSet, "DWG to PDF.pc3", "ISO_A3_(420.00_x_297.00_MM)");
                        acPlSetVdr.SetPlotRotation(acPlSet, Autodesk.AutoCAD.DatabaseServices.PlotRotation.Degrees000);
                        acPlSetVdr.SetPlotPaperUnits(acPlSet, Autodesk.AutoCAD.DatabaseServices.PlotPaperUnit.Millimeters);
                        oLayout.CopyFrom(acPlSet);                
                        tr.Commit();
                        oLayoutManager.CurrentLayout = name;
                        db.TileMode = false;        //goto Paperspace if not already
                        ed.SwitchToPaperSpace();    //turn PVP off
                        // initialize the layout
                        ed.Regen();                       
                    }
                    catch (Exception ex)
                    {
                        System.Windows.Forms.MessageBox.Show(name + " CreateNewLayout  Exception:" + ex.GetType() + "  Message:" + ex.Message);
                        tr.Abort();
                        ed.Regen();
                    } 
                }
                doclock.Dispose();
            }
            catch(Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(name +  " CreateNewLayout  Exception:" + ex.GetType() + "  Message:" + ex.Message);
            }
        }

 

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