Main API

Patchwork 3D scripting

class CurrentP3DSession(fallback_port=None)

Bases: p3dsdk._p3d_session.P3DSession

Class that connects to the running Patchwork 3D instance.

If the script is not executed from Patchwork 3D, fallback_port lets you specify a port to connect to. In this case it is equivalent to P3DSession("localhost", fallback_port).

Parameters

fallback_port (int, optional) -- Port to use to connect to Patchwork 3D on localhost when the script is not run from Patchwork 3D.

Raises

P3DError -- If no fallback_port is given and the script is not executed in the Patchwork 3D Python console.

property app

Access to the current Patchwork 3D.

Type

Application, read-only

close()

Close the session.

property data

Access to the current Database opened in Patchwork 3D.

Type

Database, read-only

property host

Host of the session.

Type

str, read-only

property port

TCP port of the session.

Type

int, read-only

class P3DSession(host, port)

Class that manages a scripting session with Patchwork 3D.

Note

If possible use IP address directly for host. This way, it will avoid a hostname lookup and queries will be quicker. For example, instead of connecting to localhost, prefer using 127.0.0.1.

Parameters
  • host (str) -- IP address or hostname of Patchwork 3D instance to connect to.

  • port (int) -- TCP port of Patchwork 3D instance to connect to.

property app

Access to the current Patchwork 3D.

Type

Application, read-only

close()

Close the session.

property data

Access to the current Database opened in Patchwork 3D.

Type

Database, read-only

property host

Host of the session.

Type

str, read-only

property port

TCP port of the session.

Type

int, read-only

Direct access to .p3d file

class P3DFile
classmethod create()

Create a new empty database.

Returns

The newly created database access.

Return type

Database

classmethod open(filename, read_only=False)

Open an existing .p3d database.

Parameters
  • filename (str) -- The database filename to open.

  • read_only (bool, optional) -- Whether to open the database as read-only.

Returns

The opened database access.

Return type

Database

Direct access to .kev file

class KEVFile
classmethod open(filename)

Open an existing .kev file.

Parameters

filename (str) -- The KEV file to open.

Returns

The environment contained in the KEV file.

Return type

Environment

Raises

FileNotFoundError -- If filename can't be opened.

Direct access to .kmt file

class KMTFile
classmethod open(filename)

Open an existing .kmt file.

Parameters

filename (str) -- The KMT file to open.

Returns

The material contained in the KMT file.

Return type

Material

Raises

FileNotFoundError -- If filename can't be opened.