Getting number of selected objects not working in 5.2


I have a JavaScript macro that generates some XML from the current model. The macro either generates the XML for all objects if nothing is selected in the workspace or only for the selected objects.

However after upgrading to 5.2 detecting of the selected objects does not work any longer. Even though nothing is selected “SelectedObjects” returns 1.

The macro looks something like this:

function Main(){
var App = System.GetInterface(“Application”);
var Model = App.ActiveModel;
var WS = App.ActiveWorkSpace;

var form, lblSeparator, txtSeparator, lblQuotations, txtQuotations;

form = System.CreateForm(‘Form’,‘Generate ChangeSet’, 250, 200);
form.ExecuteScriptName = ‘GenerateChangeSet’;
form.ExecuteMethodName = ‘GenerateLB’;
form.CloseAfterExecute = true;

… add some controls to the dialog

if (This.Count > 0) – this always returns 1
lblSelected = form.AddControl(“lblSelectedCount”, 5);
lblSelected.Caption = “Exporting " + This.Count + " objects to change set”;
lblSelected.Left = 8;
lblSelected.Top = 100;

form.RegisterObject(This, ‘SelectedObjects’);
form.RegisterObject(Model, ‘Model’);

function GenerateLB()

var sel = SelectedObjects.Count;

if (sel = 0)
… generate all objects
… generate selected objects

Inside the “generated selected” objects part I have a for loop that calls SelectedObjects.GetObject(i) to retrieve the selected objects and then generates the approriate XML for them. Currently I only check for ObjectType = 2504 (tables) and ObjectType = 2503 (Relationships). The selected ObjectType is 2501 which is apparently the workspace itself.

Has this been changed in 5.2 so that the current workspace is always a “selected object”?


Read, problem understood, I will have this checked and will update you asap!




So there shouldn’t be a problem with any change in TDM, but if (sel = 0) is always true, it should be if (sel == 0) instead.

Should you still face issues with the macro, please send it in PM or attach it here.



It’s the other way round. The number of selected objects is always 1 (the collection of selected objects always contains the Workspace), even if nothing is selected.

The if (sel = 0) was just a typo in my question. I do use (sel == 0) in my real code

OK, can you provide the macro for testing and debugging, please? You can attach it here, send it attached in Private Message or send it to

Thank you!


OK, I have more details:

This behaviour only shows when the macro is invoked from the popup menu. If the macro is invoked from the main menu, the selection is reported correcly.

I have attached a stripped down version of my script that only opens a dialog that shows the number of selected objects. When nothing is selected and this macros is invoked from the main menu it correctly displays: “Selected 0”. When the macro is invoked from the Workspace’s popup menu it shows “Selected 1” even though nothing is selected.

Sorry, forgot to attach the sample package in the previous post. (1.06 KB)

Thanks a lot for the sample, Thomas!

The issue here is that when the macro is executed from the Designer popup menu, from Workspace, then the particular Workspace is in SelectList. It’s done this way in order to be able to state on which WS it was called.

So, ObjectType of PERWorkspace object is 2501 and the condition needs to be altered to find out if only WS is selected or not.

The condition should look like:

((This.Count==0) || ((This.Count == 1) && (This.GetObject(O).ObjectType == 2501)))

Let me know!


Yes, that’s the workaround I implemented now.

I’m pretty sure 5.1 behaved differently though.

Sure, will double-check then.