aconityAPIfiles package

Submodules

aconityAPIfiles.AconitySTUDIO_client module

class aconityAPIfiles.AconitySTUDIO_client.AconitySTUDIO_client(login_data)

Bases: object

The AconitySTUDIO Python Client. Allows for easy automation and job management.

For example usages, please consult the examples folder in the root directory from this repository.

To create the client call the classmethod create.

change_global_parameter(param, value, check_boundaries=True)

Change a global parameter in the locally saved job and synchronizes this change with the Server Database.

If the parameter may only have values confined in a certain range, the new value will be changed to fit these requirements. (Example: The parameter must lie in the interval [1, 10]. If the attempted change is to set the value to 12 the function sets it to 10.)

Parameters:
  • param (string) – The parameter to be changed. Example: ‘supply_factor’
  • value (int/float/bool) – The new value of the parameter to be changed
  • check_boundaries (bool) – Ignore min and max values of a parameter.

Note: Calling this function does not mean that a running job will be paused and resumed with the updated value.

change_part_parameter(part_id, param, value, laser='*', check_boundaries=True)

Change a part parameter in the locally saved job and synchronizes this change with the Server Database.

If the parameter may only have values confined in a certain range, the new value will be changed to fit these requirements. (Example: The parameter must lie in the interval [1, 10]. If the attempted change is to set the value to 12 the function sets it to 10.)

Note: Calling this function does not mean that a running job will be paused and resumed with the updated value.

Parameters:
  • part_id (int) – The part id to be changed. For example, this number can be seen in the GUI inside the jobs view -> clicking on a part -> expanding the part -> a number within “[ ]” is appearing. Other possibility: In the Script tab -> Init/Resume there are lines like “$p.add(4,2,_modelsection_002_s1_vs)”. part_id -> 4.
  • param (string) – The parameter to be changed. Example: ‘laser_power’
  • value (int/float/bool) – The new value of the parameter to be changed
  • laser (int) – Used to select the scanner. Either ‘*’ (->”Scanner All”) or 1, 2, 3, 4 etc …
  • check_boundaries (bool) – Ignore min and max values of a parameter.
config_exists(config_name=None, config_id=None)

Checks if a config exists.

One can either use the config_name or the config_id as a search parameter (XOR). If this is not done, raises a ValueError.

Parameters:
  • config_name (str) – Name of the config
  • config_id (str) – Id of the config
Return type:

bool

config_has_component(component, config_id=None)

Checks if a config has a certain component.

Parameters:
  • component (string) – The component to be checked.
  • config_id (string) – Config Id. If config_id == None, the client uses its own attribute config_id.
  • config_name (string) – Config Name.
Return type:

bool

config_state(config_id=None)

Returns the current state of the config

Parameters:config_id (str) – Id of the config. If none is given, the client uses its own attribute config_id.
Returns:‘operational’, ‘inactive’, or ‘initialized’
Return type:string
classmethod create(login_data)

Factory class method to initialize a client. Convenient as this function takes care of logging in and creating a websocket connection. It will also set set up a ping, to ensure the connection will not be lost.

Parameters:login_data (dictionary) – required keys are rest_url, ws_url, password and email.

Usage:

login_data = {
    'rest_url' : 'http://192.168.1.1:2000',
    'ws_url' : 'ws://192.168.1.1:2000',
    'email' : 'admin@yourcompany.com',
    'password' : '<password>'
}
client = await AconitySTUDIO_client.create(login_data)
download_chunkwise(url, save_to, chunk_size=1024)
enable_pymongo_database(name='database_test', keep_last=120)

Setup for the Mongodatabase

Parameters:
  • mongodatabase (string) – name of the database
  • keep_last (float) – If larger that zero, automatically delete entries older than keep_last seconds
execute(channel, script, machine_id=None)

Sends scripts (commands) to the WebSocket Server.

Parameters:
  • machine_id (string) – Machine ID
  • channel (string) – currently only “manual” is supported
  • script (string) – The command(s) that the Server executes
get(url, log_level='debug', logger=True, headers={}, verbose=False, timeout=300)

The client sends a get request to the Server. If the response status is != 200, raises a http Exception. If the response status is 200, returns the body of the return json.

Parameters:url (string) – request url, which will get added to self.rest_url. For example, to call the route http://192.168.1.123:9000/machines/functions the url is “machines/functions”.
get_config_id(config_name)

Returns the config_id of the config with the given name.

If it is not unique or no config with the given name is found, raises a ValueError. In this case, start the Browser based GUI AconitySTUDIO and copy the id from the URL and manually set the attribute config_id.

Saves the config_id into self.config_id. Saves the name of the operational config into self.config_name.

Returns:Config ID
Return type:string
get_job_id(job_name)

Get the job id for a given jobname. If the job_name is unique, sets and returns the attribute job_id. If it is not unique or no job with the given name is found, raises a ValueError. In this case, start the Browser based GUI AconitySTUDIO and copy the id from the URL and manually set the attribute machine_id.

Parameters:job_name (string) – jobname
Returns:Job ID
Return type:string
get_lasers()

Returns a list with all lasers.

If no config_id is set, raises an AttributeError

get_lasers_off_cmds()

Returns the command to turn the laser off.

get_last_built_layer()

When a job is running, a websockets receives information about how many addLayerCommands have been executed. This information is used to calculate the current layer number by adding it to the starting layer which was specified when a job was started.

Returns:current layer number during a job
Return type:int
get_machine_id(machine_name)

Get the machine_id from a given Machine Name.

If no or multiple machines with the given name are given, raises ValueErrors. In this case, start the Browser based GUI AconitySTUDIO and copy the id from the URL and manually set the attribute machine_id.

If successfull, returns the machine_id and saves it to self.machine_id.

Parameters:machine_name (string) – Name of Machine
Returns:Machine ID
Return type:string
get_session_id(n=-1)

Get all session ids. If successfull, saves the session ID in self.session_id

Parameters:n (int) – With the default parameter n=-1, the most recent session id gets saved to self.session_id (second last session, use n=-2 etc).
Returns:Session ID
Return type:string
get_workunit_and_channel_id(result=None)

Retrieves workunit_id and channel_id. If successfull, saves them in self.channel_id and self.workunit_id and returns them

If not successfull, raises a ValueError.

Returns:workunit_id, channel_id
Return type:tuple
pause_job(workunit_id=None, channel_id='run0')

Pauses the running script on the given channel and workunit

Parameters:
  • workunit_id (string) – the route GET /script yields information about the current workunit_id
  • channel – the route GET /script yields information about the current workunit_id
post(url, data=None, files=None, headers={}, timeout=300)

The client sends a post request to the Server. If the response status is 200, returns the body of the return json, else a http exception is raised.

Parameters:
  • url (string) – request url, will get added to self.rest_url (for details see get())
  • data (dict) – data to be posted
post_script(init_script='', execution_script='', job_id=None, channel_id='run0', file_path_init_script=None, file_path_execution_script=None)

The client posts execution and init/resume scripts to the Server.

If the response status is != 200, raises Exception. Returns the body of the return json.

It is recommended that the API function start_job is used instead of this function, because start_job generates the init_script automatically.

Parameters:
  • data (dict) – data to be posted
  • job_id (string) – job_id of the job
  • channel_id (string) – channel_id of the job, for instance “run0”.
  • execution_script (string) – execution script
  • init_script (string) – init script
  • file_path_execution_script – If != None, gets interpreted as a filepath. The file will be read and any string given to parameter execution_script is ignored.
  • file_path_execution_script – string
  • file_path_init_script – If != None, gets interpreted as a filepath. The file will be read and any string given to parameter init_script is ignored.
  • file_path_init_script – string
Returns:

Returns the body of the return json from the request.

Return type:

dict

put(url, data=None, files=None, headers={})

The client sends a put request to the Server. If the response status is 200, returns the body of the return json, else a http exception is raised.

Parameters:
  • url (string) – request url, will get added to self.rest_url (for details see get())
  • data (dict) – data to be posted
restart_config()

The attribute “config_id” must be set. Restarts the config with that id.

If no config_id is set, raises a ValueError.

resume_job(layers=None, parts='all', workunit_id=None, channel_id='run0')

Resumes the running job on the given channel and workunit.

Parameters:
  • init_resume_script (string) – the init/resume script.
  • workunit_id (string) – the route GET /script yields information about the current workunit_id
  • channel – the route GET /script yields information about the current workunit_id
resume_script(init_resume_script, workunit_id=None, channel_id='run0', file_path_given=False)

Resumes the running script on the given channel and workunit.

Parameters:
  • init_resume_script (string) – the init/resume script.
  • workunit_id (string) – the route GET /script yields information about the current workunit_id. If workunit_id = None, the client attempts to use its own attribute workunit_id. If that fails, raises ValueError.
  • channel – the route GET /script yields information about the current workunit_id
save_data_to_pymongo_db()

Continually saves the output of the WebSocket Server by saving it into a Mongo database Call enable_pymongo_database() before calling this function

start_job(layers, execution_script, job_id=None, channel_id='run0', parts='all')

Starts a job. The init/resume script will be generated automatically from the current job.

Parameters:
  • execution_script (string) – The execution script which shall be executed.
  • job_id (string) – Id of the Job. Get it by calling get_job_id().
  • channel_id (string) – ‘run0’.
  • layers (list) – Specify the layers which shall be built. Must be given as list with 2 integer entries
  • parts (list/string) – Specify the parts which shall be built. Can either be a list of integers or the string ‘all’.
stop_channel(channel='manual_move')

Stops the running execution on the given channel.

Parameters:channel (string) – Example: ‘manual_move’
stop_job(workunit_id=None, channel='run0')

Stops the running script on the given channel and workunit

Parameters:
  • workunit_id (string) – the route GET /script yields information about the current workunit_id
  • channel (string) – the route GET /script yields information about the current channel
subscribe_report(name)

Subscribes to reports via the WebServer.

To get information about the reports use the route configurations/{client.config_id}/topics).

Parameters:name (string) – name of report, example reports: ‘state’, ‘task’.
subscribe_topic(name)

Subscribes to reports via the WebServer.

To get information about the topics use the route configurations/{client.config_id}/topics).

Parameters:name (string) – name of topic. Examples are ‘State’, ‘Sensor’,’cmds’ and ‘Positioning’.

aconityAPIfiles.AconitySTUDIO_utils module

class aconityAPIfiles.AconitySTUDIO_utils.JobHandler(job, logger, studio_version)

Bases: object

The Python Client uses this Class to modify a job locally (so it can later be uploaded to the Server database). Additionally, it uses the locally saved job to create init and init_resume scripts The user of the Python Client never needs to use this class directly.

change_global_parameter(param, new_value, check_boundaries=True)

Function to change global build parameters

change_part_parameter(part_id, param, new_value, laser='*', check_boundaries=True)

Function to build parameters for individual parts

convert_to_string(data=None)

Convert input data type into a sring.

create_addParts()

Returns the commands to add parts to the job

create_init_resume_script(layers, parts='all')

Message to resume the execution of a script

create_init_script(layers, parts='all')

Message to start the execution of a script

create_laser_beam_sources(lasers)

Creates and returns a dictionary containing the laser beam sources

create_preStartParams()

Returns the parameters set before the start of the build

create_preStartSelection(layers, parts)

Select the parts to be used

get_lasers()

Returns the available lasers

get_mapping_parts_to_index()

Returns the indices of the job parts

set(job)

Set the internal job variable to the input job

to_json()

Convert current job to json

aconityAPIfiles.AconitySTUDIO_utils.customTime(*args)

Converts time to the local machine timezone.

aconityAPIfiles.AconitySTUDIO_utils.filter_out_keys(data, allowed=['name', 'type', 'value'])

Loop through input dictionary and only retain the ‘name’, ‘type’, ‘value’ keys

aconityAPIfiles.AconitySTUDIO_utils.fix_ws_msg(msg, replace_value=-1)
aconityAPIfiles.AconitySTUDIO_utils.get_adress(args)

Return the address of the machine

aconityAPIfiles.AconitySTUDIO_utils.get_time_string(raw_time_stamp, format='%b %d %H:%M:%S')

Return a string with the current time

aconityAPIfiles.AconitySTUDIO_utils.log_setup(filename, directory_path='')

Initialise the logging functionality

aconityAPIfiles.AconitySTUDIO_utils.track_layer_number(client, msg)

Update the current layer class attribute

Module contents