Hi @Dean D,
The issue you're experiencing occurs because enumeration classes defined in a data dictionary are owned exclusively by that dictionary. When the dictionary closes, it clears its enumeration definitions, breaking references in your exported bus structures. So, the solution around this workaround is keeping the data dictionary open when creating and using bus structures:
dd = Simulink.data.dictionary.open('yourDictionary.sldd'); dDataSection = getSection(dd, 'Design Data'); busEntry = getEntry(dDataSection, 'YourBusName'); busObj = getValue(busEntry); emptyStruct = Simulink.Bus.createMATLABStruct(busObj); % Keep dictionary open while using emptyStruct
The dictionary must remain open to maintain enumeration definitions in memory. The other alternative approaches to consider:
If you need standalone files:
1. Export both bus objects AND enumeration class definition files (.m files) together
2.Manually maintain both file sets in your project
If enumerations aren't critical for initialization:
1. Modify bus element data types from enumerations to underlying numeric types (uint8, int32, etc.)
2. Generate structures without enumeration dependencies
Note: This loses type safety
For programmatic workflows:
*Save structures to MAT-files while dictionary is open
*Reopen the dictionary before loading saved structures
Key Points
Enumerations defined in a data dictionary cannot exist independently of that dictionary. Your workflow must account for this dependency - either keep the dictionary loaded or export enumeration definitions separately as .m files alongside your bus objects.
Hope this helps.
References