private void NewPos() { Autodesk.AutoCAD.EditorInput.Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; PromptPointResult result = ed.GetPoint("Baz noktası: "); if (result.Status == PromptStatus.OK) { Database db = HostApplicationServices.WorkingDatabase; using (Transaction tr = db.TransactionManager.StartTransaction()) { try { BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); Point3d pt = result.Value; RebarPos pos = new RebarPos(); pos.TransformBy(Matrix3d.Displacement(pt.GetAsVector())); pos.TransformBy(Matrix3d.Scaling(25.0, pt)); pos.Pos = ""; pos.Count = "1"; pos.Diameter = "12"; pos.Spacing = ""; pos.Shape = "GENEL"; pos.A = "1000"; pos.Note = ""; #if DEBUG pos.Pos = "1"; pos.Count = "2x3"; pos.Diameter = "12"; pos.Spacing = "200"; pos.Shape = "00"; pos.A = "1000"; pos.Note = ""; #endif pos.SetDatabaseDefaults(db); btr.AppendEntity(pos); tr.AddNewlyCreatedDBObject(pos, true); tr.Commit(); } catch (System.Exception ex) { MessageBox.Show("Error: " + ex.Message, "RebarPos", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
public void CMD_DumpShapes() { Autodesk.AutoCAD.EditorInput.Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; PromptPointResult result = ed.GetPoint("Baz noktası: "); if (result.Status != PromptStatus.OK) { return; } Point3d pt = result.Value; foreach (string name in PosShape.GetAllPosShapes()) { DWGUtility.DrawShape(name, pt, 100); pt = pt.Add(new Vector3d(0, 120, 0)); } }
/// <summary> /// insert signatures /// </summary> /// <param name="dwgPath"></param> /// <param name="dwgNameList"></param> public void InsertSign(string dwgPath, List <string> dwgNameList) { AdeskAppSvr.Document doc = AdeskAppSvr.Application.DocumentManager.MdiActiveDocument; this.Hide(); AdeskDBSvr.Database CurrDB = doc.Database;//current database AdeskEdIn.Editor ed = doc.Editor; AdeskEdIn.PromptPointResult prPointRes_Base = ed.GetPoint(new AdeskEdIn.PromptPointOptions("选择插入的基点")); AdeskEdIn.PromptPointResult prPointRes_opp = ed.GetPoint(new AdeskEdIn.PromptPointOptions("选择基点的对角点")); //In order to make the signs look nicely , calculate the base point and its opposite point AdeskGeo.Point3d P_base = CalPoint(prPointRes_Base.Value, prPointRes_opp.Value, 0.1); AdeskGeo.Point3d P_opp = CalPoint(prPointRes_Base.Value, prPointRes_opp.Value, 0.9); //sign's width and height double SignWidth = P_opp.X - P_base.X; double SignHeight = P_opp.Y - P_base.Y; //distance between each other double distanceW = prPointRes_opp.Value.X - prPointRes_Base.Value.X; double distanceH = prPointRes_opp.Value.Y - prPointRes_Base.Value.Y; //scale of signature. 36 is the width of sign, and 17 is the height. you should adjust them in your condition. double scaleWidth = SignWidth / 36; double scaleHeight = SignHeight / 17; //today string date = System.DateTime.Today.ToLocalTime().ToString().Split(' ')[0]; try { for (int i = 0; i < dwgNameList.Count; i++) { using (AdeskDBSvr.Database tmpdb = new AdeskDBSvr.Database(false, false)) { //read drawing tmpdb.ReadDwgFile(dwgPath + dwgNameList[i], FileShare.Read, true, null); //insert it as a new block AdeskDBSvr.ObjectId idBTR = CurrDB.Insert(this.ICCardList[i], tmpdb, false); using (AdeskDBSvr.Transaction trans = CurrDB.TransactionManager.StartTransaction()) { AdeskDBSvr.BlockTable bt = (AdeskDBSvr.BlockTable)trans.GetObject(CurrDB.BlockTableId, AdeskDBSvr.OpenMode.ForRead); AdeskDBSvr.BlockTableRecord btr = (AdeskDBSvr.BlockTableRecord)trans.GetObject(bt[AdeskDBSvr.BlockTableRecord.ModelSpace], AdeskDBSvr.OpenMode.ForWrite); //insert point AdeskGeo.Point3d inPt = new AdeskGeo.Point3d(P_base.X, P_base.Y - i * distanceH, P_base.Z); #region signature date //signature date AdeskDBSvr.MText SignDate = new AdeskDBSvr.MText(); AdeskDBSvr.TextStyleTable TextStyleTB = (AdeskDBSvr.TextStyleTable)trans.GetObject(CurrDB.TextStyleTableId, AdeskDBSvr.OpenMode.ForWrite); AdeskDBSvr.TextStyleTableRecord TextStyleTBRec = new AdeskDBSvr.TextStyleTableRecord(); TextStyleTBRec.Font = new AdeskGra.FontDescriptor("宋体", true, false, 0, 0); TextStyleTB.Add(TextStyleTBRec); trans.AddNewlyCreatedDBObject(TextStyleTBRec, true); //trans.Commit(); SignDate.TextStyle = TextStyleTBRec.Id; SignDate.Contents = date; SignDate.TextHeight = SignHeight / 2; SignDate.Width = SignWidth / 3; //date's location should fit the frame SignDate.Location = new AdeskGeo.Point3d((inPt.X + distanceW), (inPt.Y + 1.5 * SignDate.TextHeight), inPt.Z); btr.AppendEntity(SignDate); trans.AddNewlyCreatedDBObject(SignDate, true); #endregion try { //create a ref to the block using (AdeskDBSvr.BlockReference bref = new AdeskDBSvr.BlockReference(inPt, idBTR)) { bref.ScaleFactors = new AdeskGeo.Scale3d(scaleWidth, scaleHeight, 1.0); btr.AppendEntity(bref); trans.AddNewlyCreatedDBObject(bref, true); } trans.Commit(); } catch (System.Exception err) { MessageBox.Show("one: " + err.Message); } } } } } catch (Autodesk.AutoCAD.Runtime.Exception err) { MessageBox.Show("insert: " + err.Message); } this.Show(); }