question

Li ze avatar image
0 Likes"
Li ze asked Li ze edited

How to list only user-created objects in the model?

When I use forobjecttreeunder Command, it lists all subnode's name under Model.

forobjecttreeunder(model())
{
     pt(a.name); pr();
}

It's a little bit confusion in the lastest version cause all subnodes in tool are printed as well.

How to list only user-created objects?

微信截图-20221101110133.png


I tried the following code:

forobjecttreeunder(model())
{
     if(isclasstype(a,CLASSTYPE_FLEXSIMOBJECT)) 
         print(a.name);      
}

but the list still shows some objects that were not created by me.

微信截图-20221101112749.png

Is there a good way to list only user-created objects in the model?

How to list only user-created objects in the model_v2022.1.fsm

FlexSim 22.1.2
listobjectcountprintuser-created
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Arun Kr avatar image
1 Like"
Arun Kr answered Li ze edited

You can use the Objects() table to list them in your output console or clone to a table.

Here's a simple example.

Table Objects  = Table.query("SELECT * FROM Objects()"); // creates queried table 

int i =2;
while(i<=Objects.numRows)
{
Object ModelObject = Objects[i][1];
print(ModelObject.name);
i++;
}

Furthermore, you can also customize the query to list the objects as per your requirements.

It will be helpful to you if you read the property table documentation to have a deeper understanding.

Without writing code, you can use the property table itself. All the objects created in the model can be brought to the property table and their attributes can be added as fields.

1667293404144.png

You can also SQL query a property table in your code.propertytable.fsm

Regards,

Arun KR


1667293404144.png (86.5 KiB)
propertytable.fsm (33.4 KiB)
· 3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Li ze avatar image Li ze commented ·

Pretty awesome solution!

Thanks very much!

Is there any more details about Objects()?

0 Likes 0 ·
Arun Kr avatar image Arun Kr Li ze commented ·

In the property table doc, under Using the Objects() Table heading you will find some more.

0 Likes 0 ·
Li ze avatar image Li ze Arun Kr commented ·

Thanks a million! I got it.

0 Likes 0 ·