Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - FSXManu

Pages: [1] 2
1

I see. I tried that now but for some reason I still can't see a new row in the t_diagramobjects table.


You may be undoing your changes then by saving the diagram or something like that.
Make sure you don't do anything else after the diagramObject.Update() method and then look in the database.

See https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library/blob/master/Projects/Project%20M/Diagram%20Group/Add%20defaults%20from%20template%20diagram.vbs for an example script that adds elements to a diagram.

Geert

Thank you! It finally worked. It didn't show up until I also assigned diaObj.Sequence a value and then it worked. Thank you very much

Manuel

2
Code: [Select]
diaObj = diagram.DiagramObjects.AddNew("l=200;r=400;t=200;b=600;", "")
    diaObj.Update()

The problem is that you now have a diagramObject that doesn't represent anything.
DiagramObject is nothing more then the link between a diagram and an Element. It says: This element is shown on this diagram at location x with properties y

So you'll have to set the elementID on the diagramObject before saving.

Code: [Select]
diaObj = diagram.DiagramObjects.AddNew("l=200;r=400;t=200;b=600;", "")
   diaObj.ElementID = myElement.ElementID
    diaObj.Update()

There's no deed to call Update() on the DiagramObjects collection.

Geert

I see. I tried that now but for some reason I still can't see a new row in the t_diagramobjects table.

I thought maybe I need to call update on the diagram.DiagramObjects because the Documentation of the Collection Class says "Updates the current Collection object after modification or appending a new item. " for the Update call. But I will get an error saying Update doesn't work on <Unknown> so I assume it doesn't know that this is a collection.

3
Hi

I'm trying to create a DiagramObject with the API but for some reason it won't turn up in the Database and just won't save.
I tested it with the basic sample given on the Documentation (https://sparxsystems.com/enterprise_architect_user_guide/14.0/automation/the_addnew_function.html) but it still won't work. Any idea what I am doing wrong?

Cheers
Manuel
Manuel,

If you post the code you are using we could maybe help.
Without the code it's just guessing.

Geert

Hi Geert

Yes attached it i posted it before I attached it but I modified it now. Sorry for that.

Manuel

4
Hi

I'm trying to create a DiagramObject with the API but for some reason it won't turn up in the Database and just won't save.
I tested it with the basic sample given on the Documentation (https://sparxsystems.com/enterprise_architect_user_guide/14.0/automation/the_addnew_function.html) but it still won't work. Any idea what I am doing wrong?

Edit: attached my code I tried:
diaObj = diagram.DiagramObjects.AddNew("l=200;r=400;t=200;b=600;", "")
    diaObj.Update()


and also
diagram.DiagramObjects.AddNew("l=200;r=400;t=200;b=600;", "")
 diagram.DiagramObjects.Update()

Cheers
Manuel

5
You shouldn't assume the format of t_image.image is going to be the same as the format of t_document.bincontent

The easiest way to figure out what needs to be done is doing it manually though the GUI first.
Then replicate the results using the API untill you have exactly the same info in the bincontent field.

Geert

Yes I managed to make it work. I can import into the T_Image table via the importreferencedata command from the API. I just need to create an xml with the image first. This all worked pretty good. But since last Friday when I import the xml via this importreferencedata command in the code, it only creates one image and overwrites it with the next one so if I import an xml with 10 images in it there will be only one image in the table with the content of the last image. Even when I try it with the code that was working a week before I have the problem. Did you ever came accross this issue?

6
I don't think there's anything special about the imageID, it's an Identity column in SQL server, so it gets a new ID automatically, you only need to insert name, type and image.
Have you tried copying the values from another t_image record?
I'm guessing there's still something wrong with the value in t_image.image

Geert

Okay so I think the t_image entry is fine since that is the entry for the image manager and it shows up just fine there. On the other hand in the t_document table where it's needed to be an artifact and diagram object it's not showing correctly. Even though I took the t_image.image value and put it into t_document.bincontent withoug modifying it. What should go into the BINCONTENT column?

FSXManu

7
I don't think there's anything special about the imageID, it's an Identity column in SQL server, so it gets a new ID automatically, you only need to insert name, type and image.
Have you tried copying the values from another t_image record?
I'm guessing there's still something wrong with the value in t_image.image

Geert

Could be something wrong with the t_imga.image yes. I'm still investigating that. Since I have to create the record with SQL I also have to pass an ImageID since it doesn't get generated. This is primarily that the Image Manager recognises it afaik.


8

What isn't working? That is exactly what you need to do.

Geert

So now most things are fine. I got the Image Artifact in EA. The problem is when I open the Image in EA with double click it says it cannot open it because it's corrupted. But when I look at it in the db it's fine. I think the problem is that the Image is in the t_image table and needs a correct ImageID. I just couldn't figure out how to get the correct ImageID and that this needs to be created by EA or sth. Do you know anything about the ImageID in the t_image table?

9
You have to pass a single string to Repository.Execute, so more like:

Code: [Select]
repo.Execute("INSERT INTO T_DOCUMENT (BINCONTENT) VALUES (image_bytes)")
Geert

Okay I managed to create an entry in the t_document with my image.
But I struggle to link the document entry to a diagram. Any ideas? I tried to add an entry to diagram.DiagramObjects collection but it doesn't work.

FSXManu

10

Then you have to figure out how to import the actual image. The API won't help us there, so you'll have to figure out how to do it directly in the database

EA stores the image of your image asset in the table t_document

Code: [Select]
select d.* from t_object o
inner join t_document d on d.ElementID = o.ea_guid
where o.ea_guid = '{D15B1DD6-A86B-405c-ACFD-6B040386DBEE}'

by replacing the GUID above by the GUID of your image asset you'll find the record you'll need to recreate.
The difficult part will be to somehow fill in the bincontent with an SQL Query


Thank you for your help yeah I was able to use the AddNew method. Now I'm trying to insert the image into the documents table.
I read about the Execute() method which is undocumented but it would help. Problem is I always get the error "Execute() takes from 1 to 2 positional arguments but 3 were given"

My line which gives me that error:
Code: [Select]
repo.Execute("INSERT INTO T_DOCUMENT (BINCONTENT) VALUES (:1);", (image_bytes))

Do you have any idea how that works? I'll try other methods

FSXManu

11
Quote
Can you describe what you do manually to create that in EA?

Sorry I shoul've clarified it a bit better. It should look like in the screenshot below:
So the structure in EA would look something like this:
Packacke
--Class
----StateMachine
------Artifact Image (this is the png image)

I especially struggle with the AddNew method because I can't pass the Image correctly

You haven't actually answerred the question but only described the end result somewhat.
The reason I'm asking is because you'll have to replicate the manual steps using the API.

I'm guessing you'll have to create an artifact, add an image to the image library, and then link the image to the artifact, but it all depends on what you actually do to ge the desired end result.

Geert

Hi again

Yes So what I do in EA itself is open an item of type StateMachine and then in the Toolbox I drag an "Image Asset" into it and select my local png file. So this is what I need to do via the api I'm just not sure how/I haven't figured it out yet

FSXManu

12
Bugs and Issues / Unique constraint violated
« on: March 08, 2022, 07:59:22 pm »
Hi

I got a problem that when I want to create a Class or Package or anything I get an error saying:

OraOLEDB [0x80040e2f]
ORA-00001: unique constraint (EAxxx.PK_OBJECT) violated


It doesn't matter if I try to do it via the EA UI or via the EA API.

I've read in a thread that an Oracle DB for EA is bad. While that may be true I just got into this ongoing project and we can't change that atm so it's not an option to switch to MSSQL or anything else.

regards,
FSXManu

13
An image can never be an element.

q.

I found a thread from 2014 in which you answered with the steps one needs to do.
I wonder if you ever did it since then or tested it. Sorry I'm completely new to this.

https://www.sparxsystems.com/forums/smf/index.php?topic=5373.0


14
An image can never be an element.

q.

Ah okay. Sorry did some digging I think it's like Class->SubElement->Statechart/Diagram->image artifact
Does that make more sense?

15
What exactly do you mean by "create Image/png object"?

Can you describe what you do manually to create that in EA?

Geert

Sorry I shoul've clarified it a bit better. It should look like in the screenshot below:
So the structure in EA would look something like this:
Packacke
--Class
----StateMachine
------Artifact Image (this is the png image)

I especially struggle with the AddNew method because I can't pass the Image correctly

Pages: [1] 2