From 159c0761cf6289c0195e8c5b7fe7ca99210b9fa1 Mon Sep 17 00:00:00 2001 From: vicwjb Date: Sun, 17 Aug 2025 11:43:48 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8DzcedGetEnv=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E5=85=A5=E5=8F=A3=E7=82=B9=E9=94=99=E8=AF=AF=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/CADShared/Runtime/Env.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CADShared/Runtime/Env.cs b/src/CADShared/Runtime/Env.cs index fd18bc8..024eb5d 100644 --- a/src/CADShared/Runtime/Env.cs +++ b/src/CADShared/Runtime/Env.cs @@ -469,8 +469,8 @@ public static void SetVar(string varName, object value, bool echo = true) // TODO: 中望没有测试,此处仅为不报错;本工程所有含有"中望"均存在问题 #if zcad [System.Security.SuppressUnmanagedCodeSecurity] - [DllImport("zwcad.exe", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl, - EntryPoint = "zcedGetEnv")] + [DllImport("zwcad.exe", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl, + EntryPoint = "?zcedGetEnv@@YAHPEB_WPEA_W_K@Z")]//名称大小写不能换 private static extern int AcedGetEnv(string? envName, StringBuilder returnValue); [System.Security.SuppressUnmanagedCodeSecurity] -- Gitee From fe4a8388af389d166a58ac4f3a0b9f2caa7d6326 Mon Sep 17 00:00:00 2001 From: vicwjb Date: Sun, 17 Aug 2025 12:08:23 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E4=B8=BA=E5=A4=9A=E8=A1=8C=E6=96=87=E5=AD=97?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E7=9A=84=E6=89=A9=E5=B1=95=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/CADShared/CADShared.projitems | 1 + .../Entity/AttributeDefinitionEx.cs | 22 +++++++++++ tests/TestShared/TestBlock.cs | 38 +++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 src/CADShared/ExtensionMethod/Entity/AttributeDefinitionEx.cs diff --git a/src/CADShared/CADShared.projitems b/src/CADShared/CADShared.projitems index ecde82d..d221b2c 100644 --- a/src/CADShared/CADShared.projitems +++ b/src/CADShared/CADShared.projitems @@ -40,6 +40,7 @@ + diff --git a/src/CADShared/ExtensionMethod/Entity/AttributeDefinitionEx.cs b/src/CADShared/ExtensionMethod/Entity/AttributeDefinitionEx.cs new file mode 100644 index 0000000..e60e181 --- /dev/null +++ b/src/CADShared/ExtensionMethod/Entity/AttributeDefinitionEx.cs @@ -0,0 +1,22 @@ +namespace IFoxCAD.Cad; + +/// +/// 属性文字扩展 +/// +public static class AttributeDefinitionEx +{ + /// + /// 设置属性为多行文字,并通过委托设置多行文字的属性 + /// + /// 属性对象 + /// 设置多行文字的委托 + public static void SetMTextAttribute(this AttributeDefinition attr, Action action) + { + attr.IsMTextAttributeDefinition = true; + var mt = attr.MTextAttributeDefinition; + action(mt); + attr.MTextAttributeDefinition = mt; + attr.UpdateMTextAttributeDefinition(); + } + +} \ No newline at end of file diff --git a/tests/TestShared/TestBlock.cs b/tests/TestShared/TestBlock.cs index 20baa82..918dca2 100644 --- a/tests/TestShared/TestBlock.cs +++ b/tests/TestShared/TestBlock.cs @@ -287,6 +287,44 @@ public void Test_BlockFiledxf() } + + [CommandMethod("Test_CreateMTextAttributeBlock")] + public void Test_CreateMTextAttributeBlock() + { + + using var tr = new DBTrans(); + + tr.BlockTable.Add("MTextAttributeBlock",btr => + { + btr.Origin = Point3d.Origin; + // 创建一个多行文字作为块的一部分 + var mtext = new MText(); + mtext.Contents = "默认多行文字内容\n第二行内容\n第三行内容"; + mtext.Location = new Point3d(0, 0, 0); + mtext.Width = 200; // 多行文字宽度 + mtext.Height = 2.5; // 文字高度 + btr.AddEntity(mtext); + + + // 创建属性定义 + var attrDef = new AttributeDefinition(); + attrDef.Position = new Point3d(0, -50, 0); // 位置在多行文字下方 + attrDef.Prompt = "请输入属性值"; + attrDef.Tag = "ATTR_TAG"; + attrDef.TextString = "默认属性值"; + attrDef.Height = 2.5; + attrDef.Justify = AttachmentPoint.MiddleCenter; // 居中对齐 + + // 设置为多行属性 + attrDef.SetMTextAttribute(att => att.Width = 100); + btr.AddEntity(attrDef); + }); + + tr.CurrentSpace.InsertBlock(Point3d.Origin, "MTextAttributeBlock"); + + + } + [CommandMethod(nameof(Test_ClipBlock))] public void Test_ClipBlock() -- Gitee