Thanks for the update onekk, and for getting sliptonics input......I am new to the forum so not as familiar with the controls.
I don't have direct experience with cnc but I do have peripheral knowledge and I know 'tool management' is a big portion of the work for any serious enterprise beyond hobby. .
The concept of a central tool library is useful to create the standard set of tools and their parameters available for any specific job....
but usually once a job has been defined any tools associated with it....and the speeds and feeds for that specific process you want to remain static...so if you return to reproduce that Job at a later date (6 months .... 1 year later) that NONE of the operational parameters or tools have been modified by edits occurring in other processes.
That means that most of the 'tool library' functionality should be considered as a template system.
I am looking for a way to 'consolidate' and 'flatten' all that information into a single file that is under user control that allows for the
user to backup/restore/clone a collection of tools for both existing and new projects/jobs.
So far I have been able to create a simple csv file structure that consolidates the Toolbit info and Library data that can easily be parsed to
recreate all the key components from a single file. csv files can be more easily maintained by end-users.
The below code creates a list of dicts from the file above
and the first Tool (NR=0) is a dummy tool that actually contains information regarding this Library....default material, paths, and version info.
Code: Select all
import csv
import os.path
import json
# ....
# -- required for gitem() function
boolTokens = ['True','False','T','F']
# -- test for multiple data types and return the most likely.
# -- Handles most simple datatypes....integer,float,boolean,string.
def gitem(item):
item.strip()
try:
item=int(item)
return item
except ValueError:
pass
try:
item=float(item)
return item
except ValueError:
pass
for x in boolTokens:
if any( x == item for x in boolTokens):
if any (y == item for y in boolTokens[::2]):
return True
else:
return False
return item
# -- takes a header list and row list converts it into a dict.
# -- Uses gitem() function to handle most simple datatypes....integer,float,boolean,string.
def rowConvert(h,a):
b=[]
for x in a:
b.append(gitem(x))
k = iter(h)
it = iter(b)
res_dct = dict(zip(k, it))
return res_dct
def load_Params(filename= '../Mod/FeedsAndSpeeds/params.csv'):
if not os.path.isfile(filename):
print ('Error: [ ' + filename + ' ] does not exist!')
return None
mlist=[]
with open(filename,'r') as csvin:
alist=list(csv.reader(csvin))
firstLine = True
for a in alist:
if firstLine:
if len(a) == 0: continue
if len(a) == 1: continue
else:
h = a
firstLine = False
else:
print(rowConvert(h,a))
mlist.append(rowConvert(h,a))
return mlist
# -- requires import csv and import os.path
# -- ToolLib load
curDir=os.path.split(App.ActiveDocument.FileName)[0]
alist=load_Params( curDir + '/myToolLib.csv')
for row in alist:
print (row)
print (' row items ')
for k,v in row.items():
print ( k + ' : ' + str(v) )
parm_dict=json.loads(row['parameter'])
print (' -- parameter items ' )
for k,v in parm_dict.items():
print ( ' -- ' + k + ' : ' + v )
Below is the sample output...
Code: Select all
{'nr': 0, 'version': 1, 'name': 'My ToolLibrary', 'shape': '', 'parameter': '{"Shape_Path": "My/Shape/Path","Material":"Aluminum","Notes": "--"}', 'attribute': '{}'}
row items
nr : 0
version : 1
name : My ToolLibrary
shape :
parameter : {"Shape_Path": "My/Shape/Path","Material":"Aluminum","Notes": "--"}
attribute : {}
-- parameter items
-- Shape_Path : My/Shape/Path
-- Material : Aluminum
-- Notes : --
{'nr': 1, 'version': 2, 'name': '5mm Drill', 'shape': 'drill.fcstd', 'parameter': '{"Diameter": "5.0000 mm","Length": "50.0000 mm","TipAngle": "119.0000 \\u00b0"}', 'attribute': '{}'}
row items
nr : 1
version : 2
name : 5mm Drill
shape : drill.fcstd
parameter : {"Diameter": "5.0000 mm","Length": "50.0000 mm","TipAngle": "119.0000 \u00b0"}
attribute : {}
-- parameter items
-- Diameter : 5.0000 mm
-- Length : 50.0000 mm
-- TipAngle : 119.0000 °
{'nr': 2, 'version': 2, 'name': '5mm Endmill', 'shape': 'endmill.fcstd', 'parameter': '{"CuttingEdgeHeight": "30.0000 mm","Diameter": "5.0000 mm","Length": "50.0000 mm","ShankDiameter": "3.0000 mm"}', 'attribute': '{}'}
row items
nr : 2
version : 2
name : 5mm Endmill
shape : endmill.fcstd
parameter : {"CuttingEdgeHeight": "30.0000 mm","Diameter": "5.0000 mm","Length": "50.0000 mm","ShankDiameter": "3.0000 mm"}
attribute : {}
-- parameter items
-- CuttingEdgeHeight : 30.0000 mm
-- Diameter : 5.0000 mm
-- Length : 50.0000 mm
-- ShankDiameter : 3.0000 mm
{'nr': 3, 'version': 2, 'name': '5mm-thread-cutter', 'shape': 'thread-mill.fcstd', 'parameter': '{ "Crest": "0.10 mm","Diameter": "5.00 mm", "Length": "50.00 mm", "NeckDiameter": "3.00 mm", "NeckLength": "20.00 mm", "ShankDiameter": "5.00 mm" }', 'attribute': '{}'}
row items
nr : 3
version : 2
name : 5mm-thread-cutter
shape : thread-mill.fcstd
parameter : { "Crest": "0.10 mm","Diameter": "5.00 mm", "Length": "50.00 mm", "NeckDiameter": "3.00 mm", "NeckLength": "20.00 mm", "ShankDiameter": "5.00 mm" }
attribute : {}
-- parameter items
-- Crest : 0.10 mm
-- Diameter : 5.00 mm
-- Length : 50.00 mm
-- NeckDiameter : 3.00 mm
-- NeckLength : 20.00 mm
-- ShankDiameter : 5.00 mm
{'nr': 4, 'version': 2, 'name': '6mm Ball End', 'shape': 'ballend.fcstd', 'parameter': '{"CuttingEdgeHeight": "40.0000 mm","Diameter": "6.0000 mm","Length": "50.0000 mm","ShankDiameter": "3.0000 mm"}', 'attribute': '{}'}
row items
nr : 4
version : 2
name : 6mm Ball End
shape : ballend.fcstd
parameter : {"CuttingEdgeHeight": "40.0000 mm","Diameter": "6.0000 mm","Length": "50.0000 mm","ShankDiameter": "3.0000 mm"}
attribute : {}
-- parameter items
-- CuttingEdgeHeight : 40.0000 mm
-- Diameter : 6.0000 mm
-- Length : 50.0000 mm
-- ShankDiameter : 3.0000 mm
{'nr': 5, 'version': 2, 'name': '6 mm Bull Nose', 'shape': 'bullnose.fcstd', 'parameter': '{"CuttingEdgeHeight": "40.0000 mm","Diameter": "6.0000 mm","FlatRadius": "1.5000 mm","Length": "50.0000 mm","ShankDiameter": "3.0000 mm"}', 'attribute': '{}'}
row items
nr : 5
version : 2
name : 6 mm Bull Nose
shape : bullnose.fcstd
parameter : {"CuttingEdgeHeight": "40.0000 mm","Diameter": "6.0000 mm","FlatRadius": "1.5000 mm","Length": "50.0000 mm","ShankDiameter": "3.0000 mm"}
attribute : {}
-- parameter items
-- CuttingEdgeHeight : 40.0000 mm
-- Diameter : 6.0000 mm
-- FlatRadius : 1.5000 mm
-- Length : 50.0000 mm
-- ShankDiameter : 3.0000 mm
{'nr': 6, 'version': 2, 'name': '45 Deg. Chamfer', 'shape': 'chamfer.fcstd', 'parameter': '{"CuttingEdgeAngle": "45.0000 \\u00b0","CuttingEdgeHeight": "6.3500 mm","Diameter": "12.3323 mm","FlatRadius": "5.0000 mm","Length": "30.0000 mm","ShankDiameter": "6.3500 mm"}', 'attribute': '{}'}
row items
nr : 6
version : 2
name : 45 Deg. Chamfer
shape : chamfer.fcstd
parameter : {"CuttingEdgeAngle": "45.0000 \u00b0","CuttingEdgeHeight": "6.3500 mm","Diameter": "12.3323 mm","FlatRadius": "5.0000 mm","Length": "30.0000 mm","ShankDiameter": "6.3500 mm"}
attribute : {}
-- parameter items
-- CuttingEdgeAngle : 45.0000 °
-- CuttingEdgeHeight : 6.3500 mm
-- Diameter : 12.3323 mm
-- FlatRadius : 5.0000 mm
-- Length : 30.0000 mm
-- ShankDiameter : 6.3500 mm
{'nr': 7, 'version': 2, 'name': '60 Deg. V-Bit', 'shape': 'v-bit.fcstd', 'parameter': '{"CuttingEdgeAngle": "60.0000 \\u00b0","Diameter": "10.0000 mm","CuttingEdgeHeight": "1.0000 mm","TipDiameter": "1.0000 mm","Length": "20.0000 mm","ShankDiameter": "5.0000 mm"}', 'attribute': '{}'}
row items
nr : 7
version : 2
name : 60 Deg. V-Bit
shape : v-bit.fcstd
parameter : {"CuttingEdgeAngle": "60.0000 \u00b0","Diameter": "10.0000 mm","CuttingEdgeHeight": "1.0000 mm","TipDiameter": "1.0000 mm","Length": "20.0000 mm","ShankDiameter": "5.0000 mm"}
attribute : {}
-- parameter items
-- CuttingEdgeAngle : 60.0000 °
-- Diameter : 10.0000 mm
-- CuttingEdgeHeight : 1.0000 mm
-- TipDiameter : 1.0000 mm
-- Length : 20.0000 mm
-- ShankDiameter : 5.0000 mm
{'nr': 8, 'version': 2, 'name': 'Probe', 'shape': 'probe.fcstd', 'parameter': '{"Diameter": "6.0000 mm","Length": "50.0000 mm","ShaftDiameter": "4.0000 mm"}', 'attribute': '{}'}
row items
nr : 8
version : 2
name : Probe
shape : probe.fcstd
parameter : {"Diameter": "6.0000 mm","Length": "50.0000 mm","ShaftDiameter": "4.0000 mm"}
attribute : {}
-- parameter items
-- Diameter : 6.0000 mm
-- Length : 50.0000 mm
-- ShaftDiameter : 4.0000 mm
{'nr': 9, 'version': 2, 'name': 'Slitting Saw', 'shape': 'slittingsaw.fcstd', 'parameter': '{"BladeThickness": "3.0000 mm","CapHeight": "3.0000 mm","CapDiameter": "8.0000 mm","Diameter": "76.2000 mm","Length": "50.0000 mm","ShankDiameter": "19.0500 mm"}', 'attribute': '{}'}
row items
nr : 9
version : 2
name : Slitting Saw
shape : slittingsaw.fcstd
parameter : {"BladeThickness": "3.0000 mm","CapHeight": "3.0000 mm","CapDiameter": "8.0000 mm","Diameter": "76.2000 mm","Length": "50.0000 mm","ShankDiameter": "19.0500 mm"}
attribute : {}
-- parameter items
-- BladeThickness : 3.0000 mm
-- CapHeight : 3.0000 mm
-- CapDiameter : 8.0000 mm
-- Diameter : 76.2000 mm
-- Length : 50.0000 mm
-- ShankDiameter : 19.0500 mm
>>>