C++ Tools Creating Configs

From The Foundry MODO SDK wiki
Revision as of 17:47, 16 October 2019 by TomDym (Talk | contribs) (The Tool)

Jump to: navigation, search

Generally you want your tool attributes to display in a form for easy reading as well as being able to modify them without going to the view-port. In order to achieve this we can use a config file to tell Modo how are attributes should be display within a form.

In Modo all tools have their properties display by the same form, this is to make it convenient to access the values without having to change the form each time. It achieves this by creating filters for each tool and then only display the attributes associated with that filter. Along with the filter we also need to tell the form how we want our attributes to be displayed.

We can also use forms to implement UI features such as Icon buttons and tool tips and to disable the command based on certain conditions, Ie Tool only active when in polygon mode however these will be covered in the advanced config section.


The Tool

The tool used in this demo uses exactly the same code as the one used by the "Your First Tool in Modo" and can be found in the provided sdk.
The only change made has been to the name of the tool to ensure there are no conflicts.

void initialize()
{
	CLxGenericPolymorph		*srv;
	srv = new CLxPolymorph<BasicTool>;
	srv->AddInterface(new CLxIfc_Tool      <BasicTool>);
	srv->AddInterface(new CLxIfc_ToolModel <BasicTool>);
	srv->AddInterface(new CLxIfc_Attributes<BasicTool>);
	thisModule.AddServer("tool.basicConfig", srv);
}

Config File

Im going to show the whole contents of the config file and then break it down section by section to explain it.

<?xml version="1.0" encoding="UTF-8"?>
<configuration >
  <atom type="Filters">
    <hash type="Preset"
                                        key="BasicTool:filterPreset">
      <atom type="Name">Basic Tool Config</atom>
      <atom type="Category">95043940005:filterCat</atom>
      <list type="Node">1 .group 0 ""</list>
      <list type="Node">1 toolType tool.basicConfig</list>
      <list type="Node">-1 .endgroup </list>
    </hash>
  </atom>

  <atom type="Attributes">
    <hash type="Sheet"
                                        key="BasicTool:sheet">
      <atom type="Label">Basic Tool Config</atom>
      <atom type="ShowLabel">1</atom>
      <atom type="Layout">properties</atom>
      <atom type="Columns">1</atom>
      <atom type="IconMode">text</atom>
      <atom type="IconSize">small</atom>

      <atom type="Filter">BasicTool:filterPreset</atom>
      <hash type="InCategory" key="toolprops:general#head">
        <atom type="Ordinal">100.61</atom>
      </hash>
      <atom type="Group">toolprops/edit</atom>

      <list type="Control" val="cmd user.value basicConfigExample ?">
        <atom type="Label">Example User Value</atom>
        <atom type="Tooltip">A Example User Value</atom>
      </list>
	  
	  <list type="Control" val="cmd tool.attr tool.basicConfig factorX ?">
        <atom type="Label">Factor X</atom>
        <atom type="Tooltip">Factor X</atom>
      </list>
	  
	  <list type="Control" val="cmd tool.attr tool.basicConfig factorY ?">
        <atom type="Label">Factor Y</atom>
        <atom type="Tooltip">Factor Y</atom>
      </list>
  
      
    </hash>
 
  </atom>

  <atom type="UserValues">

    <hash type="Definition" key="basicConfigExample">
      <atom type="Type">boolean</atom>
    </hash>

  </atom>

</configuration>

The filter can be used to control when a form is displayed. They are defined by name, and have various nodes which dictate the rules for when a form should be displayed, in this case it uses the tooltype filter. The tooltype filter chooses which tools attributes to display

 <atom type="Filters">
    <hash type="Preset" key="BasicTool:filterPreset">
      <atom type="Name">Basic Tool Config</atom>
      <atom type="Category">95043940005:filterCat</atom>
      <list type="Node">1 .group 0 ""</list>
      <list type="Node">1 toolType tool.basicConfig</list>
      <list type="Node">-1 .endgroup </list>
    </hash>
  </atom>

The properties form (also known as an attribute sheet) is defined by an Attribute/Sheet hash. Contains the rules about how a sheet should be displayed

 <atom type="Attributes">
    <hash type="Sheet" key="BasicTool:sheet">
      <atom type="Label">Basic Tool Config</atom>
      <atom type="ShowLabel">1</atom>
      <atom type="Layout">properties</atom>
      <atom type="Columns">1</atom>
      <atom type="IconMode">text</atom>
      <atom type="IconSize">small</atom>

      <atom type="Filter">BasicTool:filterPreset</atom>
      <hash type="InCategory" key="toolprops:general#head">
        <atom type="Ordinal">100.61</atom>
      </hash>
      <atom type="Group">toolprops/edit</atom>

The attribute sheet also contains the controls and attributes of our tool, These are generally defined in two ways:

  • User Value
    • User Values are not dynamic attributes of a tool so they are not created within the tool plugin in itself but can be defined by a config and used to provide

information to the tool, such as check box or drop downlist. They do not effect the tool dynamically.

   <list type="Control" val="cmd user.value basicConfigExample ?">
        <atom type="Label">Example User Value</atom>
        <atom type="Tooltip">A Example User Value</atom>
   </list>
  • Dynamic Attributes
    • Here we call the attributes we defined within our tool. The differ from user values in that when we make a change to our dynamic attributes it will atomically update the tool whereas a user value will not. It can be desirably to use either depending on the effect you wish to achieve.
   <list type="Control" val="cmd tool.attr tool.basicConfig factorX ?">
        <atom type="Label">Factor X</atom>
        <atom type="Tooltip">Factor X</atom>
   </list>
	  
   <list type="Control" val="cmd tool.attr tool.basicConfig factorY ?">
        <atom type="Label">Factor Y</atom>
        <atom type="Tooltip">Factor Y</atom>
   </list>

We must define our user values within the config

  • Note - user values are stored in modos main config and must have unique names to avoid conflicts with other kits
   <atom type="UserValues">

       <hash type="Definition" key="basicConfigExample">
         <atom type="Type">boolean</atom>
       </hash>

   </atom>

Usage

To see the config in action you will need to manually add it in modo via the File->Add Config menu.

FootNotes

There are many more aspects to config files that I will eventually cover within the advanced section of config files, this was aimed as a starter to get used to creating forms for tools.