Author Topic: Transaction.AddNewlyCreatedDBObject() parameters  (Read 2889 times)

0 Members and 1 Guest are viewing this topic.

GUIDO ROOMS

  • Guest
Transaction.AddNewlyCreatedDBObject() parameters
« 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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Transaction.AddNewlyCreatedDBObject() parameters
« Reply #1 on: June 20, 2012, 07:57:09 AM »
from the Help ArxMgd.chm

Quote
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:

Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

GUIDO ROOMS

  • Guest
Re: Transaction.AddNewlyCreatedDBObject() parameters
« Reply #2 on: June 20, 2012, 09:05:58 AM »
Quote
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.

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Transaction.AddNewlyCreatedDBObject() parameters
« Reply #3 on: June 20, 2012, 12:42:27 PM »
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.
Revit 2019, AMEP 2019 64bit Win 10

dgorsman

  • Water Moccasin
  • Posts: 2394
Re: Transaction.AddNewlyCreatedDBObject() parameters
« Reply #4 on: June 20, 2012, 01:02:14 PM »
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.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

Maxence

  • Mosquito
  • Posts: 1
Re: Transaction.AddNewlyCreatedDBObject() parameters
« Reply #5 on: October 31, 2015, 06:48:07 AM »
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:

Code: [Select]
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
« Last Edit: October 31, 2015, 06:52:57 AM by Maxence »

CADbloke

  • Bull Frog
  • Posts: 307
  • Crash Test Dummy
Re: Transaction.AddNewlyCreatedDBObject() parameters
« Reply #6 on: November 01, 2015, 05:41:25 PM »
@Maxence, welcome to the Swamp. For those who don't know, the Jon Skeet of AutoCAD (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 in SMF (this forum).

Jeff H

  • Needs a day job
  • Posts: 6043
Re: Transaction.AddNewlyCreatedDBObject() parameters
« Reply #7 on: November 07, 2015, 02:56:23 AM »
Thanks Maxence and welcome.

Never could get an example or explanation when you would pass in false until now.

Bryco

  • Water Moccasin
  • Posts: 1849
Re: Transaction.AddNewlyCreatedDBObject() parameters
« Reply #8 on: November 09, 2015, 08:32:16 PM »
Wow that's why my convert poly crashes. Cheers mate

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Transaction.AddNewlyCreatedDBObject() parameters
« Reply #9 on: November 09, 2015, 08:39:53 PM »
David covered it with
Quote
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.
« Last Edit: November 09, 2015, 08:46:09 PM by Kerry »
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--