0564.测试.zip在ORD旗舰版中出现了插入多个单元软件直接崩退的问题,也不会报错,在原来的ORD 10.08版本中就没有出现过这种情况,这是我的测试代码和文件,请各位老师帮忙看看是什么问题导致的, 谢谢
不知道您用中国版本地工具中的放置单元工具测试过没有,单元放置这块本身底层就是MS的接口,看了您的代码,崩溃具体出现再哪一块》?是 BIM.CellElement ele = myApp.CreateCellElement2(cellName, point, scal, true, ma);这句吗?
老师,崩溃的地方我们没找到,单步执行就不会崩溃,直接执行就软件崩退,报错程序信息为 “[10004] OpenRoadsUltimateChina.exe”已退出,返回值为 -1073740940 (0xc0000374)。
麻烦老师运行一下我的代码中的这个过程, 看看在您那崩溃吗
老师, 用我那个代码,能加载出来单元库, 没问题
换用PInvoke技术调用c/c++的函数来完成从单元库中放置单元的工作吧,COM接口可能在这种频繁调用的情况下有些问题。
[DllImport("ustation.dll")] public unsafe static extern uint mdlCell_placeCell(DPoint3d* rOrigin, DPoint3d* scale, bool trueScale, DMatrix3d* rotMatrix, short* attributes, uint ggroup, bool relativeMode, uint baseLevel, int sharedFlag, long cellName, long library); [DllImport("ustation.dll")] public unsafe static extern uint mdlElmdscr_read(long* elemDescrPP, uint filePos, long modelRef, int expandSharedCells, uint* readFilePos); public unsafe static void TempFunction() { MsApp.AttachCellLibrary(@"D:\CellLib1.dgn"); DPoint3d rOrigin = DPoint3d.Zero; DPoint3d scale = new DPoint3d(1, 1, 1); DMatrix3d rotMatrix = DMatrix3d.Identity; string cellName = "MyCell1"; IntPtr intPtr = Marshal.StringToHGlobalUni(cellName); uint filePos = mdlCell_placeCell(&rOrigin, &scale, false, &rotMatrix, null, 0, false, 0, 0, intPtr.ToInt64(), 0); long elmdscr; mdlElmdscr_read(&elmdscr, filePos, Session.Instance.GetActiveDgnModel().GetNative().ToInt64(), 0, null); BIM.Element cellEle = MsApp.MdlCreateElementFromElementDescrP(elmdscr); MessageBox.Show(cellEle.ID.ToString()); Marshal.FreeHGlobal(intPtr); }
老师,为啥我这会报错,是我缺少引用吗
请勾选下图这个选项:
老师,我试了, 插入单元没问题了,问题应该是在 ReplaceTextInCell(ref cell, fontName, fontHeight, fontWidth, txtA, txtB); 这个过程了, 请老师帮忙看看是哪里写的有问题
您是如何确定问题出现在ReplaceTextInCell这个函数里边的了?
老师,可能我猜测的不对,我这边再试试,您也帮忙看看到底是哪里写的有问题
我测试了,问题确实出在这个函数里边,如下代码所示是以前写的修改单元中文本元素的代码,您可以参考着改成您的。主要区别就是不再将子元素拷贝一份去修改,而是直接对遍历到的子元素进行修改,修改后调用其Rewrite方法保存修改。
var subEls = comEl.GetSubElements(); while (subEls.MoveNext()) { var subEl = subEls.Current; if (subEl.Type == BIM.MsdElementType.Text) { BIM.TextElement curTxtEle = (BIM.TextElement)subEl; curTxtEle.Text = "aaa"; curTxtEle.Rewrite(); } else if (BIM.MsdElementType.TextNode == subEl.Type) { BIM.TextNodeElement curTxtNodeEle = (BIM.TextNodeElement)subEl; BIM.ElementEnumerator curSubEles = curTxtNodeEle.GetSubElements(); while (curSubEles.MoveNext()) { var curSubEle = curSubEles.Current; if (curSubEle.Type == BIM.MsdElementType.Text) { BIM.TextElement curTxtEle = (BIM.TextElement)curSubEle; curTxtEle.Text = "aaa"; curTxtEle.Rewrite(); } } } }
老师, 我替换上您这段代码试了下, 还是崩,不知道崩在哪