Author Topic: Add note properties  (Read 2841 times)

0 Members and 1 Guest are viewing this topic.

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Add note properties
« on: August 30, 2016, 10:50:12 AM »
Trying to add a note to an autocad dbpoint but think I have something wrong with my code below. Little help appreciated. Thanks!

Code - C#: [Select]
  1.                    acPoint.CreateExtensionDictionary();                                        
  2.                                         TextNote txt = new TextNote();
  3.                                         txt.Note = finalstring;
  4.                                         DBDictionary extdict = (DBDictionary)acPoint.ExtensionDictionary.GetObject(OpenMode.ForWrite);
  5.                                         extdict.SetAt(TextNote.ExtensionDictionaryName, txt);
  6.                                         MyTrans.AddNewlyCreatedDBObject(txt, true);
  7.  

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Add note properties
« Reply #1 on: August 30, 2016, 11:44:02 AM »
Been while since I've done .Net, but what does 'CreateExtensionDictioary()' return?  If it returns the dictionary, then I would think to add the point to that dictionary, and add that to the database.

Right now it looks like you are creating the dictionary, then trying to get the newly created dictionary from an object that does not have it yet (since it has not been added to the database).

I could be totally wrong though, as I said it's been awhile since I played with .Net.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Re: Add note properties
« Reply #2 on: August 30, 2016, 09:57:29 PM »
Thanks T.Willey...that was it...had to split the transaction into two.

Much appreciated!

Code - C#: [Select]
  1.                                             acBlkTblRec.AppendEntity(acPoint);
  2.                                             newtrans.AddNewlyCreatedDBObject(acPoint, true);
  3.                                             newtrans.Commit();
  4.  
  5.                                             acPoint.CreateExtensionDictionary();
  6.                                             TextNote txt = new TextNote();
  7.                                             txt.Note = finalstring;
  8.                                             DBDictionary extdict = (DBDictionary)acPoint.ExtensionDictionary.GetObject(OpenMode.ForWrite);
  9.                                             extdict.SetAt(TextNote.ExtensionDictionaryName, txt);
  10.                                             MyTrans.AddNewlyCreatedDBObject(txt, true);

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Add note properties
« Reply #3 on: August 31, 2016, 03:01:32 AM »
I'm glad you got it to work, but I have to think there is a better way than committing two transactions like that.  Hopefully someone more familiar with .Net will chime in with a better solution.  If not, maybe I can look into some of my old code to see if I did anything like this.  When I have time.  You're welcome, Area51Visitor.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: Add note properties
« Reply #4 on: August 31, 2016, 03:14:09 AM »

Have you tried just using the one transaction and only calling commit at the end?
You can use AddAddNewlyCreatedDBObject more than once with different objects and sometimes you need to do this with some entities as you have found before you can edit some properties.

You can think of a transaction like an undo controller, starting the transaction is like setting the undo marker, you do your stuff and if anything goes wrong the transaction will roll back any changes to that point. Once you commit it will then finalise the changes.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Add note properties
« Reply #5 on: August 31, 2016, 03:16:36 AM »
Check out the code my Gile in this post:  https://www.theswamp.org/index.php?topic=42203.msg473386#msg473386  I think you just need to add you point, AddNewlyCreatedDBObject(acPoint, true), to your transaction, the single main transaction, before you can use it.  You didn't have that step in your first post.

Ninja'ed by MickD... but I will post it anyway.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Re: Add note properties
« Reply #6 on: August 31, 2016, 11:52:00 PM »

Have you tried just using the one transaction and only calling commit at the end?


I did...but didn't seem to work. I might have had something wrong.  Thanks MickD!

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: Add note properties
« Reply #7 on: September 01, 2016, 10:00:39 AM »
At the risk of sounding dumb...what's a TextNote? Which Assembly is it located in?

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Re: Add note properties
« Reply #8 on: September 01, 2016, 06:55:31 PM »
At the risk of sounding dumb...what's a TextNote? Which Assembly is it located in?

Autodesk.Aec.DatabaseServices