Hey Lars,
First off… creating custom widget objects with the SDK is very tricky. This comes from the fact that this part of the model (especially the `CustomWidgetType` and contents) represent a separate model inside the Mendix model. The SDK does not offer many safety nets here, and – as you already found – might cause problems in Pro when not set up completely.
However, it should be doable. I’ll try to cover all parts (and hope I don’t miss anything, given the complexity of this).
To begin, you’ll need the `WidgetObjectType` that belongs to your object property; assuming you already have the corresponding `WidgetProperty` as `property`, you should be able to retrieve that through `property.type.valueType.objectType`.
To create the new object, it’s best to build it fully before adding it to the list, so using `customwidgets.WidgetObject.create(model)` is preferred. On the resulting object, set the `type` field to the `objectType` from the previous step.
However, now comes the tricky part; as this `WidgetObject` will need to be initialized with all properties and corresponding values. To do so, loop over all properties from the `objectType.propertyTypes`.
For each of those `propertyType` results; create a `customwidgets.WidgetProperty` (in the same way as the object; using `.create(model)`) and set the `type` to the `propertyType`. Next, create a `customwidgets.WidgetValue` (once again, using `.create(model)` and set it’s `type` to `propertyType.valueType`. This value can now be set on the `value` field of the created property.
Finally, you could/should set the value’s value. Which field in `WidgetValue` is correct depends on the `WidgetValueType` inside the `valueType.type` field.
Note:
- `TranslatableString` uses the `translatableValue` field, which Studio Pro might actually expect to be set to a value… so you might need to create a `texts.Text` instance in this field even if you don’t want to set anything for this property type.
- `TextTemplate` uses the `template` field; which probably needs to be set as well for Pro.
- `Action` uses `action`, but that field seems to have a default value at least (being `NoClientAction`), so that should be fine for Pro by default.
All other properties should, I believe, work with whatever the SDK puts in the fields by default.
(edit, I forgot to mention this:) As the last thing; you’ll of course need to add the created object to the `objects` list in the initial widget value
Once again; this whole process is pretty tricky and error-prone. Here be dragons; make sure to back up the project, as it might break in a way that can only be (attempted to) fix in the SDK :).
Best of luck!