- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Guys, I've had the same 'problem' now couple of times, wonder what's your thoughts on this:
for example, I've turned this code into an method, with as input an hatch, and as output the hatches boundaries. something like:
public static DBObjectCollection hatchbounds(Hatch hatch)
{
DBObjectCollection resultaat = new DBObjectCollection();
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
using (Transaction tr = doc.TransactionManager.StartTransaction())
if (hatch != null)
{
BlockTableRecord btr = tr.GetObject(hatch.OwnerId, OpenMode.ForWrite) as BlockTableRecord;
Plane plane = hatch.GetPlane();
int nLoops = hatch.NumberOfLoops;
for (int i = 0; i < nLoops; i++)
{
HatchLoop loop = hatch.GetLoopAt(i);
if (loop.IsPolyline)
{
using (Polyline poly = new Polyline())
{
int iVertex = 0;
foreach (BulgeVertex bv in loop.Polyline)
{
poly.AddVertexAt(iVertex++, bv.Vertex, bv.Bulge, 0.0, 0.0);
}
resultaat.Add(poly);
//tr.AddNewlyCreatedDBObject(poly, true);
}
}
}
}
}
In the main code I want to decide whether the boundaries should be drawn or not. So I've got (something like) this:
DBObjectCollection bds = hatchbounds(tijd);
//DECIDE WHETHER THEY SHOULD BE DRAWN OR NOT
foreach (Entity a in bds)
{
a.setpropertiesfrom(tijd)
blort.AppendEntity(a);
trat.AddNewlyCreatedDBObject(a, true);
}
Now this code is not working. it gives a "eNullEntityPointer"-error or in some cases an fatal error in autocad. Strange, because when putting them in the same code (so without a method) they should work right?
However, what i'm mostly interrested in is not how to solve this, but:
Since working with an dbobjectcollection, is it correct I need to add the objects to the database in the first method? Because, maybe from the main method, it seems unnecessary to do this right? Why would I add them to the database and erase them in the main code? Is that the only way? And there isn't something like just an objectCollection. or EntityCollection. I've also tried making a Curve2dCollection, but converting the curves to Entities seems lots of extra work. Next to that, the most important reason for asking this question is I trying to understand exact working of the database, not to get the code working.
Anyhow, it isn't all perfectly clear to me, any explantion or what is going wrong would be appreciated.
Solved! Go to Solution.