简体   繁体   English

Autocad.net Get Line and Make line by it

[英]Autocad.net Get Line and Make line by it

I've got something like following code:我有类似以下代码的内容:

var trat = doc.Database.TransactionManager.StartTransaction();
blort = trat.GetObject(blott[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

List<Line> nieuwelijnen = new List<Line>(); 
Point3dCollection punten = new Point3dCollection();
foreach (ObjectId id in set.GetObjectIds())
{
  Entity ent = trat.GetObject(id, OpenMode.ForRead) as Entity;
  breaklijn.IntersectWith(ent, Intersect.OnBothOperands, punten, IntPtr.Zero, IntPtr.Zero);

  if (ent.GetType() == typeof(Line))
    {
    Line tijdelijk = trat.GetObject(id, OpenMode.ForRead) as Line;
    Line tijdelijk1 = new Line(tijdelijk.startpoint, punten[0]);
    nieuwelijnen.Add(tijdelijk1);
    }
}

int iaantal = nieuwelijnen.Count();
for(int i = 0; i < iaantal; i++ )
  {
  blort.AppendEntity(nieuwelijnen[i]);
  }

trat.Commit(); 

At first it seems to work fine, what means, when I follow by 'watches', properties and stuff seem to be set right, right startpoint, right endpoint, works ok.起初它似乎工作正常,这意味着当我跟随“手表”时,属性和东西似乎设置正确,正确的起点,正确的终点,工作正常。

however, it stucks on the trat.commit(), not giving any errors or such, but neither adding the lines to my autocad.但是,它卡在 trat.commit() 上,没有给出任何错误等,但也没有将这些行添加到我的 autocad 中。

then, when opening the watches, there are some runtime errors in the lines, so expect the mistake to be in the 'Line tijdelijk = trat.GetObject(id, OpenMode.ForRead) as Line;'.然后,当打开手表时,行中有一些运行时错误,所以预计错误出现在“Line tijdelijk = trat.GetObject(id, OpenMode.ForRead) as Line;”中。 however not sure of it.但是不确定。 must be some dumb mistake but can't figure out what.一定是一些愚蠢的错误,但无法弄清楚是什么。 any ideas?有任何想法吗?

You need to:你需要:

trat.AddNewlyCreatedDBObject(blort, true);

Before:前:

trat.Commit(); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM