Python Sample Usage Guide

You are currently viewing the documentation for a pre-release version (2.2.0). To access documentation for other versions, click the "Switch Version" button located in the upper-right corner of the page.

■ If you're unsure about the version of the product you are using, please contact Mech-Mind Technical Support for assistance.

This section introduces how to configure and run Python samples of Mech-Vision SDK.

Prerequisites

Sample Overview

Python samples are located in development/python/examples/ as standalone files:

Sample file Description

solution_basic.py

Open, close, save, and rename solutions; get solution information and project information lists.

project_basic.py

Run projects and get output data (pick point poses).

project_data_storage.py

Operate project data storage and read/write stored data.

project_param_recipe.py

Get parameter recipe lists and switch the current parameter recipe.

solution_comm_config.py

Get and modify communication configurations of a solution (TCP/IP, Modbus, and so on).

solution_device_status.py

Get camera status information in a solution, such as connection status, temperature, and transfer rate.

solution_global_variable.py

Read and write global variables in a solution (integer, floating-point, string, queue, and so on).

step_basic.py

Get Step information, pin Step output ports, and get Step output data (such as point poses) after running a project.

step_props.py

Read and set Step parameters in JSON format.

Run Samples

  1. Ensure that Mech-Vision is running.

  2. Update the solution path in the sample file by replacing the default path with the actual one:

    path = "D:/path/to/your/solution"
  3. Run the sample in a command line:

    python solution_basic.py

Code Examples

Open a Solution and Get Project Information (solution_basic.py)

import mmind_vision
from mmind_vision import *

def main():
    # Open a solution
    solution = Solution()
    solution.open("D:/data/vision_sdk_example", "", "")

    # Get solution information
    solution_info = solution.get_info()
    print(f"Solution: {solution_info.name}")
    print(f"Path:     {solution_info.path}")

    # Get project information list
    project_infos = solution.get_all_project_infos()
    for info in project_infos:
        print(f"  Project: {info.name}, Running: {info.is_running}")

    # Save and close the solution
    solution.save()
    solution.close()

if __name__ == '__main__':
    mmind_vision.initialize()
    main()
    mmind_vision.uninitialize()

Run a Project and Get Output Data (project_basic.py)

import mmind_vision
from mmind_vision import *
import json

def main():
    solution = Solution()
    solution.open("D:/data/vision_sdk_example", "", "")

    # Get the first project name
    project_infos = solution.get_all_project_infos()
    project = Project(project_infos[0].name)

    # Run the project (wait until it finishes)
    project_result = project.run(
        ProjectRunWaitState.Finished, "request_1")

    # Parse output data (pick point poses)
    output = json.loads(project_result.output_json)
    pick_points = output.get("workobject_data", {}).get("pick_points", [])
    print(f"Pick points count: {len(pick_points)}")

if __name__ == '__main__':
    mmind_vision.initialize()
    main()
    mmind_vision.uninitialize()

Read and Set Step Parameters (step_props.py)

import mmind_vision
from mmind_vision import *
import json

def main():
    solution = Solution()
    solution.open("D:/data/vision_sdk_example", "", "")

    step = Step("3D Matching_1", "Matching")

    # Read step parameters
    names_json = json.dumps(["confidenceThreshold"])
    props_json = step.get_properties_json(names_json)
    props = json.loads(props_json)
    print(f"Confidence threshold: {props['confidenceThreshold']}")

    # Set step parameters
    new_props = json.dumps({"confidenceThreshold": 0.8})
    step.set_properties_json(new_props)

if __name__ == '__main__':
    mmind_vision.initialize()
    main()
    mmind_vision.uninitialize()

Is this page helpful?

You can give a feedback in any of the following ways:

We Value Your Privacy

We use cookies to provide you with the best possible experience on our website. By continuing to use the site, you acknowledge that you agree to the use of cookies. If you decline, a single cookie will be used to ensure you're not tracked or remembered when you visit this website.