【field相关】操作字段对话框,AcFdUiInvokeFieldDialog
本帖最后由 qq1254582201 于 2022-6-9 15:20 编辑using System;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
namespace FieldDialog
{
public class Utils
{
private static extern Int32 InvokeFieldDialog(ref IntPtr fd, Int32 bEdit, IntPtr pDb, IntPtr pParent);
public void InsField()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
if (doc == null) return;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptPointResult ppr =
ed.GetPoint("\nУкажите точку вставки мультитекста: ");
if (ppr.Status != PromptStatus.OK) return;
using (Field fd = new Field())
{
IntPtr ptr = fd.UnmanagedObject;
InvokeFieldDialog(ref ptr, 1, db.UnmanagedObject, IntPtr.Zero);
using (BlockTableRecord curSpace =
db.CurrentSpaceId.Open(OpenMode.ForWrite) as BlockTableRecord)
{
using (MText mt = new MText())
{
mt.Location = ppr.Value;
curSpace.AppendEntity(mt);
mt.SetField("TEXT", fd);
fd.Evaluate((int)FieldEvaluationContext.Demand, db);
}
}
}
}
}
} 本帖最后由 qq1254582201 于 2022-6-9 15:24 编辑
void addFieldWithDialog()
{
AcGePoint3d pnt1;
// pick start point
if(acedGetPoint(NULL, L"\nPick Insertion point ",
asDblArray(pnt1)) != RTNORM)
{
return;
}
AcDbDatabase *pDb =
acdbHostApplicationServices()->workingDatabase();
AcDbField *pField = NULL;
Acad::ErrorStatus es;
//show the dialog box..
if(AcFdUiInvokeFieldDialog(pField, FALSE, pDb) == IDOK)
{
//open the model space for write
AcDbObjectId modelId;
modelId = acdbSymUtil()->blockModelSpaceId(pDb);
AcDbBlockTableRecord *pBlockTableRecord;
es = acdbOpenAcDbObject((AcDbObject*&)pBlockTableRecord,
modelId, AcDb::kForWrite);
//add a Mtext;
AcDbMText *pMText = new AcDbMText();
pMText->setLocation(pnt1);
// Add to Db
AcDbObjectId objectId;
pBlockTableRecord->appendAcDbEntity(objectId, pMText);
AcDbObjectId fieldId;
//add a field
es = pMText->setField(_T("TEXT"), pField, fieldId);
es = pField->evaluate(AcDbField::kDemand, pDb);
pField->close();
pMText->close();
pBlockTableRecord->close();
}
}这个是arx版的
页:
[1]