- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows;
using System.Collections;
using Autodesk.AutoCAD;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Colors;
using System.Threading;
namespace EAACExtansion
{
/// <summary>
/// Constructor for the Document Root object
/// </summary>
public abstract class AcExDocumentRoot
{
public Document mainAcadDocument;
public Editor mainEditor;
public Database mainAcadDatabase;
public AcExDocumentRoot self;
// I like to enable configuration of my tool tough a textfile. This variables will be used for it.
private String configPath;
protected SortedList<string,string> configuration;
public String installationPath = "D:\\ACADExtension_2012";
/// <summary>
///
/// </summary>
public AcExDocumentRoot()
{
self = this;
try
{
mainAcadDocument = Application.DocumentManager.MdiActiveDocument;
mainEditor = mainAcadDocument.Editor;
mainAcadDatabase = mainAcadDocument.Database;
}
catch ( System.Exception ex) {
Application.ShowAlertDialog(ex.ToString());
return;
}
configPath = installationPath + "\\Config\\EaAcConfigfile.conf";
configuration = new SortedList<string,string>();
// ReReadConfig();
}
/// <summary>
///
/// </summary>
/// <param name="Question">The question you want the user to answere. This variable will be changed according to the answere of the user.</param>
/// <returns>the answere false means that the user aborted the question. If true he answered and the question variable is changed.</returns>
public Boolean AnswereOf(ref String Question)
{
PromptStringOptions EditorQuestion = new PromptStringOptions(Question);
PromptResult Answere;
do
{
Answere = mainEditor.GetString(EditorQuestion);
} while (Answere.Status != PromptStatus.OK & Answere.Status != PromptStatus.Cancel);
if (Answere.Status == PromptStatus.Cancel)
{
mainEditor.WriteMessage("**Abort**");
}
else
{
Question = Answere.StringResult;
return true;
}
return false;
}
public ObjectId GetLinetypeID(String lineTypeName) {
LinetypeTable MyLineTypeTable;
using (Transaction MyTrans = this.mainAcadDocument.TransactionManager.StartTransaction())
{
MyLineTypeTable = (LinetypeTable)MyTrans.GetObject(this.mainAcadDatabase.LinetypeTableId, OpenMode.ForRead);
if (MyLineTypeTable.Has(lineTypeName))
{
return MyLineTypeTable[lineTypeName];
}
else {
this.mainEditor.WriteMessage("Found wrong spelled linetypename: " + lineTypeName + " in optionfile. Error will occur");
throw new System.Exception();
}
}
}
/// <summary>
/// This Methode is doing the Operations defined in the Operation objekt. For all Elements in the Document.
/// </summary>
/// <param name="MyOperation"></param>
internal void LoopThrowEachObject(Operation MyOperation)
{
long zaehler = 0;
using (Transaction MyTrans = this.mainAcadDocument.TransactionManager.StartTransaction())
{
// Blocktabelle für die Datenbank
BlockTable MyBlockTable = (BlockTable)MyTrans.GetObject(this.mainAcadDatabase.BlockTableId, OpenMode.ForRead);
// LinkedList<Thread> Threadlist = new LinkedList<Thread>();
// Loop über alle Objekte in der Datenbank
foreach (ObjectId Blocktableobject in MyBlockTable)
{
// Extrahieren der Objekte aus der Tabelle
BlockTableRecord DiscreteBlocktableobject = (BlockTableRecord)MyTrans.GetObject(Blocktableobject, OpenMode.ForWrite);
foreach (ObjectId DescreteObject in DiscreteBlocktableobject)
{
// Extrahiere das Entity (also die Linie etc aus der Tabelle für weitere bearbeitung.)
Entity MyEntity = (Entity)DescreteObject.GetObject(OpenMode.ForWrite);
// Und nun muss man was vernüftiges mit dem Teil tun.
// MyOperation.setEntity(MyEntity);
MyOperation.start(MyEntity);
// Mögliche Erweiterung um die Funktionalität mit Threading.
// Thread InstanceCaller = new Thread(MyOperation.start);
// InstanceCaller.Start(MyEntity);
// Threadlist.AddFirst(InstanceCaller);
// MyOperation.start(MyEntity);
zaehler++;
// Und hier hat man hoffentlich mit dem Teil etwas getan.
}
}
// Nach der Bearbeitung der Element muss man die Transaction übergeben.
MyTrans.Commit();
}
}
public abstract void CheckExistanceOfSwitches();
/// <summary>
///
/// </summary>
/// <param name="newLayer"></param>
/// <returns> Null if Layer could not added. Else it returns the layer.</returns>
public LayerTableRecord AddLayer(String newLayer)
{
LayerTable myLayerTable;
LayerTableRecord activeLayer = null;
// LinetypeTableRecord MyLineTypeTableRevord;
using (Transaction MyTrans = this.mainAcadDocument.TransactionManager.StartTransaction())
{
myLayerTable = (LayerTable)MyTrans.GetObject(this.mainAcadDatabase.LayerTableId, OpenMode.ForRead);
if (!myLayerTable.Has(newLayer))
{
// try{ activeLayer = (LayerTableRecord) MyTrans.GetObject(myLayerTable[newLayer],OpenMode.ForWrite);
try
{
activeLayer = new LayerTableRecord();
activeLayer.Name = newLayer;
myLayerTable.Add(activeLayer);
MyTrans.Commit();
if (myLayerTable.Has(newLayer)) { return activeLayer; }
} catch (System.Exception ex) {
this.mainEditor.WriteMessage(ex.Message);
this.mainEditor.WriteMessage("Layermanager error: " + newLayer + " in this Installation");
return null;
}
}
if (activeLayer != null) { return activeLayer; }
}
this.mainEditor.WriteMessage("Layermanager error: " + newLayer + " in this Installation");
return null;
}
/// <summary>
/// The function here is to start a operation for each existing layer in the layer table.
/// </summary>
/// <param name="myOperation"></param>
internal void LoopThroughEachLayer(Operation myOperation)
{
LayerTable myLayerTable;
LayerTableRecord activeLayer;
using (Transaction MyTrans = this.mainAcadDocument.TransactionManager.StartTransaction())
{
myLayerTable = (LayerTable)MyTrans.GetObject(this.mainAcadDatabase.LayerTableId, OpenMode.ForRead);
foreach (ObjectId activeId in myLayerTable)
{
activeLayer = (LayerTableRecord)MyTrans.GetObject(activeId, OpenMode.ForWrite);
myOperation.start(activeLayer);
}
MyTrans.Commit();
}
}
}
}
|
|