Skip to content

Include parameter

Within a .pyp file it is possible to include the parameters of another .pyp file using the #include directive. A typical use case for that can be e.g., to include:

  • files with general PythonPart parameter
  • files with parameter blocks for indexing

into the current .pyp file. The use of the #include directive allows to define these parameters only once. This avoids a lot of typing and simplifies the modification of the pyp file. Here is how the general form of the statement look like:

Syntax
<Page>
    <Name>FirstPage</Name>
    <Text>Page text 1</Text>
    <TextId>1001</TextId>

    <!--(1)!-->#include _file_name;index1,text1;index2,text2;…|LanguageFile=IncludeParameter_incpyp

    <Parameter>
        </Parameter>
</Page>
  1. Note, that the #include statement must be added to the <Page> tag of the .pyp file.
Variable Definition
_file_name Path and name of the file to include. The path can be a relative path related to the current .pyp file or with a leading etc\, std\, usr\ or prj\ to make it globally a standard Allplan path.
index... Index of the parameter which will be added as suffix to the names (defined in <Name> tag) of all parameters in the source file. The value can be a string, a single number or an index range like 2-4.
text... Text, which will replace the # placeholder in all existing <Text> tags from the source file. The text can be a text ID like 1002. In case of an index range like 2-4, the index replaces the #.
LanguageFile=... Definition of the language file for the <TextId> tags from the include file. The path can be defined locally to the current pyp file or with a leading etc\, std\, usr\ or prj\ to make it globally a standard Allplan path. If the language file is not defined, the text for the IDs is taken from the resource file of the pyp file.

Warning

Note, that the path defined in _file_name remains untouched, when the PythonPart is moved/copied by the user within the Allplan library. In this case the main .pyp file is moved/copied, but the included files not, causing a relative path pointing to nonexistent file. Providing an absolute path with leading etc\, std\, usr\ or prj\ would be a solution.

Note

If the index value is an index range, the index can also be used to replace the # in a <Visible> or <Enable> tag defined like this:

<Visible>CoordCount .gt. #</Visible>

Example

In this example, the source file contains one parameter Length. It is being included using the #include statement into the target file.

<Page>
    <Name>FirstPage</Name>
    <Text>Page text 1</Text>
    <TextId>1001</TextId>

    #include IncludeParameter.incpyp<!--(1)!-->;Left,1002;2-4<!--(2)!-->;Right,1003<!--(3)!-->

    <Parameter>
        </Parameter>
</Page>
  1. The file suffix does not have to be .incpyp. Parameter from regular .pyp files can also be included.
  2. Note, that there is no text specified here, as the index is defined as a range!
  3. With this #include statement we will be including the parameter 5 times in total, with following indexes: Left, 2, 3, 4, Right.
<Parameter>
    <Name>Length</Name>
    <Text>Length #<!--(1)!--></Text>
    <TextId>2000</TextId>
    <Value>0</Value>
    <ValueType>Length</ValueType>
</Parameter>
  1. This placeholder will be replaced with text from the #include statement
<Item>
    <TextId>1002</TextId>
    <Text>links</Text>
</Item>
<Item>
    <TextId>1003</TextId>
    <Text>rechts</Text>
</Item>
<Item>
    <TextId>2000</TextId>
    <Text>Länge #<!--(1)!--></Text>
</Item>
  1. As the string in the <Text> tag in the source .pyp file contains the # placeholder, it is also needs to be specified in here.
<Page>
    <Name>FirstPage</Name>
    <Text>Page text 1</Text>
    <TextId>1001</TextId>

    <Parameter>
      <Name>LengthLeft</Name>
      <Text>Länge links</Text>
      <Value>0</Value>
      <ValueType>Length</ValueType>
    </Parameter>
    <Parameter>
      <Name>Length2</Name>
      <Text>Länge2</Text>
      <Value>0</Value>
      <ValueType>Length</ValueType>
    </Parameter>
    <Parameter>
      <Name>Length3</Name>
      <Text>Länge 3</Text>
      <Value>0</Value>
      <ValueType>Length</ValueType>
    </Parameter>
    <Parameter>
      <Name>Length4</Name>
      <Text>Länge 4</Text>
      <Value>0</Value>
      <ValueType>Length</ValueType>
    </Parameter>
    <Parameter>
      <Name>LengthRight</Name>
      <Text>Länge rechts</Text>
      <Value>0</Value>
      <ValueType>Length</ValueType>
    </Parameter>
</Page>

The use of the include statement is also shown in the example:

  • …\etc\Examples\PythonParts\PaletteExamples\IncludeParameter.pyp
  • …\etc\PythonPartsExampleScripts\PaletteExamples\IncludeParameter.py

References to included parameters

If the source file contains parameters, that refer to another parameter in this file e.g., to control the visibility, we must use the $ placeholder to consider the index in the referred parameter name.

Example

In this example, the source file contains two parameters:

  • Height - a length parameter
  • ShowHeight - a check box, that should control the visibility of the Height parameter

The target file includes the parameter from the source file two times, with different indices: Wall and Beam

<Page>
    <Name>FirstPage</Name>
    <Text>First page</Text>

    #include IncludeParameter.incpyp;Wall,wall;Beam,beam<!--(1)!-->
</Page>
  1. With this #include statement, the parameters from the source file will be included two times in total, each time with a different index.
<Parameter>
    <Name>Height</Name>
    <Text>Height of the #<!--(2)!--></Text>
    <Value>3000</Value>
    <ValueType>Length</ValueType>
    <Visible>ShowHeight$<!--(1)!--></Visible>
</Parameter>
<Parameter>
    <Name>ShowHeight</Name>
    <Text>Show # height</Text>
    <Value>True</Value>
    <ValueType>Checkbox</ValueType>
</Parameter>
  1. This placeholder will be replaced with the string Wall or Beam from the #include statement, creating a reference to a specific parameter as a result
  2. The # placeholder will be replaced with the string wall or beam, creating a specific text in the palette.
<Page>
    <Name>FirstPage</Name>
    <Text>First page</Text>

    <Parameter>
        <Name>HeightWall</Name>
        <Text>Height of the wall</Text>
        <Value>3000</Value>
        <ValueType>Length</ValueType>
        <Visible>ShowHeightWall<!--(1)!--></Visible>
    </Parameter>

    <Parameter>
        <Name>ShowHeightWall</Name>
        <Text>Show wall height</Text>
        <Value>True</Value>
        <ValueType>Checkbox</ValueType>
    </Parameter>

    <Parameter>
        <Name>HeightBeam</Name>
        <Text>Height of the beam</Text>
        <Value>3000</Value>
        <ValueType>Length</ValueType>
        <Visible>ShowHeightBeam<!--(2)!--></Visible>
    </Parameter>

    <Parameter>
        <Name>ShowHeightBeam</Name>
        <Text>Show beam height</Text>
        <Value>True</Value>
        <ValueType>Checkbox</ValueType>
    </Parameter>

</Page>
  1. The $ was replaced with Wall, creating the correct reference to the ShowHeightWall parameter, ensuring the correct visibility behavior of the control.
  2. The $ was replaced with Beam, creating the correct reference to the ShowHeightBeam parameter, ensuring the correct visibility behavior of the control.