在Autocad 2018中运行此c#2013例程
如何在CIVIL 3D或AUTOCAD中运行此c#2013例程/*
* © Andrey Bushman, 2013
* AutoCAD 2014 x64 Enu
*
* AutoCAD references:
*
* AcCoreMgd.dll
* AcDbMgd.dll
* AcMgd.dll
* Interop.ACSMCOMPONENTS19Lib.dll
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cad = Autodesk.AutoCAD.ApplicationServices.Application;
using App = Autodesk.AutoCAD.ApplicationServices;
using Db = Autodesk.AutoCAD.DatabaseServices;
using Ed = Autodesk.AutoCAD.EditorInput;
using Rtm = Autodesk.AutoCAD.Runtime;
using Comp = ACSMCOMPONENTS19Lib;
namespace Bushman.AutoCAD.SheetSetEditor {
public class Commands {
const String ns = "bush"; // namespace
public void Renumber() {
App.Document doc = cad.DocumentManager.MdiActiveDocument;
Db.Database db = doc.Database;
Ed.Editor ed = doc.Editor;
Comp.AcSmSheetSetMgr mng = new Comp.AcSmSheetSetMgr();
Comp.IAcSmEnumDatabase enumerator = mng.GetDatabaseEnumerator();
Comp.AcSmDatabase smDb = null;
while ((smDb = enumerator.Next()) != null) {
String fname = smDb.GetFileName();
Comp.AcSmSheetSet sheetset = smDb.GetSheetSet();
String name = sheetset.GetName();
String descr = sheetset.GetDesc();
ed.WriteMessage("\nSheet Set: {0}\n", name);
Comp.IAcSmEnumComponent encomp = sheetset.GetSheetEnumerator();
Comp.IAcSmComponent component = null;
while ((component = encomp.Next()) != null) {
ProcessElement(ed, component, 0);
}
encomp.Reset();
}
enumerator.Reset();
}
// Recursive processing of the elements
void ProcessElement(Ed.Editor ed, Comp.IAcSmComponent component, Int32 level) {
ed.WriteMessage("\t{0}{1} (Subset)\n", new String('\t', level), component.GetName());
Array array = null;
component.GetDirectlyOwnedObjects(out array);
if (array != null) {
Int32 sheet_number = 0;
foreach (var item in array) {
if (item is Comp.IAcSmSubset) {
ProcessElement(ed, (Comp.IAcSmSubset)item, level + 1);
}
else if (item is Comp.IAcSmSheet) {
Comp.IAcSmSheet sheet = (Comp.IAcSmSheet)item;
ed.WriteMessage("\t\t{0}{1} (Sheet)", new String('\t', level), sheet.GetName());
sheet.SetNumber(sheet_number.ToString()); // I get an exception here!
++sheet_number;
}
else if (item is Comp.IAcSmPersist) {
Comp.IAcSmPersist persist = (Comp.IAcSmPersist)item;
ed.WriteMessage("\t\t{0}Additional info: {1}", new String('\t', level), persist.GetTypeName());
}
else {
ed.WriteMessage("\t\t{0}Unknown object: {1}", new String('\t', level), item.GetType().ToString());
}
ed.WriteMessage("\n");
}
}
}
}
}
**** Hidden Message ***** 哪个AutoCAD版本
它需要在Visual Studio中编译,并引用合适的库以匹配AutoCAD版本
DUH:只需重新阅读标题
对于autocad 2018- 2019- 2020
,我已经尝试过了,但我在尝试构建时总是有错误。
我需要一个特殊的指南来构建autocad 2018-2019-2020? 由于代码主要是关于通过其COM API的Sheet Set。因此,它与AutoCAD API本身没有什么关系。就构建错误而言,您确实应该包含有关错误是什么的更多详细信息,或者附上图片以显示错误。
但是,我想错误很可能来自COM API参考“AcSmComponents2x.tlb”,其中2x可能是21、22、23,具体取决于AutoCAD版本。因此,检查VS项目中的“参考”以确保您有正确的版本Sheet Set COM API库参考,对应于您的AutoCAD版本(对于AutoCAD2018,它是22),除了正确的AutoCAD版本。NET API参考,当然。
页:
[1]