Script to Read Excel Data into 3-Matic Via Pandas 'Dataframe' objects

Script to Read Excel Data into 3-Matic via Pandas ‘Dataframe’ object

A Dataframe object is a multi-dimensional table-like data structure (a multi-dimensional array)

Your data must be in a simple multiple array format with only column and row labels, 2D excel data.
See the example below:

Model X1 Y2 Z3 X1 Y2 Z3 NX NY NZ  
R1   05 10 15 31 15 04 08 04 02 
R2   01 45 02 03 05 04 08 06 04 
R3   02 05 04 45 05 06 05 04 50

Once the data is imported as a dataframe object, row numbers will be created to iterate through each model

  Model X1 Y2 Z3 X1 Y2 Z3 NX NY NZ 
0  R1   05 10 15 31 15 04 08 04 02 
1  R2   01 45 02 03 05 04 08 06 04 
2  R3   02 05 04 45 05 06 05 04 50

You can follow the Pandas ‘Dataframe’ documentation for maniuplating the imported data.

This link below on Realpython.com is very helpful

The pandas DataFrame: Make Working With Data Delightful – Real Python.

#Import 3-matic and pandas libraries
import trimatic 
import pandas as pd

#Create a new project 
trimatic.file.new_project()

#***Must be changed for your script***
#The path where you excel data is located
path = r'C:\Users\user\Excel Dataframes Template.xlsx'

#Creating the Datafram object using the pandas 'read_excel' function and the excel file located at the 
windows path
df = pd.read_excel(path)

#Loop that interates along length of dataframe (# of rows)
#This specific demo data contains information to create 2 points, a plane (using normal and origin 
data), and a measurement between the two points.
for i in range(len(df)):

#Iterating through the first column to extract the model name for each point coordinate set
name = df.Model_ID[i]

#Point 1 Creation
x_cord = df.P1_X[i]
y_cord = df.P1_Y[i]  
z_cord = df.P1_Z[i]
P1_cords = [x_cord,y_cord,z_cord]
P1 = trimatic.create_point(P1_cords)
P1.name = f'{name} Point 1'

#Point 2 (Origin) Creation 
x_cord = df.O1_X[i]
y_cord = df.O1_Y[i]  
z_cord = df.O1_Z[i]
O1_cords = [x_cord,y_cord,z_cord]
O1 = trimatic.create_point(O1_cords)
O1.name = f'{name} Point 2 Origin'

#Plane Creation
#Normal coordinates
x_cord = df.N_X[i]
y_cord = df.N_Y[i]  
z_cord = df.N_Z[i]
n_cords = [x_cord,y_cord,z_cord]
plane = trimatic.create_plane_normal_origin(normal=n_cords,origin=O1_cords)
plane.name = f'{name} Plane'

#Create distance measurement and name based on model ID
distance = trimatic.create_distance_measurement(P1, O1)
distance.name = f'{name} {P1.name} to {O1.name} Distance'

#Group points, plane and distance measurement into groups based on Model ID
trimatic.create_group(entities=[P1, O1, plane, distance],name=name)