// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== // // // Creation Date: 10.May.2002 // // // // // // // getApplicationVersionAsFloat() // // // float : Value containing the major and minor version numbers. // // // Return the application version number as a float value. //

// If you use the "about -version" command you get a string // value containing the application version. Strings of course // may not be used in comparisons like: //

// if ($version > 3.5) { ... }; //

// This procedure will return a float value containing the // major and minor version number. The major version will be // separated from the minor version by a decimal. For example, // 4.0.3 will return a float value of 4.03. // // // if (getApplicationVersionAsFloat() >= 2.5) { // print ("Running version 2.5 or higher\n"); // }; // // // global proc float getApplicationVersionAsFloat() { float $version = 0.0; string $result; string $versionString = `about -version`; // The following regular expression will ensure a string begins // with a digit and strip out any non-numeric characters. You will be // left with a result that looks like the following (where N is // one more digits). // // N // N.N // N.N.N // N.N.N.N // string $regularExpression = "^[0-9]+[.]*[0-9]*[.]*[0-9]*[.]*[0-9]*"; $result = `match $regularExpression $versionString`; if ("" != $result) { // // Determine the major, minor and patch numbers by tokenizing // the string with the period character. // // The first token will become the whole value left of the // decimal point. The remaing tokens will be appended together // to form the fractional part to the right of the decimal. // // For example, N.N.N.N will become N.NNN. // string $tokenArray[]; int $tokenCount; $tokenCount= `tokenize $result "." $tokenArray`; $result = ""; for ($index = 0; $index < $tokenCount; $index++) { $result += $tokenArray[$index]; if ($index == 0 && $tokenCount > 1) { $result += "."; } } $version = $result; } // If the version could not be determined from the version string parsing // then retrieve it from the apiVersion using `about -apiVersion`. // // Note: // The version retrieved from the apiVersion returns only the N.N // (major.minor) version values. // // Recommendation: // If only the major.minor version values are needed, then // consider using `about -apiVersion` directly instead of // getApplicationVersionAsFloat(). See the `about` command for details // on the value returned. // if ($version == 0) { $version = `about -apiVersion` / 100.0; if ($version >= 201800.0) { $version = `trunc ( $version / 100.0)`; } } return $version; }