TheSwamp
Code Red => .NET => Topic started by: GUIDO ROOMS on June 20, 2012, 07:52:54 AM
-
Could anybody tell me what happens when the second parameter of AddNewlyCreatedDBObject - add - is set to false?
I've searched the docs and whatnot but I don't get much further or maybe I'm too dumb.
If the documentation were anything to write home about, I wouldn't bother you with questions like this one.
Thanks in advance.
-
from the Help ArxMgd.chm
If add == true, the object pointed to by obj is added to the top transaction. If add == false, then the object is removed from whatever transaction it's within.
piccy:
-
If add == true, the object pointed to by obj is added to the top transaction. If add == false, then the object is removed from whatever transaction it's within.
Hi Kerry,
Yes, that's what I found in arxdoc.chm for AutoCAD 2010, too.
But what does it all mean? Why remove an object that's not yet been added?
Why remove an object from a transaction at all, and not plainly erase it from the database?
If the explanation quoted from the docs has hidden meanings, which I doubt, then I don't see them.
Documenting something is not just making lists and summing up. That documentation plainly stinks.
Thanks for the reply.
-
That documentation plainly stinks.
LOL, welcome to the AutoCAD API my friend. Try the verticals like ACA/MEP then you'll know what bad documentation is all about.
-
Its a common problem across many industries. Programmers and other design technicians don't take a lot of training in technical writing, and when the task comes up its shuffled off in favor of something more important (read: less boring). Finally it ends up on the desk of a junior who doesn't know what they are writing about and doesn't have any experience in formatting information to be well laid out. And then the head honcho comes along and demands that work be put aside in favor of their own pet project. Finally the project runs out of budget so any excess hours must be spent only on critical problems.
End result: half-finshed, stale dated, obsolete, and difficult to follow.
-
To answer the question: you need to set add to false in order to remove the object from the transaction when you convert it to another type of object while transfering its id. This happens for example when your convert a light weight polyline to a 2d polyline with the ConvertTo method:
using (Polyline pline = (Polyline)t.GetObject(plineId, OpenMode.ForWrite))
{
t.AddNewlyCreatedDBObject(pline, false);
Polyline2d poly2 = pline.ConvertTo(true);
t.AddNewlyCreatedDBObject(poly2, true);
t.Commit();
}
The LWPolyline is opened by means of the transaction, so it is known by the transaction. But you are replacing it by a Polyline2d which will take the id. So you need to remove the LWPolyline to the transaction by calling AddNewlyCreatedDBObject with the second argument to false. If you don't do this, you will get a fatal error when committing.
In fact, there should have a RemoveObject on the transaction to handle the rare case when you need to remove an object from it, and not an AddNewlyCreatedDBObject with a strange second argument. It's like pressing the Start button on the taskbar to halt the computer :x
http://adndevblog.typepad.com/autocad/2012/06/converting-polyline-to-polyline2d.html
-
@Maxence, welcome to the Swamp. For those who don't know, the Jon Skeet (http://stackoverflow.com/users?tab=Reputation&filter=all) of AutoCAD (http://stackoverflow.com/tags/autocad/topusers) (I assume that's you).
:yay!:
That's a great example btw, as is the Start Button.
btw, this is a good post on formatting code (http://www.theswamp.org/index.php?topic=48309.0) in SMF (this forum).
-
Thanks Maxence and welcome.
Never could get an example or explanation when you would pass in false until now.
-
Wow that's why my convert poly crashes. Cheers mate
-
David covered it with
End result: half-finished, stale dated, obsolete, and difficult to follow.
:cry:
added:
Personally I lay some of the responsibility on the AutoDesk 'visible' guys who started translating vba to vb.net for public consumption because it was "easier". This caused a dichotomy in the message and the resulting effort to support 2 languages sucked the budget dry, resulting in sub-standard documentation.