twitter youtube facebook linkedin email

IN THE PIPES

How to extract part of one property into another property

Dan Scales
July 16, 2015

Imagine you have a property that contains a data string, and you need to extract a section of the data into a new property.

How do you do it without having to manually enter the data into the new property?

It can be done by using the Substring function of the PLANTDEFINECALCPROPERTIES command:

So for example, you have a 6 digit property called TagCode for hand valves that includes a text prefix followed by a hyphen and then a number (eg, AA-101) and you would like to extract the number (101) into a new property without including the text prefix.

This can be achieved using the following syntax "Substring(TagCode,3,3)":

PlantDefineCalcProperties

The resulting calculated property, is a new property, called TagAnno that only includes the last 3 digits from the TagCode property:

Result

 

  • Featured Links

    Dan Scales

    Dan studied Construction at Sheffield Hallam University and Building Surveying at Heriot Watt University in Edinburgh. Joining Autodesk in 2000, Dan has provided support for a wide variety of Autodesk products and has been supporting Plant and P&ID since the very first releases. Prior to joining Autodesk, Dan gained experience working as a design draftsman for a number of consulting engineers in and around Edinburgh. Outside of work Dan enjoys riding motorcycles, road bikes and mountain bikes.

    3 Comments

    View by:
    Most Recent Oldest
    1. AvatarAndy Davis

      May I emphasise that this only works where the position of the 3 digits is fixed.
      It is not possible to return the last 3 digits of a variable length string as there is no function available to determine the length of the string.

    2. Dan ScalesDan Scales

      Thanks for commenting Peter.
      The example shown was specifically for extracting the last 3 characters from a 6 character long property.
      If the property contains more or less characters then the syntax will of course need to be modified accordingly.

    3. AvatarPeter Quinn

      I hate to be pedantic, but this is programming and details matter.
      Your calculated property does not always include the last 3 characters of the TagCode. It contains 3 chars starting with the 4th digit. 3 means the 4th char not the 3rd because you use a 0 to get the first char. I don’t know this for sure, but it looks like it based on your example.
      If your strings are always 6 characters long, it works out the same. If your strings are 7 characters or longer, it won’t give you the last 3.

    '