nxopentse.tools package

Submodules

nxopentse.tools.excel module

nxopentse.tools.excel.hello()

nxopentse.tools.general module

nxopentse.tools.general.color_object(displayable_object: NXOpen.DisplayableObject, color: int = 42) None

Color a displayable object with a specified color.

Parameters:
  • displayable_object (NXOpen.DisplayableObject)) – The displayable object to color.

  • color (int, optional) – The color to apply. Defaults to 42.

nxopentse.tools.general.create_full_path(file_name: str, extension: str = '.unv') str

This function takes a filename and adds the .unv extension and path of the part if not provided by the user. If the fileName contains an extension, this function leaves it untouched, othwerwise adds .unv as extension. If the fileName contains a path, this function leaves it untouched, otherwise adds the path of the BasePart as the path. Undefined behaviour if basePart has not yet been saved (eg FullPath not available)

Parameters:

file_name (str) – The filename with or without path and .unv extension.

Returns:

A string with .unv extension and path of the basePart if the fileName parameter did not include a path.

Return type:

str

nxopentse.tools.general.create_string_attribute(nx_object: NXOpen.NXObject, title: str, value: str, work_part: NXOpen.BasePart = None) None
nxopentse.tools.general.get_expression_by_name(name: str, work_part: NXOpen.Part = None) NXOpen.Expression | None

Get the expression object by it’s name.

Parameters:
  • name (str) – The name of the expression to retrieve, case insensitive

  • work_part (NXOpen.Part, optional) – The part to move the object in. Defaults to the work part.

Returns:

The found expression if exactly one match exists, None if no match is found.

Return type:

NXOpen.Expression or None

Raises:

ValueError – If multiple expressions with the given name are found.

Notes

The search is case-insensitive. The function performs an exact match on the expression name.

nxopentse.tools.general.indentation(level: int) str

Helper method to create indentations (eg tabs) with a given length. Can be used in print strings in a tree like structure

Parameters:

level (int) – The depth of the indentations.

Returns:

The indentation

Return type:

str

Notes

Tested in SC2306

nxopentse.tools.general.move_object_to_layer(object: NXOpen.DisplayableObject, layer: int, work_part: NXOpen.Part = None) None

Move a displayable object to a specified layer.

Parameters:
  • object (NXOpen.DisplayableObject) – The object to move.

  • layer (int) – The layer to move the object to.

  • work_part (NXOpen.Part, optional) – The part to move the object in. Defaults to the work part.

Notes

nxopentse.tools.general.print_component_tree(component: NXOpen.Assemblies.Component, requested_level: int = 0) None

Prints the component tree for the given component to the listing window. Recursive function

Parameters:
  • component (NXOpen.Assemblies.Component) – The component for whch to print the component tree

  • requested_level (int) – Optional parameter used for creating indentations.

Notes

Tested in SC2306

nxopentse.tools.general.print_part_tree(base_part: NXOpen.BasePart, requested_level: int = 0) None

Prints the part tree for the given BasePart to the listing window. Recursive function

Parameters:
  • base_part (NXOpen.BasePart) – The BasePart to print the tree for.

  • requested_level (int) – Optional parameter used for creating indentations.

Notes

Tested in SC2306

nxopentse.tools.general.save_view_to_file(file_path: str) str

Saves the current view of the model to a file in TIFF format.

This function exports the current view of the model to an image file in TIFF format. If the specified file already exists, it is deleted to ensure that the new image overwrites the previous one. The image export options are set to enhance edges, make the background transparent, and save in the TIFF file format.

Parameters:
  • file_name (str) – The full paht of the file to save the image to. File extension will be updated in line with the type.

  • type (NXOpen.Gateway.ImageExportBuilder.FileFormats, optional) – The file format to save the image as. The default is .Tiff.

Returns:

The full path of the saved image file. Note that the file extension is not included in the return value.

Return type:

str

Raises:
  • FileNotFoundError – If the file path is invalid or the file cannot be created.

  • IOError – If an error occurs during the image export process.

Notes

  • The function currently only supports saving images in TIFF format.

  • If the file already exists, it will be deleted and overwritten with the new image.

  • Tested in SC2312. SC2406

  • Errors on a second run “Gateway does not Exist on NXOpen” because of NXOpen.Gateway.ImageExportBuilder.FileFormats.Tiff NXOpen.Gateway.ImageExportBuilder.BackgroundOptions.Transparent

nxopentse.tools.general.show_only(objects: List[NXOpen.DisplayableObject], base_part: NXOpen.BasePart = None) None

Show only the specified objects.

Parameters:

objects (List[NXOpen.DisplayableObject]) – The objects to show.

Notes

Tested in Simcenter 2406

nxopentse.tools.vector_arithmetic module

nxopentse.tools.vector_arithmetic.create_vector(point1: NXOpen.Point | NXOpen.Point3d, point2: NXOpen.Point | NXOpen.Point3d) NXOpen.Vector3d

Create a vector from two points.

Parameters:
  • (Union[NXOpen.Point (point2) – The first point.

  • NXOpen.Point3d]) – The first point.

  • (Union[NXOpen.Point – The second point.

  • NXOpen.Point3d]) – The second point.

Returns:

The vector from vector1 to vector2.

Return type:

NXOpen.Vector3d

Notes

nxopentse.tools.vector_arithmetic.cross_product_vector3d(vector1: NXOpen.Vector3d, vector2: NXOpen.Vector3d) NXOpen.Vector3d

Calculate the cross product of two vectors.

Parameters:
  • (NXOpen.Vector3d) (vector2) – The first vector.

  • (NXOpen.Vector3d) – The second vector.

Returns:

The cross product of the two vectors.

Return type:

NXOpen.Vector3d

Notes

Tested in SC2306

nxopentse.tools.vector_arithmetic.distance_between_points(point1: NXOpen.Point | NXOpen.Point3d, point2: NXOpen.Point | NXOpen.Point3d) float

Calculate the distance between two points.

Parameters:
  • point1 (NXOpen.Point or NXOpen.Point3d) – The first point.

  • point2 (NXOpen.Point or NXOpen.Point3d) – The second point.

Returns:

The distance between the two points.

Return type:

float

Notes

Tested in NX2412

nxopentse.tools.vector_arithmetic.dot_product_vector3d(vector1: NXOpen.Vector3d, vector2: NXOpen.Vector3d) float

Calculate the dot product of two vectors.

Parameters:
  • (NXOpen.Vector3d) (vector2) – The first vector.

  • (NXOpen.Vector3d) – The second vector.

Returns:

The dot product of the two vectors.

Return type:

float

Notes

Tested in SC2306

nxopentse.tools.vector_arithmetic.get_angle_between_vectors(vector1: NXOpen.Vector3d, vector2: NXOpen.Vector3d) float

Calculate the angle between two vectors (radians).

Parameters:
  • (NXOpen.Vector3d) (vector2) – The first vector.

  • (NXOpen.Vector3d) – The second vector.

Returns:

The angle between the two vectors in radians.

Return type:

float

nxopentse.tools.vector_arithmetic.get_closest_point(point: NXOpen.Point | NXOpen.Point3d, points: List[NXOpen.Point] | List[NXOpen.Point3d]) NXOpen.Point | NXOpen.Point3d

Get the point closest to a given point from a list of points.

Parameters:
  • point (NXOpen.Point3d) – The point to get the closest point to.

  • points (List[NXOpen.Point3d]) – The list of points to search

Returns:

The closest point to the given point in the list of points. The type is the same as the type of point in the list.

Return type:

Union[NXOpen.Point, NXOpen.Point3d]

Notes

Should be extended to handle point and point3d iso only point3d Tested in NX2412

Module contents