Book a Demo

Author Topic: Setting a specific guid to a new element  (Read 3818 times)

Nik

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Setting a specific guid to a new element
« on: March 17, 2009, 03:22:22 am »
Hello!

I want to import elements from another system into EA which have already a Guid.
I get my new elements with the AddNew command, but they are already assigned with a EA generated Guid and this property is read only.
Is there any way to assign a Guid by myself?
This would be very important, because the elements in EA shoud be clearly associated with the elements in our other system.

best regards, Nik

Frank Horn

  • EA User
  • **
  • Posts: 535
  • Karma: +1/-0
    • View Profile
Re: Setting a specific guid to a new element
« Reply #1 on: March 17, 2009, 04:15:49 am »
I don't think you can assign a guid via API unless you start hacking the database. You could add a tagged value to each imported element though, carrying the guid from the foreign system.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Setting a specific guid to a new element
« Reply #2 on: March 17, 2009, 04:17:33 am »
Technically, the GUID is write-once, sometimes. At least this is how EA views it from the COM interface.

If you are using a 'pure' COM interface it is possible to create a new element, set the ElementGUID property (remember that it is a string), then call Update(). EA will use the GUID you provided instead of assigning one. Either way, once you call Update() for the first time the property is read-only from that point on.

This breaks when you use something like .Net (and perhaps Java). The wrapper for .Net is a bit restricted here; it must assign the property as either read only or read-write. Since the latter is not appropriate - since writing to the property after the first Update() should be impossible - it considers the property read-only from the start.

Once upon a time I asked Sparx to consider an additional method to set the GUID property, even if only before the first Update() call. The .Net and Java wrappers could include this method, providing a way for developers to assign their own GUID. Like the COM interface, attempting to set the GUID after the first Update() - either directly or via the new method - would throw an exception. No response...

If you really want such a thing - any of you - make a feature request to Sparx. Perhaps if enough requests come in from enough developers - there's no real advantage to multiple requests from the same person - Sparx will consider adding the method. If you want to do this, make the request using the Feature Request link below the Support link near the bottom of any forum page.

HTH, David

David
No, you can't have it!

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Setting a specific guid to a new element
« Reply #3 on: March 17, 2009, 08:25:32 am »
Not being able to set a GUID is not related to the .Net wrapper.  It is readonly for .Net because it is readonly for COM.
« Last Edit: March 17, 2009, 08:26:03 am by simonm »

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Setting a specific guid to a new element
« Reply #4 on: March 18, 2009, 01:22:18 am »
Yet you used to be able to set it via the COM interface (not the Interop), then call Update.
No, you can't have it!