How to generate a macro for output values?

LeMarc
LeMarc New Altair Community Member
edited November 2024 in Community Q&A
Hi,

I would like to generate a general macro which extracts the output (attribute values) independent of the model. Because dependent on the selected model,each output has a different attribute name. Therefore it makes no sense to generate a macro with the "attribute name" of the output.

However, I have no idea how to create such a macro. Can anybody help? Or is there already an Operator with such a function?

Thank you!

Welcome!

It looks like you're new here. Sign in or register to get started.

Best Answers

  • MartinLiebig
    MartinLiebig
    Altair Employee
    Answer ✓
    Hi @LeMarc ,
    das ist interssanterweise etwas, was nicht mit operatoren geht. Ich habe mich auch schon ein paar mal gefragt warum. Anbei ist Prozess, der Execute Script nutzt um das zu lösen. Das ist mein Workaround für das Problem. Ich hoffe, dass das hilft.

    LG,
    Martin
    Spoiler
    <?xml version="1.0" encoding="UTF-8"?><process version="9.6.000">
      <context>
        <input/>
        <output/>
        <macros/>
      </context>
      <operator activated="true" class="process" compatibility="9.6.000" expanded="true" name="Process">
        <parameter key="logverbosity" value="init"/>
        <parameter key="random_seed" value="2001"/>
        <parameter key="send_mail" value="never"/>
        <parameter key="notification_email" value=""/>
        <parameter key="process_duration_for_mail" value="30"/>
        <parameter key="encoding" value="SYSTEM"/>
        <process expanded="true">
          <operator activated="true" class="retrieve" compatibility="9.6.000" expanded="true" height="68" name="Retrieve Golf" width="90" x="246" y="85">
            <parameter key="repository_entry" value="//Samples/data/Golf"/>
          </operator>
          <operator activated="true" class="execute_script" compatibility="9.6.000" expanded="true" height="82" name="Execute Script" width="90" x="380" y="85">
            <parameter key="script" value="&#10;ExampleSet inputData =(ExampleSet) input[0];&#10;&#10;String labelName = inputData.getAttributes().getLabel().getName();&#10;operator.getProcess()getMacroHandler().addMacro(&quot;macroName&quot;,labelName);&#10;&#10;return inputData;"/>
            <parameter key="standard_imports" value="true"/>
          </operator>
          <connect from_op="Retrieve Golf" from_port="output" to_op="Execute Script" to_port="input 1"/>
          <portSpacing port="source_input 1" spacing="0"/>
          <portSpacing port="sink_result 1" spacing="0"/>
        </process>
      </operator>
    </process>




  • MartinLiebig
    MartinLiebig
    Altair Employee
    Answer ✓
    Hallo @LeMarc,
    dieses kleine script setzt mit dieser Zeile:
    operator.getProcess()getMacroHandler().addMacro("macroName",labelName);
    den Wert des macros macroName auf den namen des Label attributes. du kannst also in allen weiteren operatoren %{macroName} nutzen und wie gewohnt damit arbeiten. Selbstverständlich kannst du auch irgendeinen anderen namen wählen.

    LG,
    Martin

Answers

  • MartinLiebig
    MartinLiebig
    Altair Employee
    Hi,
    so you want to have the name of the label attribute as a macro?
    Best,
    Martin
  • LeMarc
    LeMarc New Altair Community Member
    Danke für die schnelle Antwort @mschmitz.
    Ja genau. Das meine ich.
  • MartinLiebig
    MartinLiebig
    Altair Employee
    Answer ✓
    Hi @LeMarc ,
    das ist interssanterweise etwas, was nicht mit operatoren geht. Ich habe mich auch schon ein paar mal gefragt warum. Anbei ist Prozess, der Execute Script nutzt um das zu lösen. Das ist mein Workaround für das Problem. Ich hoffe, dass das hilft.

    LG,
    Martin
    Spoiler
    <?xml version="1.0" encoding="UTF-8"?><process version="9.6.000">
      <context>
        <input/>
        <output/>
        <macros/>
      </context>
      <operator activated="true" class="process" compatibility="9.6.000" expanded="true" name="Process">
        <parameter key="logverbosity" value="init"/>
        <parameter key="random_seed" value="2001"/>
        <parameter key="send_mail" value="never"/>
        <parameter key="notification_email" value=""/>
        <parameter key="process_duration_for_mail" value="30"/>
        <parameter key="encoding" value="SYSTEM"/>
        <process expanded="true">
          <operator activated="true" class="retrieve" compatibility="9.6.000" expanded="true" height="68" name="Retrieve Golf" width="90" x="246" y="85">
            <parameter key="repository_entry" value="//Samples/data/Golf"/>
          </operator>
          <operator activated="true" class="execute_script" compatibility="9.6.000" expanded="true" height="82" name="Execute Script" width="90" x="380" y="85">
            <parameter key="script" value="&#10;ExampleSet inputData =(ExampleSet) input[0];&#10;&#10;String labelName = inputData.getAttributes().getLabel().getName();&#10;operator.getProcess()getMacroHandler().addMacro(&quot;macroName&quot;,labelName);&#10;&#10;return inputData;"/>
            <parameter key="standard_imports" value="true"/>
          </operator>
          <connect from_op="Retrieve Golf" from_port="output" to_op="Execute Script" to_port="input 1"/>
          <portSpacing port="source_input 1" spacing="0"/>
          <portSpacing port="sink_result 1" spacing="0"/>
        </process>
      </operator>
    </process>




  • LeMarc
    LeMarc New Altair Community Member

    Danke für deinen Lösungsvorschlag! Leider kann ich nicht programmieren und verstehe daher auch nur ungefähr was codiert wurde. 
    Der Name des generierten Attribut soll im nächsten Schritt für den Operator 'Generat Attribute' verwendet werden. Wie wird das denn mit deinem Lösungsvorschlag umgesetzt?
  • MartinLiebig
    MartinLiebig
    Altair Employee
    Answer ✓
    Hallo @LeMarc,
    dieses kleine script setzt mit dieser Zeile:
    operator.getProcess()getMacroHandler().addMacro("macroName",labelName);
    den Wert des macros macroName auf den namen des Label attributes. du kannst also in allen weiteren operatoren %{macroName} nutzen und wie gewohnt damit arbeiten. Selbstverständlich kannst du auch irgendeinen anderen namen wählen.

    LG,
    Martin
  • LeMarc
    LeMarc New Altair Community Member
    Super, Danke @mschmitz für die Erklärung!

Welcome!

It looks like you're new here. Sign in or register to get started.

Welcome!

It looks like you're new here. Sign in or register to get started.