How can I retrieve the names of all the blocks in a sim-mechanics model?

I would like to list down all the names of bodies in a simmechanics model. Basically the purpose is to get the names of the block automatically and see if that type of block (component) exists in my database. For example, in a gear assembly, there are several components, for instance, gear1 (driver), gear 2 (driven), revolute and so on. Gear 1 and gear 2 belongs to "gear" category in my database. Now the database will give me corresponding parameters, which needs to be extracted for that particular category. So, for gear category, I need radius of both gears and so on. Is it possible to do such thing? I know how to use get_param, but for this I need to write the name of the block manually. Please help!
Thanks.

 Accepted Answer

NOTE: I am assuming SimMechanics second generation. For first generation, the same stuff below works, but the names are a bit different.
You can use the find_system function... for example, let's say you want the name of all the Solid blocks in a model.
First, manually select a Solid block and get its BlockType :
get_param(gcb,'BlockType')
ans =
SimMechanicsBlock
There's another property which will tell you the "class" of SimMechanics block:
>> get_param(gcb,'ClassName')
ans =
RigidTransform
So, you can use these properties to search your current model (referred to as bdroot , though you can use the actual model name too):
>> allSMBlocks = find_system(bdroot,'BlockType','SimMechanicsBlock')
>> allSolidBlocks = find_system(bdroot,'ClassName','Solid')
This will return to you a cell array of blocks which you can access using, for instance:
>> allSMBlocks{2}
- Sebastian

2 Comments

Hi Sebastian,
Thanks for your answer. I am using first generation. I will try these commands now and will get back to you if in case it does not work. Hope you would be able to help further!
Yes it worked! This was really helpful. Thank you so much.

Sign in to comment.

More Answers (0)

Categories

Find more on Modeling in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!