Assigning categories according to prefixes of entities

Hi all,

I am working with a huge model (about 800 entities) and want to color the entities according to their prefixes, i.e., I want all entities with a given prefix to become red for example. I have figured out that using categories might help for this task. Unfortunately, the items in the Object tab in “Categories Properties” are not listed alphabetically which would be sufficient for my job.

Does anybody know a solution to this problem? I’d appreciate little script or at least the class hierachy and the name of the method to set a category for an entity.


PS: I’m new to JScript and Visual Basic…

Class associations:
Model - Entities
Entity - Category

Model - Categories
Category - Objects

So you can go through your Model and for each Entity with the given prefix you can add a Category like this in JScript:
EntityObject.SetLinkedObject(“Category”, CategoryObject);

Good luck

Hello Norbert,

Just to let you know...

the items in the Object tab in "Categories Properties" are not listed alphabetically.

To list them alphabetically - a new CR has been created. CR # 46 244.

Thanks for your co-operation!



Thank you for your hint, Fero! Unfortunately, I don’t really know how to use it. So I’d like to ask you to correct the following wrong script:

function main(){

var i;
var Ent;

for(i=0; i<Model.Entities.Count; i++)
Ent = Model.Entities.GetObject(i);
if (Ent.Name.substring(0,4) == “pre_”){

Assume there already exists a catgegory called “pre” and the entities I want to add to “pre” have prefixes “pre_”.

I bet, the task is too hard for you.
Show me that I’m wrong


Nice try Norbert!

Actually when you want “link” objects, the first parameter to SetLinkedObject is the Name of the Property in your Ent object. For an Entity it is “Category” not “pre”. It is a custom that all our objects that can hold a Category object have a property called Category.

The second argument when calling SetLinkedObject is the object reference that you want to link.

I’d bet we have no documentation for this handy function released yet. What’s worse it seems we won’t document that function in next official release either. That’s just because of schedule, we didn’t finished it in time. Sorry for the inconvenience

Meanwhile let’s try a text API documentation of a more robust version of SetLinkedObject :

Base::SetLinkedObject(PropertyName, LinkedObject, LinkedObjectPropertyName);
Automatically create links between objects. Links should be created every time when it’s needed for model consistency.

WideString PropertyName;
The Name of the Property where is stored a reference to the LinkedObject.

Dispatch LinkedObject;
An object which should be directly accessible from this object.

WideString LinkedObjectPropertyName
The Name of the Property in the LinkedObject where is stored a reference to this object.

Notice that the third argument can be omited. That will cause the call of the previous version of SetLinkedObject.

Have fun with scripting

Well, to sum my previous message up:

You can try to use
Ent.SetLinkedObject(“Category”, CategoryObject);

If you don’t have the CategoryObject reference yet, you can find it either iterating
the whole Category List like you do with Entities or you can try

If another issue occurs, don’t hesitate to write again!