简体   繁体   中英

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.

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;'. 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(); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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