Difference between revisions of "CreateNewObject"

m
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
[[category:Meta-Inference Functions]]
 
[[category:Meta-Inference Functions]]
 +
 +
Normally, you, as a modeler, create new objects by dragginge a new node from the [[Create and edit nodes|Node toolbar]] into a Diagram.
 +
This function lets you write functions or buttons to automate creation of new objects, or an entire module.
  
 
== CreateNewObject(class, inModule'', title, identifier, original'') ==
 
== CreateNewObject(class, inModule'', title, identifier, original'') ==
Creates a new Analytica object in the global namespace and returns a [[handle]] to it.  
+
 
 +
Create a new Analytica object with the specified «class» in the module «inModule», and return a [[handle]] to the new object.
 +
 
 +
Key phrases: Make Object, New Object, Create Object, Make variable, New variable, Create variable
  
 
'''Parameters''':
 
'''Parameters''':
*«class» specifies the type of object, such as Variable, Chance, Index, Module, FormNode, etc.  
+
*«class»: the [[Class]] or type of the new object, such as Variable, Chance, Index, Module, FormNode, etc.  
*«inModule» identifies the module where the object should be placed.
+
*«inModule»: the parent module to contain this object. It tries to position the node in the first available empty space in the diagram for this  module.
*«title» is optional title text.
+
*«title»optional text for the Title attribute of the new object.
*«identifier» is the desired identifier. If an object with that identifier already exists, it will be made unique by adding numbers to the end. If not specified, the «title» or «class» will be used to generate an identifier.
+
*«identifier»: the desired identifier. If that identifier is already in use, it adds digits to the end to make a unique identifier. If not specified, it uses the «title» or «class» to generate an identifier.
*«original» is used when creating an Alias or FormNode, and specifies the original object.
+
*«original»: If «class» is an Alias or FormNode (User input or output), the new object will refer to this original object.
 
 
Because the creation of a new object is a side-effect, it cannot be evaluated from a variable definition, or while a variable is being evaluated. You use it from the [[Typescript Window]] or a button's [[OnClick]] event.
 
  
== Usage ==
+
The creation of a new object is a [[side-effect]] -- i.e. it makes a permanent change to the model -- so you can only use CreateNewObject in a button's [[OnClick]] attribute (or  the [[Typescript Window]]) or a Function called from [[OnClick]]. You cannot use it in the definition of a Variable.
This function is rarely used in models. It is used in advanced situations that implement [[meta-inference]] algorithms, such as algorithms that alter a model and its structure, or which automatically construct a sub-model for a specialized computation, or create "diagrams as drawings" to depict information.
 
  
 
==History==
 
==History==
Introduced in [[Analytica 4.7]].
+
Introduced in [[Analytica 5.0]].
  
 
== See Also ==
 
== See Also ==

Latest revision as of 21:15, 17 April 2023


Normally, you, as a modeler, create new objects by dragginge a new node from the Node toolbar into a Diagram. This function lets you write functions or buttons to automate creation of new objects, or an entire module.

CreateNewObject(class, inModule, title, identifier, original)

Create a new Analytica object with the specified «class» in the module «inModule», and return a handle to the new object.

Key phrases: Make Object, New Object, Create Object, Make variable, New variable, Create variable

Parameters:

  • «class»: the Class or type of the new object, such as Variable, Chance, Index, Module, FormNode, etc.
  • «inModule»: the parent module to contain this object. It tries to position the node in the first available empty space in the diagram for this module.
  • «title»: optional text for the Title attribute of the new object.
  • «identifier»: the desired identifier. If that identifier is already in use, it adds digits to the end to make a unique identifier. If not specified, it uses the «title» or «class» to generate an identifier.
  • «original»: If «class» is an Alias or FormNode (User input or output), the new object will refer to this original object.

The creation of a new object is a side-effect -- i.e. it makes a permanent change to the model -- so you can only use CreateNewObject in a button's OnClick attribute (or the Typescript Window) or a Function called from OnClick. You cannot use it in the definition of a Variable.

History

Introduced in Analytica 5.0.

See Also

Comments


You are not allowed to post comments.