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,
Will

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():
            get_materials()
            self.frame.rebuild()

        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:
                    materials.append(line)

        # 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.StringField()
                                ui.Label("Atom Percent", width=self.label_width)
                                ui.FloatField()
                                ui.Label("Density (g/cm^3)", width=self.label_width)
                                ui.FloatField()

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
print(nuclide_name.get_value_as_string())
print(atom_percent.get_value_as_float())
1 Like

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