Toad World® Forums

Is there any method at the workspace/shapelist level which would allow me to derive the Workspace Names from which an Entity is currently Linked to within My Model

Hello

As We Use Multiple Workspaces in order to best create and display ERD’s within our Models, I produce a Report of Entity’s and there attachment to Workspaces (basically 2 Columns, Entity.Name and Workspace.Name)

And I want to list All Entities and the Workspace(s) they are attached to within the Model

So If Table1 is found within All Items as well as Within Workspace1 then the Chart would be

Table | Workspace

Table1 | All Items

Table1 | Workspace1

Etc…

I know I can apply brute force and build Arrays of the entities listed by Workspace and them Basically Join the Arrays as I Iterate All the Arrays and produce the result

But I would Like to know, If I itererate all the Entities of a Model, Is there anyway from the Entity Name or some component of the Entitiy to iterate the workspaces or Direct method to find workspaces by Entity.

This is the Code I have which iterates the workspaces and then the Entities within the Workspaces.

function main()
{
var app = System.GetInterface(‘Application’);
var Model = app.Models.GetObject(0);
var Workspace,i,e;

for (i=0; i<Model.Workspaces.Count; i++) // iterate Workspaces
{
Workspace = Model.Workspaces.GetObject(i);
Log.Information('Workspace = '+Workspace.Name);

for (e=0; e<Workspace.ShapeList.Count; e++) // iterate entities
{
Entity = Model.Entities.GetObjectByName(Workspace.ShapeList.GetObject(e).Name);
Log.Information('Entity.Name = '+Entity.Name);
}
}
}

Please let me know.

Thanks

Anthony Vitale

Hello Anthony,

I understand that you want method “GetWorkSpaceShapeByParentId” of Workspace, that is not exported to scripting, but I can export it for next version.

At this time you can use something like this

function main(){
var Ent = Model.Entities.GetObject(0);
var Workspace;
Log.Information(Ent.Name);
for (i=0; i<Model.Workspaces.Count; i++) // iterate Workspaces
{
Workspace = Model.Workspaces.GetObject(i);
if (Workspace.ShapeList.GetObjectByName(Ent.Name)!=null)
{
Log.Information(Workspace.Name);
}
}
}

But it will not work correctly in all cases. Problem is when on one workspace is more shortucts of same Entity. In this case has shortcuts Name postfix(Number).

Shortcut (Entity shape on workspace) has property ParentBase, that reference to it’s Entity. Entity has not references to it’s shortcuts. So you can use property ParentBase to determine if shortcut is of Entity. This procedure doen’t has problem with more shortcuts of same entity on one workspace, but it will be slowly.

Do you have some performance problem? How big models do you need to iterate?

Daril

Hi Daril

My Model Is Large and Will get Much Larger.

Your Solution above is Ok as I did not about the get by name would work with the Shapelist Workspace.ShapeList.GetObjectByName(Ent.Name)

I will never have more then 1 entity for a workspace (and I understand what you mean).

If you have a Better Method (GetWorkSpaceShapeByParentId) which would cause me not it iterate all Workspaces looking for entity names that would be great in the next release.

But For Now you have been a SAINT and a Good fellow in your help to me.

Thanks

Anthony Vitale