Hi Daril
Thanks as always,
This now works 100%
I am not sure if it is the most efficient way to do it, but it works and does what I want and does not blow up
So there appeared
-
Adding relationships to a shape for which the workspace was not setmodified to true caused issues
-
Using Substring multiple time vs once and using variable caused issue
This is my final Code
Thanks Again
function CreateCopyShape(WorkSpaceMain, WorkSpace, Object, WSType) {
var k, ObjectShape, MainObjectShape;
ObjectShape **=** WorkSpace.NewWorkSpaceShape(WSType, Object);
**for** (k **=**
0; k < WorkSpaceMain.ShapeList.Count; k**++**) {
MainObjectShape **=** WorkSpaceMain.ShapeList.GetObject(k);
**if** ((MainObjectShape.ObjectType **==** WSType)
&& (MainObjectShape.ParentBaseID **==** ObjectShape.ParentBaseID)) {
ObjectShape.**Left** **=** MainObjectShape.**Left**;
ObjectShape.Top **=** MainObjectShape.Top;
ObjectShape.Width **=** MainObjectShape.Width;
ObjectShape.Height **=** MainObjectShape.Height;
break;
}
}
}
function Main() {
var App **=** System.GetInterface("Application");
var Model **=** App.ActiveModel;
var WorkSpaceActive **=** App.ActiveWorkSpace;
var WorkingWorkspace **=** Model.Workspaces.GetObjectByName(WorkSpaceActive.Name);
var WorkSpaceMain **=** Model.Workspaces.GetObject(0);
var **Log** **=** System.CreateObject("Log");
var i, e, r, Entity, Shape, Entity, Link, ChildEntity, ParentEntity, WLine;
var Ent_Sub, Par_Sub, Child_Sub;
**Log**.Information("Starting Link_Only_My_Entities_To_This_Workspace");
Model.**Lock**();
**for** (i **=**
0; i < Model.Entities.Count; i**++**) {
Entity **=** Model.Entities.GetObject(i);
Ent_Sub **=** Entity.Name.**substring**(0, 4);
**if** (
Ent_Sub **==**
“trps” ||
Ent_Sub **==**
“tgra” ||
Ent_Sub **==**
“taoa”
) {
**if** (WorkingWorkspace.ShapeList.GetObjectByName(Entity.Name) !**=**
null) {
**Log**.Information(Entity.Name **+** " Is Already Found in Workspace");
}
**else** {
**Log**.Information(Entity.Name **+** " Is Not Found in Workspace Adding it");
CreateCopyShape(WorkSpaceMain, WorkingWorkspace, Entity, 2502); **//**ShapeEntity
}
} **//** Entity **If** **Check** Names
} **//** **For** Entities
Model.**UnLock**();
Model.SetModified(**true**);
Model.RefreshModel();
**Log**.Information("Starting Link_Only_My_Relationship_Lines_To_This_Workspace");
Model.**Lock**();
**for** (e **=**
0; e < WorkSpaceActive.ShapeList.Count; e**++**) {
Shape **=** WorkSpaceActive.ShapeList.GetObject(e);
**if** (Shape.ObjectType **==**
-
**//**entity shape on WorkSpaceActive
{
Entity **=** Shape.ParentBase; **for** (r **=**
0; r < Entity.Relations.Count; r**++**) {
Link **=** Entity.Relations.GetObject(r);
ChildEntity **=** Link.ChildEntity;
ParentEntity **=** Link.ParentEntity;
**Log**.Information("ParentEntity="
+ ParentEntity.Name +
" ChildEntity=" + ChildEntity.Name);
Par_Sub **=** ParentEntity.Name.**substring**(0, 4);
Child_Sub **=** ChildEntity.Name.**substring**(0, 4);
**if** ((Par_Sub **==**
“trps” ||
Par_Sub **==**
“tgra” ||
Par_Sub **==**
“taoa”) &&
(Child_Sub **==**
“trps” ||
Child_Sub **==**
“tgra” ||
Child_Sub **==**
“taoa”)
) {
**Log**.Information("This is a Relation that if Missing will be added");
WLine **=** WorkSpaceActive.CreateWorkspaceLineByParentobject(Link, 2504); **//**
Create Relation line
}
**else** {
**Log**.Information("This is a Relation that Will not be Added because either the Parent or Child Tables are not within the Subset of you Tables");
}
}
}
}
Model.**UnLock**();
Model.SetModified(**true**);
Model.RefreshModel();
**Log**.Information("Completed Link_Only_My_Relationship_Lines_To_This_Workspace");
**Log**.Information("Completed Link_Only_My_Entities_To_This_Workspace");
} // Main
Anthony Vitale
From: Daril [mailto:bounce-Daril@toadworld.com]
Sent: Tuesday, December 05, 2017 5:00 AM
Subject: RE: [Toad Data Modeler - Scripting & Customizations Discussion Forum] Hi, I wrote a Macro to add Entities into a Active Workspace that meet a naming criteria, and then add missing relationship lines, And I had to make this 2 seperate macros to get it t…
Reply by Daril
Hi Anthony,
if you want mark model as modified (so save model icon will be enabled) please call
Model.SetModified(true);
To memory error. I’m not sure how substring method works with string that is shorter than 4 in your case. Could you try store substring(0,4) of parent and child entity to variable before if statement and determine that is not problem when child entity has short name (less than 4)? What kind of memory error is it?
Thanks
Daril
To reply, please reply-all to this email.
Stop receiving emails on this subject.
Or
Unsubscribe from Toad Data Modeler - Scripting & Customizations Forum notifications altogether.
Toad Data Modeler - Scripting & Customizations Discussion Forum
Flag
this post as spam/abuse.