Difference between revisions of "ScanAttFromModelFile"

 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
''new to [[Analytica 4.4]]''
+
[[Category: Analytica Decision Engine]]
  
= ScanAttFromModelFile(filename,attribute) =
+
== ScanAttFromModelFile(filename, attribute) ==
 
+
This extracts the indicated top-level model «attribute» from an Analytica model file. For example, it can be used to peek at the model description attribute, model author, model title, etc.   
This extracts the indicated top-level model «attribute» from an Analytica model file. For example, it can be used to peek at the model description attribute, model author, model title, etc.   
 
  
 
No changes are made in memory, nothing is loaded, and nothing in the model file is evaluated or executed.  The scan of the file stops as soon as the top level attributes are found, and hence is very quick even for extremely large model files.
 
No changes are made in memory, nothing is loaded, and nothing in the model file is evaluated or executed.  The scan of the file stops as soon as the top level attributes are found, and hence is very quick even for extremely large model files.
Line 9: Line 8:
 
The file may be in standard [[Typescript]] format, in Analytica XML model format, or an obfuscated format.   
 
The file may be in standard [[Typescript]] format, in Analytica XML model format, or an obfuscated format.   
  
= Purpose =
+
== Purpose ==
 +
The function exists primarily for use by programs that use [[Analytica Decision Engine]] (ADE) to manage a set of models.  For example, when you upload a model file to the [[Analytica Cloud Player]], ACP's directory listing displays the model's title and author, and tooltips show the model description, e.g.:
  
The function exists primary for use by programs that use [[ADE]] to manage a set of models.  For example, when you upload a model file to the [[Analytica Cloud Player]], ACP's directory listing displays the model's title and author, and tooltips show the model description, e.g.:
+
:[[image:ACP Directory Listing.png]]
 
 
[[image:ACP Directory Listing.png]]
 
  
 
To generate this listing, ACP needs to peek at the model's top-level attributes.  This could be done by opening the model in ADE, but that would involve reading the entire model into memory, parsing the entire thing, and even evaluating index nodes, all of which could take many minutes for certain huge models.  By using [[ScanAttFromModelFile]], these attribute values can be retrieved in milliseconds.
 
To generate this listing, ACP needs to peek at the model's top-level attributes.  This could be done by opening the model in ADE, but that would involve reading the entire model into memory, parsing the entire thing, and even evaluating index nodes, all of which could take many minutes for certain huge models.  By using [[ScanAttFromModelFile]], these attribute values can be retrieved in milliseconds.
  
= Examples =
+
== Examples ==
 +
:<code>Index Attrib := ['Identifier', 'Class', 'Title', 'Description', 'Author'] Do</code>
 +
::<code>ScanAttFromModelFile("C:\Program Files\Lumina\Analytica 4.4\Business Examples\Market Model.ana", Attrib) &rarr;</code>
 +
:[[image:ScanAttFromModelFile_result.png]]
  
:[[Index]] Attrib := ['Identifier','Class','Title','Description','Author'] Do
+
=== ADE Example from C# ===
::[[ScanAttFromModelFile]]("C:\Program Files\Lumina\Analytica 4.4\Business Examples\Market Model.ana",Attrib) &rarr;
+
<pre style="background:white; border:white; margin-left: 1em;">
:::[[image:ScanAttFromModelFile_result.png]]
+
  CAEngine ade = new CAEngineClass();
 
+
  CAObject obj = ade.Get("Object");      // Any existing object will do
== ADE Example from C# ==
+
  string expr = "Index Attrib:= ['Identifier', 'Class', 'Title', 'Description', 'Author'] Do ScanAttFromModelFile(filename, Attrib)";
 
+
  CATable attVals = obj.CAObject::Evaluate(expr);
  [[CAEngine]] ade = new CAEngineClass();
+
  if (ade.ErrorCode != 0) {
  [[CAObject]] obj = ade.[[CAEngine::Get|Get]]("Object");      // Any existing object will do
+
   // report error from ade.OutputBuffer
  string expr = "[[Index]] Attrib:= ['Identifier','Class','Title','Description','Author'] Do [[ScanAttFromModelFile]](filename,Attrib)";
 
  [[CATable]] attVals = obj.[[CAObject::Evaluate]](expr);
 
  if (ade.[[CAEngine::ErrorCode|ErrorCode]] != 0) {
 
   // report error from ade.[[CAEngine::OutputBuffer|OutputBuffer]]
 
 
  } else {
 
  } else {
   string identifier = attVals.[[CATable::GetDataByLabels|GetDataByLabels]]("Identifier");
+
   string identifier = attVals.GetDataByLabels("Identifier");
   string title      = attVals.[[CATable::GetDataByLabels|GetDataByLabels]]("Title");
+
   string title      = attVals.GetDataByLabels("Title");
   string description= attVals.[[CATable::GetDataByLabels|GetDataByLabels]]("Description");
+
   string description= attVals.GetDataByLabels("Description");
   string author    = attVals.[[CATable::GetDataByLabels|GetDataByLabels]]("Author");
+
   string author    = attVals.GetDataByLabels("Author");
 
  }
 
  }
 +
</pre>
 +
==History==
 +
Introduced in [[Analytica 4.4]].
  
= See Also =
+
== See Also ==
 
+
* [[CAEngine]]
 +
* [[CAEngine::ErrorCode]]
 +
* [[CAEngine::Get]]
 +
* [[CAEngine::OutputBuffer]]
 +
* [[CAObject]]
 +
* [[CAObject::Evaluate]]
 +
* [[CATable]]
 +
* [[CATable::GetDataByLabels]]
 
* [[Analytica Decision Engine]]
 
* [[Analytica Decision Engine]]
 
* [[ReadTextFile]]
 
* [[ReadTextFile]]
 
* [[Analytica Cloud Player]]
 
* [[Analytica Cloud Player]]

Latest revision as of 01:48, 10 February 2016


ScanAttFromModelFile(filename, attribute)

This extracts the indicated top-level model «attribute» from an Analytica model file. For example, it can be used to peek at the model description attribute, model author, model title, etc.

No changes are made in memory, nothing is loaded, and nothing in the model file is evaluated or executed. The scan of the file stops as soon as the top level attributes are found, and hence is very quick even for extremely large model files.

The file may be in standard Typescript format, in Analytica XML model format, or an obfuscated format.

Purpose

The function exists primarily for use by programs that use Analytica Decision Engine (ADE) to manage a set of models. For example, when you upload a model file to the Analytica Cloud Player, ACP's directory listing displays the model's title and author, and tooltips show the model description, e.g.:

ACP Directory Listing.png

To generate this listing, ACP needs to peek at the model's top-level attributes. This could be done by opening the model in ADE, but that would involve reading the entire model into memory, parsing the entire thing, and even evaluating index nodes, all of which could take many minutes for certain huge models. By using ScanAttFromModelFile, these attribute values can be retrieved in milliseconds.

Examples

Index Attrib := ['Identifier', 'Class', 'Title', 'Description', 'Author'] Do
ScanAttFromModelFile("C:\Program Files\Lumina\Analytica 4.4\Business Examples\Market Model.ana", Attrib) →
ScanAttFromModelFile result.png

ADE Example from C#

 CAEngine ade = new CAEngineClass();
 CAObject obj = ade.Get("Object");      // Any existing object will do
 string expr = "Index Attrib:= ['Identifier', 'Class', 'Title', 'Description', 'Author'] Do ScanAttFromModelFile(filename, Attrib)";
 CATable attVals = obj.CAObject::Evaluate(expr);
 if (ade.ErrorCode != 0) {
   // report error from ade.OutputBuffer
 } else {
   string identifier = attVals.GetDataByLabels("Identifier");
   string title      = attVals.GetDataByLabels("Title");
   string description= attVals.GetDataByLabels("Description");
   string author     = attVals.GetDataByLabels("Author");
 }

History

Introduced in Analytica 4.4.

See Also

Comments


You are not allowed to post comments.