ExpressionCollection Class

class NXOpen.ExpressionCollection

Bases: object

Represents a collection of expressions.

To obtain an instance of this class, refer to NXOpen.BasePart

New in version NX3.0.0.

Methods

Method Description
AskInterpartLhsName Creates the left hand side name for an overriding interpart expression reference.
AskInterpartRhsName Creates the right hand side name for an interpart expression reference.
ChangeInterpartReferences Changes all of the references in the part owning_part from expressions in the part old_part_name to expressions in the part new_part_name.
ChangeInterpartReferencesFor4gd Interface for 4gd
Create Creates an expression
CreateExpression Creates an expression of the specified type.
CreateInterpartExpressionsBuilder Creates interpart expressions.
CreateReplaceExpressionsBuilder Replace expressions.
CreateSuppressByExpressionBuilder Creates a NXOpen.SuppressByExpressionBuilder
CreateSystemExpression Creates a system expression.
CreateSystemExpressionFromReferenceString Creates a system string expression from a reference string in Drafting Note format.
CreateSystemExpressionWithUnits Creates a system expression with units.
CreateWithUnits Creates an expression with units.
Delete Deletes an expression
Edit Edits an expression.
EditWithUnits Edits an expression with units.
ExportToFile Exports the expressions to a text file, or, if ‘file_name’ is None, list the expressions in the listing window.
FindObject Finds the NXOpen.Expression with the given identifier as recorded in a journal.
GetAttributeExpression Get the attribute expression of the specified attribute title/type.
GetInterpartReferences Returns a list of parts that are referenced from expressions in the part owning_part.
GetInterpartReferencesFor4gd Interface for 4gd
GetInterpartReferencesWithDisplayNames Returns a list of parts that are referenced from expressions in the part owning_part.
GetVisibleExpressions Returns an array of visible Number expressions in the part.
ImportFromFile Imports expressions from a file.
RemoveInterpartReferences Removes the interpart references from a part.
Rename Changes the name of the expression.
Replace Replaces references to an expression with another expression.
ReplaceAttributeExpression Replace the attribute expression of the specified attribute title/type.
ReplaceRhsInterpartExpression Replaces the old right hand side interpart expression references with those of the new right hand side interpart expression.
SystemRename Changes the name of the expression without marking system expressions as user expressions.

Enumerations

ExpressionCollectionExportMode Enumeration Indicates the mode for exporting expressions.
ExpressionCollectionImportMode Enumeration Indicates the mode for importing expressions.
ExpressionCollectionSortType Enumeration Indicates the mode for sorting expressions.

Method Detail

AskInterpartLhsName

ExpressionCollection.AskInterpartLhsName

Creates the left hand side name for an overriding interpart expression reference.

For example, if the destination part is A and the source expression is X from part B then NX will create/return the expression for the A::x overrdding interpart expression reference.

Signature AskInterpartLhsName(sourceExpression)

Parameters:sourceExpression (NXOpen.Expression) – expression in source part
Returns:left hand side name
Return type:str

New in version NX10.0.0.

License requirements: None.

AskInterpartRhsName

ExpressionCollection.AskInterpartRhsName

Creates the right hand side name for an interpart expression reference.

For example, if the destination part is A and the source expression is X from part B then NX will create/return the expression for the A::x interpart expression reference.

Signature AskInterpartRhsName(sourceExpression)

Parameters:sourceExpression (NXOpen.Expression) – expression in source part
Returns:right hand side name
Return type:str

New in version NX10.0.0.

License requirements: None.

ChangeInterpartReferences

ExpressionCollection.ChangeInterpartReferences

Overloaded method ChangeInterpartReferences

  • ChangeInterpartReferences(oldPartName, newPartName)
  • ChangeInterpartReferences(oldPartName, newPartName, doUpdate, doChecking)

-------------------------------------

Changes all of the references in the part “owning_part” from expressions in the part “old_part_name” to expressions in the part “new_part_name”.

Signature ChangeInterpartReferences(oldPartName, newPartName)

Parameters:
  • oldPartName (str) – Part name whose references are being replaced
  • newPartName (str) – New part name to reference

New in version NX4.0.0.

License requirements: None.

-------------------------------------

Changes all of the references in the part “owning_part” from expressions in the part “old_part_name” to expressions in the part “new_part_name”.

Signature ChangeInterpartReferences(oldPartName, newPartName, doUpdate, doChecking)

Parameters:
  • oldPartName (str) – Part name whose references are being replaced
  • newPartName (str) – New part name to reference
  • doUpdate (bool) – Do update if true
  • doChecking (bool) – Do checking if true

New in version NX7.5.0.

License requirements: None.

-------------------------------------

ChangeInterpartReferencesFor4gd

ExpressionCollection.ChangeInterpartReferencesFor4gd

Interface for 4gd

Signature ChangeInterpartReferencesFor4gd(targetPartOccTag, oldSourcePartName, newSourcePartOccTag, doUpdate, doChecking)

Parameters:
  • targetPartOccTag (NXOpen.Assemblies.Component) – Part occ of target part
  • oldSourcePartName (str) – Part name whose references are being replaced
  • newSourcePartOccTag (NXOpen.Assemblies.Component) – Part occ of new source part
  • doUpdate (bool) – Do update if true
  • doChecking (bool) – Do checking if true

New in version NX11.0.0.

License requirements: None.

Create

ExpressionCollection.Create

Creates an expression

Signature Create(string)

Parameters:string (str) – the equation for the expression. Must be in the format: name = right_hand_side. For example, “x = 1.2 * y + z”.
Returns:the new expression
Return type:NXOpen.Expression

New in version NX3.0.0.

License requirements: None.

CreateExpression

ExpressionCollection.CreateExpression

Creates an expression of the specified type.

Signature CreateExpression(expressionType, string)

Parameters:
  • expressionType (str) – The type of the expression, such as “Number”, “String”, “Boolean”, “Integer”, “Point” and “Vector”
  • string (str) – the equation for the expression. Must be in the format: name = right_hand_side. For example, “x = 1.2 * y + z”.
Returns:

the new expression

Return type:

NXOpen.Expression

New in version NX5.0.0.

License requirements: None.

CreateInterpartExpressionsBuilder

ExpressionCollection.CreateInterpartExpressionsBuilder

Creates interpart expressions.

Signature CreateInterpartExpressionsBuilder()

Returns:
Return type:NXOpen.InterpartExpressionsBuilder

New in version NX8.5.0.

License requirements: None.

CreateReplaceExpressionsBuilder

ExpressionCollection.CreateReplaceExpressionsBuilder

Replace expressions.

Signature CreateReplaceExpressionsBuilder()

Returns:
Return type:NXOpen.ReplaceExpressionsBuilder

New in version NX10.0.0.

License requirements: None.

CreateSuppressByExpressionBuilder

ExpressionCollection.CreateSuppressByExpressionBuilder

Creates a NXOpen.SuppressByExpressionBuilder

Signature CreateSuppressByExpressionBuilder()

Returns:SuppressByExpressionBuilder object
Return type:NXOpen.SuppressByExpressionBuilder

New in version NX5.0.0.

License requirements: None.

CreateSystemExpression

ExpressionCollection.CreateSystemExpression

Overloaded method CreateSystemExpression

  • CreateSystemExpression(string)
  • CreateSystemExpression(expressionType, string)

-------------------------------------

Creates a system expression. After creating a system expression, you should associate it with an object, such as a sketch dimension. System expressions are deleted when the object they are associated with is deleted.

Signature CreateSystemExpression(string)

Parameters:string (str) – the equation or right-hand-side for the expression. You can specify a name for the equation by providing a string in the format: name = right_hand_side. For example, “x = 1.2 * y + z”. If you do not provide a name, a name will be assigned automatically. For example, if the string is “1.2 * y + z”, a name will be assigned automatically.
Returns:the new expression
Return type:NXOpen.Expression

New in version NX3.0.0.

License requirements: None.

-------------------------------------

Creates a system expression of the specified type. After creating a system expression, you should associate it with an object, such as a sketch dimension. System expressions are deleted when the object they are associated with is deleted.

Signature CreateSystemExpression(expressionType, string)

Parameters:
  • expressionType (str) – The type of the expression, such as “Number”, “String”, “Boolean”, “Integer”, “Point” and “Vector”
  • string (str) – the equation or right-hand-side for the expression. You can specify a name for the equation by providing a string in the format: name = right_hand_side. For example, “x = 1.2 * y + z”. If you do not provide a name, a name will be assigned automatically. For example, if the string is “1.2 * y + z”, a name will be assigned automatically.
Returns:

the new expression

Return type:

NXOpen.Expression

New in version NX5.0.0.

License requirements: None.

-------------------------------------

CreateSystemExpressionFromReferenceString

ExpressionCollection.CreateSystemExpressionFromReferenceString

Creates a system string expression from a reference string in Drafting Note format.

Only expressions (X) and attributes (W) are supported.

Here is how the control character sequences need to be formatted: Expressions - Xm.n<@>exp_name Part Attributes - W<@>attr_title Object Attributes - W!obj_id<@>attr_title

Signature CreateSystemExpressionFromReferenceString(reference)

Parameters:reference (str) – the reference string in Drafting Note format
Returns:the new expression
Return type:NXOpen.Expression

New in version NX7.5.0.

License requirements: None.

CreateSystemExpressionWithUnits

ExpressionCollection.CreateSystemExpressionWithUnits

Creates a system expression with units.

After creating a system expression, you should associate it with an object, such as a sketch dimension. System expressions are deleted when the object they are associated with is deleted.

Signature CreateSystemExpressionWithUnits(string, unitType)

Parameters:
  • string (str) – the equation or right-hand-side for the expression. You can specify a name for the equation by providing a string in the format: name = right_hand_side. For example, “x = 1.2 * y + z”. If you do not provide a name, a name will be assigned automatically. For example, if the string is “1.2 * y + z”, a name will be assigned automatically.
  • unitType (NXOpen.Unit) – units for the expression
Returns:

the new expression

Return type:

NXOpen.Expression

New in version NX4.0.0.

License requirements: None.

CreateWithUnits

ExpressionCollection.CreateWithUnits

Overloaded method CreateWithUnits

  • CreateWithUnits(string, unitType)
  • CreateWithUnits(leftHandSide, rightHandSide, isUserLocked, units)

-------------------------------------

Creates an expression with units.

Signature CreateWithUnits(string, unitType)

Parameters:
  • string (str) – the equation for the expression. Must be in the format: name = right_hand_side. For example, “x = 1.2 * y + z”.
  • unitType (NXOpen.Unit) – units for the expression
Returns:

the new expression

Return type:

NXOpen.Expression

New in version NX4.0.0.

License requirements: None.

-------------------------------------

Delete

ExpressionCollection.Delete

Deletes an expression

Signature Delete(expression)

Parameters:expression (NXOpen.Expression) – The expression to be deleted

New in version NX4.0.0.

License requirements: None.

Edit

ExpressionCollection.Edit

Edits an expression.

Note, there is no difference between this method and editing the expression via NXOpen.Expression.RightHandSide() if the ExpressionCollection is owned by the part that owns the expression.

Signature Edit(expression, newRightHandSide)

Parameters:
  • expression (NXOpen.Expression) – The expression to be edited, Note: if this expression is not owned by the part that owns the ExpressionCollection, a new expression will be created in the part that owns the ExpressionCollection
  • newRightHandSide (str) – What you want to change the expression to

New in version NX3.0.0.

License requirements: None.

EditWithUnits

ExpressionCollection.EditWithUnits

Edits an expression with units.

Changing the units on an existing expression is only allowed when the expression is not referenced yet.

Note, if you do not change the units, there is no difference between this method and editing the expression via NXOpen.Expression.RightHandSide() if the ExpressionCollection is owned by the part that owns the expression.

Signature EditWithUnits(expression, unitType, newRightHandSide)

Parameters:
  • expression (NXOpen.Expression) – The expression to be edited, Note: if this expression is not owned by the part that owns the ExpressionCollection, a new expression will be created in the part that owns the ExpressionCollection
  • unitType (NXOpen.Unit) – units for the expression
  • newRightHandSide (str) – What you want to change the expression to

New in version NX4.0.0.

License requirements: None.

ExportToFile

ExpressionCollection.ExportToFile

Exports the expressions to a text file, or, if ‘file_name’ is None, list the expressions in the listing window.

Throws an exception if there is any error.

NOTE: if the file already exists, an exception is thrown and the file is not overwritten.

Signature ExportToFile(exportMode, fileName, sortType)

Parameters:

New in version NX4.0.0.

License requirements: None.

FindObject

ExpressionCollection.FindObject

Finds the NXOpen.Expression with the given identifier as recorded in a journal.

An object may not return the same value as its JournalIdentifier in different versions of the software. However newer versions of the software should find the same object when FindObject is passed older versions of its journal identifier. In general, this method should not be used in handwritten code and exists to support record and playback of journals.

An exception will be thrown if no object can be found with the given journal identifier.

Signature FindObject(journalIdentifier)

Parameters:journalIdentifier (str) – Identifier to be found
Returns:Expression found
Return type:NXOpen.Expression

New in version NX3.0.0.

License requirements: None.

GetAttributeExpression

ExpressionCollection.GetAttributeExpression

Get the attribute expression of the specified attribute title/type.

Signature GetAttributeExpression(object, title, type, index)

Parameters:
  • object (NXOpen.NXObject) – The object of the attribute
  • title (str) – The title of the attribute
  • type (NXOpen.NXObjectAttributeType) – The type of the attribute
  • index (int) – The array index if the attribute is an array (use -1 otherwise)
Returns:

the attribute expression

Return type:

NXOpen.Expression

New in version NX8.0.0.

License requirements: None.

GetInterpartReferences

ExpressionCollection.GetInterpartReferences

Returns a list of parts that are referenced from expressions in the part “owning_part”.

Signature GetInterpartReferences()

Returns:array of part names
Return type:list of str

New in version NX4.0.0.

License requirements: None.

GetInterpartReferencesFor4gd

ExpressionCollection.GetInterpartReferencesFor4gd

Interface for 4gd

Signature GetInterpartReferencesFor4gd()

Returns:a tuple
Return type:A tuple consisting of (referencedPartNames, referencedDispNames, referencedParts). referencedPartNames is a list of str. array of internal part names referencedDispNames is a list of str. array of display part names referencedParts is a list of NXOpen.NXObject. array of occ parts and part occs

New in version NX11.0.0.

License requirements: None.

GetInterpartReferencesWithDisplayNames

ExpressionCollection.GetInterpartReferencesWithDisplayNames

Returns a list of parts that are referenced from expressions in the part “owning_part”.

Signature GetInterpartReferencesWithDisplayNames()

Returns:a tuple
Return type:A tuple consisting of (referencedPartNames, referencedDispNames) referencedPartNames is a list of str. array of internal part names referencedDispNames is a list of str. array of display part names

New in version NX10.0.0.

License requirements: None.

GetVisibleExpressions

ExpressionCollection.GetVisibleExpressions

Returns an array of visible “Number” expressions in the part.

Signature GetVisibleExpressions()

Returns:array of “Number” expressions
Return type:list of NXOpen.Expression

New in version NX4.0.0.

License requirements: None.

ImportFromFile

ExpressionCollection.ImportFromFile

Imports expressions from a file.

Input a file specification. When calling this method, changes are not applied to the system until Update.DoUpdate() is called.

Signature ImportFromFile(fileName, importMode)

Parameters:
Returns:

a tuple

Return type:

A tuple consisting of (expModified, errorMessages) expModified is a bool. TRUE if any expressions were affected by the import errorMessages is a list of str. translated list of error messages

New in version NX4.0.0.

License requirements: None.

RemoveInterpartReferences

ExpressionCollection.RemoveInterpartReferences

Removes the interpart references from a part.

If a part name is given, then it removes the references to that part. If part_name is None, it removes all references to all parts.

References on the RHS are replaced by a numerical value, References on the LHS are deleted. E.g.

x = comp::len + z –> x = 3 + z

comp::height=5 –> (deleted)

The function returns TRUE is any references were removed, and FALSE otherwise.

Signature RemoveInterpartReferences(partName)

Parameters:partName (str) – Part name to remove references for
Returns:whether any changes were made
Return type:bool

New in version NX4.0.0.

License requirements: None.

Rename

ExpressionCollection.Rename

Changes the name of the expression.

Signature Rename(expression, newName)

Parameters:
  • expression (NXOpen.Expression) – expression to be renamed
  • newName (str) – new name of the expression

New in version NX4.0.0.

License requirements: None.

Replace

ExpressionCollection.Replace

Replaces references to an expression with another expression.

Signature Replace(currentName, replaceName)

Parameters:
  • currentName (str) – current expression name
  • replaceName (str) – replace expression name

New in version NX10.0.0.

License requirements: None.

ReplaceAttributeExpression

ExpressionCollection.ReplaceAttributeExpression

Replace the attribute expression of the specified attribute title/type.

Signature ReplaceAttributeExpression(expression, object, title, type, index)

Parameters:
  • expression (NXOpen.Expression) – the attribute expression
  • object (NXOpen.NXObject) – The object of the attribute
  • title (str) – The title of the attribute
  • type (NXOpen.NXObjectAttributeType) – The type of the attribute
  • index (int) – The array index if the attribute is an array (use -1 otherwise)

New in version NX8.0.0.

License requirements: None.

ReplaceRhsInterpartExpression

ExpressionCollection.ReplaceRhsInterpartExpression

Replaces the old right hand side interpart expression references with those of the new right hand side interpart expression.

For example, replacing x=”A”::x with y=”B”::y with result in right hand interpart expression x=”B”::y and expression y=x.

Signature ReplaceRhsInterpartExpression(oldRhsIpe, newRhsIpe)

Parameters:
  • oldRhsIpe (NXOpen.Expression) – right hand side interpart expression to be replaced
  • newRhsIpe (NXOpen.Expression) – right hand side interpart expression to be replaced with

New in version NX11.0.0.

License requirements: None.

SystemRename

ExpressionCollection.SystemRename

Changes the name of the expression without marking system expressions as user expressions.

Signature SystemRename(expression, newName)

Parameters:
  • expression (NXOpen.Expression) – expression to be renamed
  • newName (str) – new name of the expression

New in version NX6.0.0.

License requirements: None.