Hi Guys
I have a Need to have a Macro which adds Entities to an active workspace which match a naming criteria, and then add missing relationship lines to the workspace in which the parent/child tables also match a naming criteria.
What you see below as 2 macros I tried to make a single macro but found that I would get memory exceptions and it would blow up My Toad Process.
What I discovered is that the 1st macro, when it adds entities to a workspace, even though I am performing a RefreshModel, does not mark the workspace as having been updated and as such does not allow for save without me having to manually change something in the workspace.
So In Order for this to work even as 2 macros, I need to
- Run this macro, And when It completes, I then need to move an entity or do something on the workspace manually which then enables the Save and I can Save the model. If I do not do that then if I exit toad no changes are saved
//Macro to add entities to active workspace that start with specific characters
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, Entity, Shape, Entity, Link, ChildEntity, ParentEntity, WLine;**
if (Model == null) {
** Log.Information(“You Must have a Model Open to Run This Macro\nThe Process Is Ending Unsuccessfully”);**
** return;**
** } // Model == null**
if (WorkSpaceActive == null) {
** Log.Information(“You Must have a Model Open to Run This Macro\nThe Process Is Ending Unsuccessfully”);**
** return;**
** } // WorkSpaceActive == null**
Log.Information(“Starting SME_Link_Only_My_Entities_To_This_Workspace”);
Model.Lock();
** for (i = 0; i < Model.Entities.Count; i++) {**
Entity = Model.Entities.GetObject(i);
** if (**
** Entity.Name.substring(0, 4) == “trps” ||**
** Entity.Name.substring(0, 4) == “tgra” ||**
** Entity.Name.substring(0, 4) == “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.RefreshModel();**
** Log.Information(“Completed SME_Link_Only_My_Entities_To_This_Workspace”);**
} // Main
2) Then After I save the Model I can Run this macro to add the missing relationship lines. This appears to behave differently as when it runs if it actually adds New RElationships It does enable the Save.of the model without subsequent need for me to change something manually
//Macro to add missing relationship lines to active workspace that Have Parent and Child Tables whichstart with specific characters
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, Entity, Shape, Entity, Link, ChildEntity, ParentEntity, WLine;***
if (Model == null) {
- ** Log.Information(“You Must have a Model Open to Run This Macro\nThe Process Is Ending Unsuccessfully”);***
- ** return;***
- ** } // Model == null***
if (WorkSpaceActive == null) {
-
** Log.Information(“You Must have a Model Open to Run This Macro\nThe Process Is Ending Unsuccessfully”);***
-
** return;***
-
** } // WorkSpaceActive == null***
-
** Log.Information(“Starting SME_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 == 2502) //entity shape on WorkSpaceActive***
-
** {***
-
** Entity = Shape.ParentBase;***
-
** for (r = 0; r < Entity.Relations.Count; r++) {***
-
** Link = Entity.Relations.GetObject®;***
ChildEntity = Link.ChildEntity;
- ** ParentEntity = Link.ParentEntity;***
Log.Information(“ParentEntity=” + ParentEntity.Name + " ChildEntity=" + ChildEntity.Name);
if (ParentEntity.Name.substring(0, 4) == “trps” ||
-
** ParentEntity.Name.substring(0, 4) == “tgra” ||***
-
** ParentEntity.Name.substring(0, 4) == “taoa”***
-
** ) {***
-
** if (ChildEntity.Name.substring(0, 4) == “trps” ||***
-
** ChildEntity.Name.substring(0, 4) == “tgra” ||***
-
** ChildEntity.Name.substring(0, 4) == “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”);***
-
** }***
-
** }***
-
** 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.RefreshModel();***
-
** Log.Information(“Completed SME_Link_Only_My_Relationship_Lines_To_This_Workspace”);***
} // Main
- Finally, You see 2 If statements in the macro above which I should have been able to make into 1 if statement with the use of bracketts and the &&, however when I use && in this IF statement I get a memory error and Toad blows up.
So this
if (ParentEntity.Name.substring(0, 4) == “trps” ||
ParentEntity.Name.substring(0, 4) == “tgra” ||
ParentEntity.Name.substring(0, 4) == "taoa"
) {
if (ChildEntity.Name.substring(0, 4) == “trps” ||
ChildEntity.Name.substring(0, 4) == “tgra” ||
ChildEntity.Name.substring(0, 4) == "taoa"
) {
Should have been allowed to be this
***if ( (ParentEntity.Name.substring(0, 4) == “trps” || ******ParentEntity.Name.substring(0, 4) == “tgra” || ***ParentEntity.Name.substring(0, 4) == “taoa” ) &&
***(ChildEntity.Name.substring(0, 4) == “trps” || ******ChildEntity.Name.substring(0, 4) == “tgra” || ******ChildEntity.Name.substring(0, 4) == “taoa” ***) )
But when i use the && above I get a memory error.
Do you guys see anything I did wrong as I would love it if it was a single Macro with the && instead of 2 macros with a manual Change and then Save in the middle.
Thanks
Anthony Vitale