pyprt module

class GeneratedModel

The GeneratedModel instance contains the generated 3D geometry. This class is only employed if the com.esri.pyprt.PyEncoder encoder is used in the ModelGenerator instance.

get_attributes() dict

Returns a dictionary with the CGA rule attributes name and value used to generate this model.

Returns:

dict

get_cga_errors() List[str]

Returns a list of the CGA and asset errors messages of this model. The asset error messages additionally contain the key and URI of the asset.

Returns:

List[str]

get_cga_prints() str

Returns a string with all the CGA print outputs of this model.

Returns:

str

get_faces() List[int]

Returns the vertex indices count per face of the generated 3D geometry. If the 'emitGeometry' entry of the encoder options dictionary has been set to False, this function returns an empty vector.

Returns:

List[int]

get_indices() List[int]

Returns the vertex indices of the generated 3D geometry, for all faces. If the 'emitGeometry' entry of the encoder options dictionary has been set to False, this function returns an empty vector.

Returns:

List[int]

get_initial_shape_index() int

Returns the index of the initial shape on which the generated geometry has been built. The ModelGenerator class is instantiated by specifying a list of InitialShape instances. This index indicates the corresponding InitialShape instance of that list.

Returns:

int

get_report() dict

Returns the CGA report of the generated 3D geometry. This report dictionary is empty if the CGA rule file employed does not output any report or if the 'emitReport' entry of the encoder options dictionary has been set to False.

Returns:

dict

get_vertices() List[float]

Returns the generated 3D geometry vertex coordinates as a series of (x, y, z) triplets. Its size is 3 x the number of vertices. If the 'emitGeometry' entry of the encoder options dictionary has been set to False, this function returns an empty vector.

Returns:

List[float]

class InitialShape(*args, **kwargs)

The initial shape corresponds to the geometry on which the CGA rule will be applied.

  1. __init__ (vert_coordinates)

Constructs an InitialShape with one polygon by accepting a list of direct vertex coordinates. The vertex order is expected to be counter-clockwise.

Parameters:

vert_coordinates – List[float]

Example:

shape1 = pyprt.InitialShape([0, 0, 0, 0, 0, 10, 10, 0, 10, 10, 0, 0])

  1. __init__ (vert_coordinates, face_indices, face_count, holes)

Constructs an InitialShape by accepting a list of direct vertex coordinates, a list of the vertex indices for each faces and a list of the indices count per face. The vertex order is expected to be counter-clockwise. The last parameter, holes, is optional and allows defining holes polygons in faces. It is a list of lists, that assign hole-faces to faces. It follows this structure:

[[index-of-face1-with-holes, index-of-hole1-in-face1, index-of-hole2-in-face1,...], ..., [index-of-faceN-with-holes, index-of-hole1-in-faceN, index-of-hole2-in-faceN, ...]]

Holes must have the opposite vertex-ordering as the encircling face.

Parameters:
  • vert_coordinates – List[float]

  • face_indices – List[int]

  • face_count – List[int]

  • holes – List[List[int]]

Examples:
shape_without_holes =

pyprt.InitialShape([0, 0, 0, 0, 0, 10, 10, 0, 10, 10, 0, 0], [0, 1, 2, 3], [4])

shape_with_hole =

pyprt.InitialShape([0, 0, 0, 0, 0, 10, 10, 0, 10, 10, 0, 0, 2, 0, 2, 8, 0, 8, 2, 0, 8], [0, 1, 2, 3, 4, 5, 6], [4, 3], [[0, 1]])

  1. __init__ (init_shape_path)

Constructs an InitialShape by accepting the path to a shape file. This can be an OBJ file, Collada, etc. A list of supported file formats can be found at PRT geometry encoders.

As the given asset might reference arbitrary other files (e.g. textures), PyPRT employs a heuristic to recursively search the subtree rooted at the containing directory of the asset path. By default the recursion limit is set to 0, i.e. it will only scan the directory of the asset path. The maximum recursion depth is 255.

Parameters:
  • initial_shape_path – str

  • max_dir_recursion_depth – int

Example:

shape3 = pyprt.InitialShape(os.path.join(os.getcwd(), 'myInitialShape.obj'), 2)

get_face_counts_count() int

Returns the number of faces of the initial shape, only if the InitialShape has been initialized from a list of vertex coordinates.

Returns:

int

get_index_count() int

Returns the length of the vector containing the vertex indices of the initial shape, only if the InitialShape has been initialized from a list of vertex coordinates.

Returns:

int

get_path() str

Returns the initial shape file path, if the InitialShape has been initialized from a file. Empty otherwise.

Returns:

str

get_vertex_count() int

Returns the number of vertex coordinates of the initial shape, only if the InitialShape has been initialized from a list of vertex coordinates.

Returns:

int

class ModelGenerator(init_shapes)

The ModelGenerator class will host the data required to procedurally generate the 3D model on a given initial shape.

The ModelGenerator constructor takes a list of InitialShape instances as parameter.

Parameters:

init_shapes – List[InitialShape]

generate_model(*args, **kwargs) List[GeneratedModel]

This function does the procedural generation of the models. It outputs a list of GeneratedModel instances. You need to provide one shape attribute dictionary per initial shape or one dictionary that will be applied to all initial shapes. The shape attribute dictionary only contains either string, float or bool values, except the 'seed' value, which has to be an integer (default value equals to 0). The 'shapeName' is another non-mandatory entry (default value equals to “InitialShape”). In addition to the seed and the shape name keys, the shape attribute dictionary will contain the CGA input attributes specific to the CGA file you are using (use the get_rpk_attributes_info function to know these input attributes). Concerning the encoder, you can use the 'com.esri.pyprt.PyEncoder' or any other geometry encoder. The PyEncoder has these options: 'emitGeometry', 'emitReport' and 'triangulate' whose value is a boolean. The complete list of the other geometry encoders can be found here. In case you are using another geometry encoder than the PyEncoder, you can add an 'outputPath' entry to the shape attribute dictionary to specify where the generated 3D geometry will be outputted. In this case, the return value of this generate_model function will be an empty list.

Parameters:
  • shape_attributes – List[dict]

  • rule_package_path – str

  • geometry_encoder – str

  • encoder_options – dict

Returns:

List[GeneratedModel]

Example:

m = pyprt.ModelGenerator([shape1, shape2])

rpk = os.path.join(os.getcwd(), 'extrusion_rule.rpk')

attrs1 = {'shapeName': 'myShape1', 'seed': 555, 'minBuildingHeight': 30.0}

attrs2 = {'shapeName': 'myShape2', 'seed': 777, 'minBuildingHeight': 25.0}

models1 = m.generate_model([attrs1, attrs2], rpk, 'com.esri.pyprt.PyEncoder', {'emitReport': True, 'emitGeometry': True})

get_api_version() list

Returns a list with the PRT API version components (major, minor, build).

get_rpk_attributes_info(rule_package_path) dict

This function returns the CGA rule attributes name and value type for the specified rule package path as well as a list of the attributes annotations (annotation name, key(s) and value(s)). In case of an unnamed annotation parameter, its key is equal to '#NULL#', which can be read using the pyprt.NO_KEY constant.

Returns:

dict

initialize_prt()

Initialization of PRT. PyPRT functionalities are blocked until the initialization is done.

is_prt_initialized() bool

This function returns True if PRT is initialized, False otherwise.

Returns:

bool

shutdown_prt()

Shutdown of PRT. The PRT initialization process can be done only once per session/script. Thus, initialize_prt() cannot be called after shutdown_prt().