user2215426
user2215426

Reputation:

Simulink: Delete all blocks from subsystem through the mask

There is a subsystem in my model called 'addBlock'. Inside it, I generate InPorts during Mask Initialization based on the number of inputs that the user specifies. For example, if the user says there are going to be six blocks connecting to this subsystem, I generate 6 input ports.

Now, say I specified six inputs. The first time I double click the block and specify this it creates 6 inputs. However, if I double click the mask again and hit OK, it creates 6 more inputs numbered 7 through 12.

What I would thus like to do is to delete everything within the subsystem every time I open the mask and start creating blocks from scratch. Is there any way of getting a list of every block that exists within a subsystem?

Thanks in advance.

Upvotes: 1

Views: 1594

Answers (1)

user2215426
user2215426

Reputation:

I found the answer for this, in case anyone in the future looks it up. The method is to use

Simulink.SubSystem.deleteContents(gcb);

The gcb bit returns the name of the current block, which would be the block you want anyway because you're in that block's mask. Also, note the different camelCases. The solution is a bit inelegant because the whole subsystem needs to be created from scratch, but it does the job.

Upvotes: 1

Related Questions