How to export values from ui fields generated by loops

Hi there,

I am currently trying to integrate a Monte Carlo simulation program with Omniverse utilizing workflows. For this I have a load of data fields in the extension that change depending on the model being used (number of materials or sources etc) these are created using loops to give the correct number of data fields. However I can’t seem to find a way to then extract that information easily to a txt file for use as simulation parameters. Is there any way to easily just read values from the extension or is there a better way of building the extension to enable this?

Many Thanks,

This is how I have built the material properties side - using a txt file that has a list of materials in:

def _build_materials(self):
        # Takes the material.txt file and reads all the material names into the materials list
        def _get_materials_button():

        mat_file_path = f"{paths['output_omni']}{paths['sep']}materials.txt"
        materials = []
        if os.path.exists(mat_file_path):
            with open(mat_file_path) as file:
                for line in file:

        # Build the widgets of the Materials
        with ui.CollapsableFrame("Materials", collapsed = True):
            with ui.VStack(height=0, spacing=SPACING):
                ui.Button("Get Materials", clicked_fn=lambda: _get_materials_button())
                # Uses the materials list to create a stack of materials to edit properties
                for material in materials:
                    with ui.CollapsableFrame(f"{material}", collapsed=True):
                        with ui.VStack(height=0, spacing=SPACING):
                            with ui.HStack():
                                ui.Label("Nuclide Name", width=self.label_width)
                                ui.Label("Atom Percent", width=self.label_width)
                                ui.Label("Density (g/cm^3)", width=self.label_width)

Hi @william.smith-14. The easiest way would be to store model for each field so that you can query the values when you’re ready to process them. Each field has a model object with a similar interface to get the value.

# store the models in variables, dictionary, etc.
nuclide_name = ui.StringField().model
atom_percent = ui.FloatField().model

# later query the values
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.