明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2575|回复: 3

[打印] 如何不打开图形设置图纸的页面设置

[复制链接]
发表于 2013-6-20 20:40 | 显示全部楼层 |阅读模式
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);


发表于 2013-6-20 22:42 | 显示全部楼层
意思应该是 acLayoutMgr 和 db1 不属于同一个Dwg文件,猜而已。
 楼主| 发表于 2013-6-21 19:50 | 显示全部楼层
本帖最后由 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();
            }
发表于 2014-6-7 20:57 | 显示全部楼层
acPlSetVdr.SetDefaultPlotConfig(acPlSet);//这句我以为是设置为当前页面设置,不过试下来没用,怎么才能设置为当前页面设置啊


上面的问题不知道楼主解决没?为了给遇到同样问题的朋友以参考,我找到的方法是:
acLayout.CopyFrom(plSet)
其中acLayout为layout;plSet为PlotSettings。

具体的方法要仔细看一下Managed .NET Developer's Guide (.NET)中相应的代码。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-20 20:17 , Processed in 0.421533 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表