public static bool GetPoint(ref AcadGeo.Point3d val, string message, AcadGeo.Point3d bp) { AcadApp.DocumentManager.MdiActiveDocument.Window.Focus(); using (AcadApp.DocumentManager.MdiActiveDocument.LockDocument()) { using (AcadDB.Transaction tr = AcadFuncs.GetActiveDoc().TransactionManager.StartTransaction()) { AcadEd.PromptPointOptions prmpt_pnt = new AcadEd.PromptPointOptions(message); prmpt_pnt.UseBasePoint = true; prmpt_pnt.BasePoint = bp; AcadEd.PromptPointResult prmpt_ret = AcadFuncs.GetEditor().GetPoint(prmpt_pnt); if (AcadEd.PromptStatus.Cancel == prmpt_ret.Status) { tr.Abort(); tr.Dispose(); return(false); } val = prmpt_ret.Value; tr.Commit(); } } return(true); }
Sampler(Autodesk.AutoCAD.EditorInput.JigPrompts prompts) { AcEd.SamplerStatus samplerStatus = AcEd.SamplerStatus.NoChange; AcEd.JigPromptPointOptions opts = new AcEd.JigPromptPointOptions(); opts.Message = "\nPoint"; opts.BasePoint = m_startPt; opts.UseBasePoint = true; opts.UserInputControls |= AcEd.UserInputControls.AnyBlankTerminatesInput | AcEd.UserInputControls.NullResponseAccepted; AcEd.PromptPointResult result = prompts.AcquirePoint(opts); if (result.Status == AcEd.PromptStatus.OK) { if (m_endPt != result.Value) { m_endPt = result.Value; samplerStatus = AcEd.SamplerStatus.OK; } } return(samplerStatus); }
/// <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(); }