.NET

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

Copying plot settings

215 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 (215 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 (215 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?
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!