2014-04-03 22 views
0

我正在創建一個窗體窗體,用戶將在Autocad中運行命令,它將提示他們選擇一個對象(特別是3D多段線)。 3D折線可以具有非常廣泛的頂點。我希望每個頂點都在/創建它自己的行。每行有5列(每個頂點的屬性)。用於數據顯示/修改的適當「容器」

這是什麼適當的容器?我希望用戶能夠修改(例如更改高程)每個頂點中的每個屬性。隨着實際刪除他們想要的任何頂點。

表格佈局面板?普通面板?這裏是我「獲取」頂點的代碼:

 using (AcDb.Transaction oTr = db.TransactionManager.StartTransaction()) 
     { 
      AcDb.ObjectIdCollection ids = new AcDb.ObjectIdCollection(); 

      AcEd.PromptEntityOptions options = new AcEd.PromptEntityOptions("\nSelect a 3DPolyline:"); 
      options.SetRejectMessage("That is not select a 3DPolyline" + "\n"); 
      options.AddAllowedClass(typeof(AcDb.Polyline3d), true); 
      AcEd.PromptEntityResult result = ed.GetEntity(options); 

      if (result.Status != AcEd.PromptStatus.OK) return; 

      AcDb.Polyline3d oEnt = oTr.GetObject(result.ObjectId, AcDb.OpenMode.ForRead) as AcDb.Polyline3d; 


      foreach (AcDb.ObjectId oVtId in oEnt) 
      { 
       AcDb.PolylineVertex3d oVt = oTr.GetObject(oVtId, AcDb.OpenMode.ForRead) as AcDb.PolylineVertex3d; 
       //now to populate...something 
+0

可能是一個數據網格?應該允許您查看頂點對象的集合並直接修改(包含編輯事件之前/之後的內容)...刪除不是很明顯(選擇行,按下鍵盤上的刪除鍵),因此可能會出現在工具欄中。 – bdimag

回答

3

DataTable在收集數據時很有意義。

using (var trans = db.TransactionManager.StartTransaction()) 
{ 
    var options = new PromptEntityOptions("\nSelect a 3DPolyline:"); 
    options.SetRejectMessage("That is not select a 3DPolyline" + "\n"); 
    options.AddAllowedClass(typeof(Polyline3d), true); 
    var result = ed.GetEntity(options); 

    if (result.Status != PromptStatus.OK) 
     return; 

    var poly = (Polyline3d)trans.GetObject(result.ObjectId, OpenMode.ForRead); 
    var vertexClass = RXClass.GetClass(typeof(PolylineVertex3d)); 

    var vertexTable = new System.Data.DataTable("Vertices"); 
    vertexTable.Columns.Add("HandleId", typeof(long)); 
    vertexTable.Columns.Add("PositionX", typeof(double)); 
    vertexTable.Columns.Add("PositionY", typeof(double)); 
    vertexTable.Columns.Add("PositionZ", typeof(double)); 

    foreach (ObjectId vertexId in poly) 
    { 
     if (!vertexId.ObjectClass.IsDerivedFrom(vertexClass)) 
      continue; 

     var vertex = (PolylineVertex3d)trans.GetObject(vertexId, OpenMode.ForRead); 
     vertexTable.Rows.Add(vertex.Handle.Value, vertex.Position.X, vertex.Position.Y, vertex.Position.Z); 
    } 

    trans.Commit(); 
} 

一旦在表格中獲得了頂點數據,就可以非常輕鬆地將它綁定到可視化控件。

+0

我錯了,假設這將編輯數據「現場」?我已經填充了表單,但更改任何內容(例如z值)在我關閉表單後都不會執行任何操作。我是否需要在表單上做特定的事情? – smakfactor1

+1

根據您的應用程序要求,您需要解決數據更改時發生的情況。如果您只是想將表單上的更改應用於對象,則必須使用當前的邏輯重新獲取它們(您可以從Handle獲取ObjectID)以編輯它們,然後提交新的事務。 –

+1

交替地(也許在你的情況下更好)是在顯示錶單時保持DBObjects和事務處於打開狀態,然後在數據關閉時更新數據。您必須創建一個方法,將更新的表值設置爲您打開的對象。 –

相關問題