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

Copying plot settings

2 REPLIES 2
Reply
Message 1 of 3
mohnston
441 Views, 2 Replies

Copying plot settings

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
2 REPLIES 2
Message 2 of 3
mohnston
in reply to: mohnston

Change of strategy.
Now working with the Publisher.
CAD Programming Solutions
Message 3 of 3
Anonymous
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?

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