Copying a plotting setting from one drawing to another.

By Virupaksha Aithal

Below code shows the procedure to copy the plot setting from one drawing to the current drawing file.

[CommandMethod("CopyPlotSetting")]
static public void CopyPlotSetting()
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Database _db = doc.Database;
 
    using (Database _srDb = new Database(false, true))
    {
        _srDb.ReadDwgFile("c:\temp\testPlot.dwg",
            System.IO.FileShare.Read,
            true, null);
 
        using (Transaction _templateTr =
           _srDb.TransactionManager.StartTransaction())
        {
            using (Transaction _tr =
             _db.TransactionManager.StartTransaction())
            {
                DBDictionary dbDict = _templateTr.GetObject(
                                    _srDb.PlotSettingsDictionaryId,
                                    OpenMode.ForRead) as DBDictionary;
                if (dbDict != null)
                {
                    ObjectId settingsId = ObjectId.Null;
                    settingsId = dbDict.GetAt("TestPlotSetting");
                    PlotSettings settings = null;
                    settings =
                           _templateTr.GetObject(settingsId,
                                 OpenMode.ForRead) as PlotSettings;
 
                    PlotSettings newSettings =
                                new PlotSettings(true);
 
                    newSettings.CopyFrom(settings);
                    newSettings.AddToPlotSettingsDictionary(_db);
                    _tr.AddNewlyCreatedDBObject(newSettings, true);
                }
                _tr.Commit();
            }
            _templateTr.Commit();
        }
    }
}

Comments

3 responses to “Copying a plotting setting from one drawing to another.”

  1. Jonathan Clark Avatar
    Jonathan Clark

    This is great code. I realized that it only works for plot settings that reside in model space. Can I get some direction on how to do the same thing with plot settings that are for layouts also.
    Thanks.
    Jonathan

  2. Please try replacing
    PlotSettings newSettings = new PlotSettings(true);
    With
    PlotSettings newSettings = new PlotSettings(settings.ModelType);
    Thanks
    Viru

  3. Can i get a code for copying model and layouts space of a current drawing and paste the same into a new drawing..

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading