Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

An approach for storing and retrieving defined views in environment

#1
I have written a program to get the views stored in the station by View manager and use them in my code.
At first, I save the items in Tools/Options/ViewNames in a file with an txt extension (coppy and past). Then write the following code to save each of these views with a name and apply them to the environment when called in the main program:

import ast

def read_file(filename):
    name_matrix = []
    data_matrix = []

    with open(filename, 'r') as file:
        line = file.readline().strip()
        items = line.split('||')

        for item in items:
            name, vector = item.split('|')
            float_vector = ast.literal_eval(vector)
            name_matrix.append(name)
            data_matrix.append(float_vector)

    return name_matrix, data_matrix

def print_matrices(name_matrix, data_matrix):
    print("Name Matrix:")
    for name in name_matrix:
        print(name)

    print("Data Matrix:")
    for vector in data_matrix:
        print(vector)

def main():
    filename = r'C:\Users\rezaj\OneDrive\Desktop\Temp.txt'
    name_matrix, data_matrix = read_file(filename)
    print_matrices(name_matrix, data_matrix)

if __name__ == "__main__":
    main()


Is the program that I have written suitable and practical or is there a better way to interact between the code environment and the program environment?
#2
What exactly are you trying to achieve? Transfer View points to another station?
Otherwise, using a file should not be necessary.
Please read the Forum Guidelines before posting!
Find useful information about RoboDK by visiting our Online Documentation.
#3
(10-16-2023, 02:06 PM)Sam Wrote: What exactly are you trying to achieve? Transfer View points to another station?
Otherwise, using a file should not be necessary.

Thank you for your answer.
At first, according to the position of my cobots in the software environment, I have saved several different views by  view manager.
I have written a program in Python and I want to call those saved views.
  Because I can't call the saved views in my program. With the help of the path to store the views in the station, I copied them and put them in a file so that I can save and restore them again in the program. In my opinion, it was a bad solution, but unfortunately, I could not use the saved views in the RoboDK environment in programming.
#4
You can call the saved views in your program.

RoboDK programs can call Python scripts, and support arguments.
For instance, you can add a program call like this "LoadView(View_5)" that will call the Python script LoadView with the argument "View_5".

You can add console argument support to LoadView.py (using sys.argv) and add it to your station:
https://github.com/RoboDK/Plug-In-Interf...oadView.py
Please read the Forum Guidelines before posting!
Find useful information about RoboDK by visiting our Online Documentation.
  




Users browsing this thread:
1 Guest(s)