Hi Mark.
It looks like the pInf object is not open in a
transaction, because your code commits the
the transaction it was opened in, before you
try to write the property value.
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com
wrote in message news:5441622@discussion.autodesk.com...
I'm trying to copy plot settings from a drawing to use in a plotting program I am writing.
I get an AccessViolationException error "Attempted to read or write protected memory." when I run this code:
---------------------------------------
Database controlDB = new Database();
PlotSettings pSet = new PlotSettings(true);
PlotInfo pInf = new PlotInfo();
PlotSettingsValidator pValid = PlotSettingsValidator.Current;
controlDB.ReadDwgFile(plotControlDWG, System.IO.FileShare.Read, false, string.Empty);
Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = controlDB.TransactionManager;
//controlDB.CloseInput(true);
Transaction trans = tm.StartTransaction();
try
{
DBDictionary dic = (DBDictionary)trans.GetObject(controlDB.PlotSettingsDictionaryId, OpenMode.ForRead);
foreach (DBDictionaryEntry dicEnt in dic)
{
if (dicEnt.Key == pgSetupName)
{
pSet = (PlotSettings)trans.GetObject(dicEnt.Value, OpenMode.ForRead, false);
}
}
trans.Commit();
}
finally { trans.Dispose(); }
pInf.Layout = LayoutManager.Current.GetLayoutId("Model");
pInf.OverrideSettings = pSet;
-------------------------
The error happens on this last line.
pSet is a valid PlotSettings. I see all the properties are set when I examine it.
pInf says that "Operation is not valid due to the current state of the object.". It reports this in the .DeviceOverride property which I am not setting.
Any idea why this is generating the error?
Has anyone done this successfully?