如何不打开图形设置图纸的页面设置
Document doc = Application.DocumentManager.MdiActiveDocument;Database db1 = new Database(false, true);
db1.ReadDwgFile("c:\\Awork\\1.dwg", System.IO.FileShare.ReadWrite, true, "");
using (Transaction trans1 = db1.TransactionManager.StartTransaction())
{
// Reference the Layout Manager
LayoutManager acLayoutMgr;
acLayoutMgr = LayoutManager.Current;
// Get the current layout and output its name in the Command Line window
Layout acLayout;
acLayout = trans1.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout),
OpenMode.ForRead) as Layout;
每次执行到这一行就出错,显示“eNotFromThisDocument”,怎么回事啊
// Get the PlotInfo from the layout
PlotInfo acPlInfo = new PlotInfo();
acPlInfo.Layout = acLayout.ObjectId;
// Get a copy of the PlotSettings from the layout
PlotSettings acPlSet = new PlotSettings(acLayout.ModelType);
acPlSet.CopyFrom(acLayout);
意思应该是 acLayoutMgr 和 db1 不属于同一个Dwg文件,猜而已。 本帖最后由 lamntree 于 2013-6-21 19:54 编辑
现在已经能不打开图形创建新页面设置了,但是名为*model*初始默认页面设置无法访问编辑,我用同名plotsettings覆盖没用,想设置创建的新页面设置设置为当前,又不知道怎么弄
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db1 = new Database(false, true);
db1.ReadDwgFile("c:\\Awork\\1.dwg", System.IO.FileShare.ReadWrite, true, "");
using (Transaction trans1 = db1.TransactionManager.StartTransaction())
{
PlotSettings acPlSet = new PlotSettings(true);
DBDictionary GroDic = (DBDictionary)trans1.GetObject(db1.PlotSettingsDictionaryId , OpenMode.ForWrite);
acPlSet.PlotSettingsName = "111";//名为*model*初始默认页面设置无法访问编辑,我用同名plotsettings覆盖没用
// Update the PlotSettings object
PlotSettingsValidator acPlSetVdr = PlotSettingsValidator.Current;
// Set the plot type
acPlSetVdr.SetPlotType(acPlSet,Autodesk.AutoCAD.DatabaseServices.PlotType.Extents);
// Set the plot scale
acPlSetVdr.SetUseStandardScale(acPlSet, true);
acPlSetVdr.SetStdScaleType(acPlSet, StdScaleType.ScaleToFit);
// Center the plot
acPlSetVdr.SetPlotCentered(acPlSet, true);
// Set the plot device to use
acPlSetVdr.SetPlotConfigurationName(acPlSet, "Microsoft XPS Document Writer","A3");
acPlSetVdr.SetCurrentStyleSheet(acPlSet, "monochrome.ctb");
GroDic.SetAt("111", acPlSet);
trans1.AddNewlyCreatedDBObject(acPlSet, true);
acPlSetVdr.SetDefaultPlotConfig(acPlSet);//这句我以为是设置为当前页面设置,不过试下来没用,怎么才能设置为当前页面设置啊
try
{
db1.SaveAs("c:\\Awork\\1.dwg", true, DwgVersion.Current, doc.Database.SecurityParameters);//指定c盘根目录保存
}
catch
{
return;
}
trans1.Commit();
} acPlSetVdr.SetDefaultPlotConfig(acPlSet);//这句我以为是设置为当前页面设置,不过试下来没用,怎么才能设置为当前页面设置啊
上面的问题不知道楼主解决没?为了给遇到同样问题的朋友以参考,我找到的方法是:
acLayout.CopyFrom(plSet)
其中acLayout为layout;plSet为PlotSettings。
具体的方法要仔细看一下Managed .NET Developer's Guide (.NET)中相应的代码。
页:
[1]