from xml.dom.minidom import Document
from xml.etree.ElementTree import ProcessingInstruction
import adsk.core, adsk.fusion, adsk.cam, traceback,os
def isclose(a,b, diff)
return abs(a-b) <= diff
def run(context)
ui = None
try:
app = adsk.core.Application.get()
doc = app.activeDocument
ui = app.userInterface
#Beginning of template input section
products = doc.products
cam = adsk.cam.CAM.cast(products.itemByProductType("CAMProductType"))
if app.activeProduct.productType == "CAMProductType":
ui.messageBox("Recommend to select EMPTY setup to create operations.")
#ui.messageBox("We are in CAM application.")
setups = cam.setups
#ui.messageBox(str(setups.count))
for set in cam.setups:
if set.isActive:
asetup=set
#ui.messageBox("Active setup detected " + asetup.name)
inpt = ui.inputBox("Input machine name: (TM or VF) ","Template selection","TM")
#ui.messageBox(str(inpt[1]))
if inpt[0] == "TM" or inpt[0] == "tm":
templateFilename = "C:\\Users\\diana\\AppData\\Roaming\\Autodesk\\CAM360\\templates\\Toorik.f3dhsm-template"
#ui.messageBox("TM-2P selected")
elif inpt[0] == "VF" or inpt[0] == "vf":
templateFilename = "C:\\Users\\diana\\AppData\\Roaming\\Autodesk\\CAM360\\templates\\Toorik_Suur.f3dhsm-template"
#ui.messageBox("VF5SS selected")
else:
ui.messageBox("Invalid user input")
if not os.path.exists(templateFilename)
ui.messageBox("The template '" + templateFilename + "' does not exist")
else:
#ui.messageBox("The template '" + templateFilename + "' exists")
asetup.createFromTemplate(templateFilename)
operat = asetup.allOperations
#End of template input section
#Beginning of sketch selection section
ui.messageBox("Now select a sketch")
chooseSketch = ui.selectEntity("Select a sketch", "Sketches")
if chooseSketch.isValid == True:
sketch = chooseSketch.entity
holes = sketch.sketchCurves.sketchCircles
n = holes.count
d8points = []
d10points = []
#for hole in holes:
for i, hole in enumerate(holes)
if isclose(hole.radius, 0.5, 0.001)
d10points.append(hole.centerSketchPoint)
#ui.messageBox("Hole with diameter 10 " + str(i) + " added succsessfully")
elif isclose(hole.radius, 0.4, 0.001)
d8points.append(hole.centerSketchPoint)
#ui.messageBox("Hole with diameter 8 " + str(i) + " added succsessfully")
else:
ui.messageBox("Comparison fail")
#ui.messageBox("Point " + str(i) + " added succsessfully")
ui.messageBox("D10: " + str(len(d10points)) + " D8: " + str(len(d8points)))
#ui.messageBox("All good" )
else:
ui.messageBox("Point detection failed")
#End of sketch selection section
#Beginning of operation modification section
for op in operat:
oppoints = op.parameters.itemByName("holePoints")
ui.messageBox(str(oppoints.isEditable))
"""
for op in operat:
if op.name == "Spot":
oppoints = op.parameters.itemByName ("holePoints")
ui.messageBox(str(oppoints.isValid)+" "+ str(oppoints.objectType)+ "" )
for p in d10points:
oppoints += p.
for p in d10points:
if op.name == "Spot":
ui.messageBox("Spot operation detected")
spoints =[]
spoints.append(d10points)
spoints.append(d8points)
ui.messageBox("There are "+ str(spoints.count)+ " points in operation" + op.name)
operatpoints = spoints
ui.messageBox("There are "+ str(operatpoints.count)+ " points in operation" + op.name)
elif op.name == "D5.9":
ui.messageBox("D5.9 operation detected")
op.parameters.holePoints.append(d10points)
elif op.name == "D8.02":
ui.messageBox("D8.02 operation detected")
op.parameters.holePoints.append(d8points)
"""
else:
ui.messageBox("You need to be in CAM application!")
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))