请问中望软件用的是哪个版本?或者可以用最新的2026版试试,又或者把你例子的代码发上来看看(#^.^#)~
幸运之星正在降临...
点击领取今天的签到奖励!
恭喜!您今天获得了{{mission.data.mission.credit}}积分
我的优惠劵
-
¥优惠劵使用时效:无法使用使用时效:
之前
使用时效:永久有效优惠劵ID:×
没有优惠劵可用!





















使用的是2026版本,using (var tr = db.TransactionManager.StartOpenCloseTransaction()), solid = tr.GetObject(solid.ObjectId, OpenMode.ForWrite) as Solid3d; solid.HandOverTo(newsolid, true, true); btr.AppendEntity(newsolid); tr.AddNewlyCreatedDBObject(newsolid, true); 这是主要代码,我在看官方文档的时候,官网文档描述为未存入数据库的临时实体覆盖原来的实体,在执行到solid.HandOverTo(newsolid, true, true)这句话的时候就会报错
能否提供完整一点的代码,现在代码有点少判定不出问题,谢谢!
public class ZhiPai { [CommandMethod(“SHL”)] public void ShortenLines() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; SelectionSet ss = SelectLines(ed, “nSelect lines to shorten: “); if (ss != null) { Transaction tr = db.TransactionManager.StartOpenCloseTransaction(); using (tr) { foreach (SelectedObject so in ss) { Curve cur = (Curve)tr.GetObject( so.ObjectId, OpenMode.ForWrite ); double sp = cur.StartParam, ep = cur.EndParam, delta = (ep – sp) * 0.25; DoubleCollection dc = new DoubleCollection(); dc.Add(sp + delta); dc.Add(ep – delta); DBObjectCollection objs = cur.GetSplitCurves(dc); if (objs.Count == 3) { Entity ent = (Entity)objs[1]; cur.HandOverTo(ent, true, true); tr.AddNewlyCreatedDBObject(ent, true); cur.Dispose(); objs[0].Dispose(); objs[2].Dispose(); } } tr.Commit(); } } } private SelectionSet SelectLines(Editor ed, string msg) { PromptSelectionOptions pso = new PromptSelectionOptions(); pso.MessageForAdding = (string.IsNullOrEmpty(msg) ? “nSelect lines: ” : msg); TypedValue[] tvs = new TypedValue[1] { new TypedValue( (int)DxfCode.Start, “LINE” ) }; SelectionFilter sf = new SelectionFilter(tvs); PromptSelectionResult psr = ed.GetSelection(pso, sf); if (psr.Status != PromptStatus.OK || psr.Value.Count <= 0) return null; return psr.Value; } }
参考手册里面提到不能用事务来打开实体了,参考下面示例代码 [CommandMethod(“TestHandOverTo”)] public void TestHandOverTo() { Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; PromptEntityOptions peo = new PromptEntityOptions(“Please select a line:”); peo.SetRejectMessage(“Please select a line”); peo.AddAllowedClass(typeof(Line), false); PromptEntityResult per = ed.GetEntity(peo); if (per.Status == PromptStatus.OK) { // ⚠️ 注意:这里没有使用 Transaction(和原 VB.NET 一致) Line line = (Line)per.ObjectId.Open(OpenMode.ForWrite); Polyline pline = new Polyline(); pline.AddVertexAt( 0, new Point2d(line.StartPoint.X, line.StartPoint.Y), 0, 0, 0 ); pline.AddVertexAt( 1, new Point2d(line.EndPoint.X, line.EndPoint.Y), 0, 0, 0 ); line.HandOverTo(pline, true, true); // 提交 handOverTo 结果 pline.Close(); }
谢谢你,成功了
你这个参考手册是在官网下载的嘛?我的参考手册只有函数原型,没有任何示例和介绍
参考手册点击下载