2016-04-05 7 views
0

これは私のプログラムで、Excelのテーブル&をプログラムで作成して前述のポイントに作成するプログラムです。私が(0,0)を指定すると、左上隅が追加されます。しかし、私は左下が欲しい。コードはどうですか?Autocad 2015のテーブル(左下)をプログラムで(0,0,0)に追加

これが私のプログラム..です

[CommandMethod("exl")] 
static public void TableFromSpreadsheet() 
{ 
    const string dlName = "Excel to Autocad"; 
    var doc = Application.DocumentManager.MdiActiveDocument; 
    var db = doc.Database; 
    var ed = doc.Editor; 
    var ofd = new OpenFileDialog("Select Excel Spreadsheet to Link", null, "xls; xlsx", "ExcelFileToLink", OpenFileDialog.OpenFileDialogFlags.DoNotTransferRemoteFiles); 
    var dr = ofd.ShowDialog(); 
    if (dr != System.Windows.Forms.DialogResult.OK) 
     return; 
    ed.WriteMessage("\nFile selected was \"{0}\". Contains these sheets:", ofd.Filename); 
    var sheetNames = GetSheetNames(ofd.Filename); 
    if (sheetNames.Count == 0) 
    { 
     ed.WriteMessage("\nWorkbook doesn't contain any sheets."); 
     return; 
    } 
    for (int i = 0; i < sheetNames.Count; i++) 
    { 
     var name = sheetNames[i]; 
     ed.WriteMessage("\n{0} - {1}", i + 1, name); 
    } 
    var pio = new PromptIntegerOptions("\nSelect a sheet"); 
    pio.AllowNegative = false; 
    pio.AllowZero = false; 
    pio.DefaultValue = 1; 
    pio.UseDefaultValue = true; 
    pio.LowerLimit = 1; 
    pio.UpperLimit = sheetNames.Count; 
    var pir = ed.GetInteger(pio); 
    if (pir.Status != PromptStatus.OK) 
     return; 
    var ppr = ed.GetPoint("\nEnter table insertion point"); 
    if (ppr.Status != PromptStatus.OK) 
     return; 
    var dlm = db.DataLinkManager; 
    var dlId = dlm.GetDataLink(dlName); 
    if (dlId != ObjectId.Null) 
    { 
     dlm.RemoveDataLink(dlId); 
    } 
    var dl = new DataLink(); 
    dl.DataAdapterId = "AcExcel"; 
    dl.Name = dlName; 
    dl.Description = "Excel 2 Autocad"; 
    dl.ConnectionString = ofd.Filename + "!" + sheetNames[pir.Value - 1]; 
    dl.DataLinkOption = DataLinkOption.PersistCache; 
    dl.UpdateOption |= (int)UpdateOption.AllowSourceUpdate; 
    dlId = dlm.AddDataLink(dl); 
    using (var tr = doc.TransactionManager.StartTransaction()) 
    { 
     tr.AddNewlyCreatedDBObject(dl, true); 
     var bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); 
     var tb = new Table(); 
     tb.TableStyle = db.Tablestyle; 
     tb.Position = ppr.Value; 
     tb.Cells.SetDataLink(dlId, true); 
     tb.GenerateLayout(); 
     var btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); 
     btr.AppendEntity(tb); 
     tr.AddNewlyCreatedDBObject(tb, true); 
     tr.Commit(); 
    } 

}

+0

を試すこと私はこの位置が固定されていると信じ、GenerateLayoutの後にBoundingBoxを使ってPositionを再計算する必要があります。 –

+0

BoundingBoxについて私に説明していただければ幸いです。前もって感謝します!!! –

答えて

0

あなたはこの拡張メソッドのようなもの(それをテストするために多くの時間を持っていなかった...)

/// <summary> 
/// Recalculate the position for a bottom left coordinate. 
/// Must be called after GenerateLayout(). 
/// </summary> 
/// <param name="tbl">Table object</param> 
/// <param name="bottomLeft">Bottom Left desired position</param> 
public static void MoveToBottomLeft(this Table tbl, Point3d bottomLeft) 
{ 
    Point3d maxPoint = tbl.Bounds.Value.MaxPoint; // this is the bottom left (min point) 
    Point3d topLeft = new Point3d(maxPoint.Y, bottomLeft.Y, bottomLeft.Z); // this should be topLeft 
    Point3d newPosition = bottomLeft.TransformBy(Matrix3d.Displacement(bottomLeft.GetVectorTo(newPosition))); // move bottomLeft to newPosition 
    tbl.Position = newPosition; // apply the new position 
} 
+0

お時間をありがとう!もう一度。 –

関連する問題