.NET

Reply
Distinguished Contributor
mohnston
Posts: 184
Registered: ‎09-22-2006
Message 1 of 3 (211 Views)

Copying plot settings

211 Views, 2 Replies
01-04-2007 01:26 PM
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?
CAD Programming Solutions
Distinguished Contributor
mohnston
Posts: 184
Registered: ‎09-22-2006
Message 2 of 3 (211 Views)

Re: Copying plot settings

01-05-2007 07:25 PM in reply to: mohnston
Change of strategy.
Now working with the Publisher.
CAD Programming Solutions
*Tony Tanzillo
Message 3 of 3 (211 Views)

Re: Copying plot settings

01-05-2007 07:48 PM in reply to: mohnston
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?
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.