Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: bilon on July 23, 2019, 02:25:37 am

Title: Create standalone object?
Post by: bilon on July 23, 2019, 02:25:37 am
Is it possible to create standalone object? I mean object not connected to any model object, created just for the needs of a script.
Title: Re: Create standalone object?
Post by: Geert Bellekens on July 23, 2019, 02:34:08 pm
You mean with the API in a script or something like that?

The only way to create a new thing in EA is to use AddNew on the collection of it's owner.

Create a new element: use package.elements.AddNew()

Geert
Title: Re: Create standalone object?
Post by: bilon on July 23, 2019, 06:30:20 pm
I really meant to create it with the API in the script. I was almost sure it is impossible, but I asked :-) What a pity it's not possible!
Title: Re: Create standalone object?
Post by: qwerty on July 23, 2019, 09:06:24 pm
Out of curiosity: Are you the alter ego of Rich Anderson? Quite funny to see the same (impossible) question pop up almost the same time.

q.
Title: Re: Create standalone object?
Post by: bilon on July 24, 2019, 12:03:28 am
You are right, now I see. Interesting, but I'm definitely not Rich Anderson. As I know :-)
Title: Re: Create standalone object?
Post by: qwerty on July 24, 2019, 12:48:11 am
There might be some esoteric link between the both of you ;-)

q.
Title: Re: Create standalone object?
Post by: Mauricio Moya (Arquesoft) on July 24, 2019, 02:00:31 am
You can add it via SQL (inserting the suitable data in the t_object table) with a wrong parent_ID
Title: Re: Create standalone object?
Post by: qwerty on July 24, 2019, 07:18:51 am
You can add it via SQL (inserting the suitable data in the t_object table) with a wrong parent_ID
No. He want's just an in-memory object and not  a deserialized one from the database.

q.
Title: Re: Create standalone object?
Post by: bilon on July 24, 2019, 09:50:28 pm
Yes, that is exactly what I need!
Title: Re: Create standalone object?
Post by: smendonc on July 25, 2019, 04:14:41 am
bilon - Is the below what you are trying to do?

Below is VBScript, I have not tried anything similar with the other scripting languages.
Code: [Select]
option explicit

!INC Local Scripts.EAConstants-VBScript

'
' Script Name:
' Author:
' Purpose:
' Date:
'
sub main

dim myObject

set myObject = new MyClass

myObject.Value1 = Repository.ConnectionString
myObject.Value2 = "Hello World!"

Session.Output myObject.Value1
Session.Output myObject.Value2
end sub

'=================================================================
' Define the in memory object
'=================================================================
Class MyClass

private value_1
private value_2

public property get Value1()
Value1 = value_1
end property

public property let Value1(myVal1)
value_1 = myVal1
end property

public property get Value2()
Value2 = value_2
end property

public property let Value2(myVal2)
value_2 = myVal2
end property
End Class

main
Title: Re: Create standalone object?
Post by: bilon on July 29, 2019, 07:30:10 pm
Something like this, but I want the new objet to be of EA class (for example element) and completely independent on model.
Title: Re: Create standalone object?
Post by: Geert Bellekens on August 05, 2019, 06:36:01 pm
Something like this, but I want the new objet to be of EA class (for example element) and completely independent on model.
Maybe you can explain what you are trying to achieve.
I've never needed anything like this, and I've been doing EA development for more than 10 years now.

Geert