马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
Equivalent to fromAcDbTextStyle() under C# (.NET)
Issue
Is there any way to use the fromAcDbTextStyle() function in my .NET application?
解答:
One workaround for your issue is to use standard .NET P/Invoke technique. The sample below shows code for importing “fromAcDbTextStyle” in .NET.
- [DllImport("acdb18.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl,
- EntryPoint = ?fromAcDbTextStyle@@YA?AW4ErrorStatus@Acad@@AAVAcGiTextStyle@@PB_W@Z)]
- private static extern ErrorStatus fromAcDbTextStyle(System.IntPtr style, string styleName);
- [CommandMethod("getTextStrWidth")]
- public void getTextStrWidth()
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- Editor ed = doc.Editor;
- PromptResult pr = ed.GetString("\nEnter a string: ");
- if (pr.Status != PromptStatus.OK) return;
- using (Transaction Tx = db.TransactionManager.StartTransaction())
- {
- TextStyleTable TxtStlTbl = Tx.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
- string styleName = "STANDARD";
- if (!TxtStlTbl.Has(styleName))
- {
- ed.WriteMessage("\nStyle " + styleName + " doesn't exist :(");
- return;
- }
- Autodesk.AutoCAD.GraphicsInterface.TextStyle iStyle = new Autodesk.AutoCAD.GraphicsInterface.TextStyle();
- if (fromAcDbTextStyle(iStyle.UnmanagedObject, styleName) == ErrorStatus.OK)
- {
- Extents2d ex = iStyle.ExtentsBox(pr.StringResult, true, true, null);
- double width = ex.MaxPoint.X - ex.MinPoint.X;
- double height = ex.MaxPoint.Y - ex.MinPoint.Y;
- ed.WriteMessage("\n-Width = " + width.ToString() + "\n-Height = " + height.ToString());
- }
- }
- }
|