Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to get compensation type from operation

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
pavel_viktorin
257 Views, 6 Replies

How to get compensation type from operation

Hi, I'm trying to get compensation type from existing operations, but without any satisfying result. Does anybody know how to get it?

 

My goal is to rename the operation if it's using tool compensation controlled by the control system of the machine, as is customary in our company.

 

Thanks in advance for your help.

 

 

Sample script with message box instead of op. renaming below:

 

import adsk.core, adsk.fusion, adsk.cam, traceback, adsk.drawing

app = adsk.core.Application.get()
ui  = app.userInterface
doc = app.activeDocument
products = doc.products
cam = adsk.cam.CAM.cast(products.itemByProductType("CAMProductType"))

def toolComp():

    for setup in cam.setups:
        for op in setup.operations:

            getCompensation = op.parameters.itemByName('compensationType')
            getStrategy = op.strategy

            if getCompensation == '\'control\'':
                comp = "- tool compensation active"
            elif getCompensation == '\'off\'':
                comp = "- tool center"
            elif getCompensation == None:
                comp = "- null"
            else:
                comp = "- other"
            
            ui.messageBox(getStrategy + comp )


def run(context):
    try:

        toolComp()

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

 

6 REPLIES 6
Message 2 of 7

Hi @pavel_viktorin 

you have to use something like in this line to get the compensation type

getCompensation = op.parameters.itemByName('compensationType').value.value

if you are using value.value method then you can simply check aganist the string contol or off. no need for the quotes .

there is a other method as well which is expression where you are use that well but for that quotes are needed for the comparision.

getCompensation = op.parameters.itemByName('compensationType').expression

 


Boopathi Sivakumar
Senior Technology Consultant

Message 3 of 7

Hello, I appreciate your help. The .value.value method confused me a little, but after a few tries, I have managed to write a working script. Thank You!

 

Solution here:

 

import adsk.core, adsk.fusion, adsk.cam, traceback, adsk.drawing

app = adsk.core.Application.get()
ui  = app.userInterface
doc = app.activeDocument
products = doc.products
cam = adsk.cam.CAM.cast(products.itemByProductType("CAMProductType"))

def toolComp():

    for setup in cam.setups:
        for op in setup.operations:

            getStrategy = op.strategy
            
            if getStrategy == "contour2d":
                getCompensation = op.parameters.itemByName('compensationType')
                compVal: adsk.cam.ChoiceParameterValue = getCompensation.value

                if compVal.value == "control":
                    comp = "-kor"
                elif compVal.value == "off":
                    comp = "-stredem"
                else:
                    comp = ""

                ui.messageBox(getStrategy + comp)

def run(context):
    try:
        toolComp()
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

 

Message 4 of 7
Tomas_V_cz
in reply to: pavel_viktorin

great script to check... Would it be possible to output a description of the operation instead of the text "contour2d"?

That would be great, because that way you can easily tell which operation the output is referring to

 

Dobrý den, píšu česky (podle vašeho jména snad dobře). Líbí se mi Váš cript na kompenzaci, napadlo mě, jestli by bylo možné místo "

contour2d

dát na výstup popis operace? Myslím že by to bylo mnohem přehlednější.

A druhá věc, myslíte že by bylo možné udělat podobný script na chlazení? Vypnuto, vnitřní, vnější atd?

Díky

 

Message 5 of 7

EN: Yes, it is possible, and yes, you can also use lots of other parameters.

 

CZ: Místo contour2d můžete použít jakýkoli text nebo třeba název konkrétní operace, což asi bude to, o čem mluvíte. Kromě korekce můžete používat i hromadu dalších parametrů, tedy i chlazení. Princip je úplně stejný.

 

import adsk.core, adsk.fusion, adsk.cam, traceback, adsk.drawing

app = adsk.core.Application.get()
ui  = app.userInterface
doc = app.activeDocument
products = doc.products
cam = adsk.cam.CAM.cast(products.itemByProductType("CAMProductType"))

def toolComp():

    for setup in cam.setups:
        for op in setup.operations:

            getStrategy = op.strategy
            
            if getStrategy == "contour2d":

                # any text
                # text = "any text" 

                # operation name
                text = op.name

                # compensation check
                getCompensation = op.parameters.itemByName('compensationType')
                compVal: adsk.cam.ChoiceParameterValue = getCompensation.value

                if compVal.value == "control":
                    comp = "-cor"
                elif compVal.value == "off":
                    comp = "-tool center"
                else:
                    comp = ""

                # coolant check
                getCoolant = op.parameters.itemByName('tool_coolant')
                coolantVal: adsk.cam.ChoiceParameterValue = getCoolant.value

                if coolantVal.value == "flood":
                    coolant = "-flood"
                elif coolantVal.value == "mist":
                    coolant = "-mist"
                elif coolantVal.value == "tool":
                    coolant = "-tool"
                elif coolantVal.value == "air":
                    coolant = "-air"
                elif coolantVal.value == "air through tool":
                    coolant = "-air through tool"
                elif coolantVal.value == "suction":
                    coolant = "-suction"
                elif coolantVal.value == "flood mist":
                    coolant = "-flood mist"
                elif coolantVal.value == "flood tool":
                    coolant = "-flood tool"                                               
                else:
                    coolant = "-without cooling"

                ui.messageBox(text + comp + coolant)

def run(context):
    try:
        toolComp()
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Message 6 of 7
Tomas_V_cz
in reply to: pavel_viktorin

Skvělé, díky moc.

Mezitím jsem se snažil nějak dostat výstup do jednoho okna, abych nemusel desetkrát klikat na OK- tady je výsledek. 

obrázek_2024-03-27_085752365.png

 

Ale je to udělané blbě- roztahoval jsem uvozovky u každého výstupu tak dlouho, než to bylo na jeden řádek.

Kdybyste uměl ten script na korekce (a možná i na to chlazení) všechny operace do jednoho okna s tím, že místo textu

countur2D by byl ten popis operace (myslím že v tom na chlazení to tak je), to by bylo opravdu skvělé. 

A chlazení možná pro všechny operace

Díky moc

Edit: teď jsem si všiml, že jde na výstup také typ korekce. Bylo by možné to dát vše do jednoho okna- s tím, že korekce by byla pouze u kontury 2D?

 

 

 

Message 7 of 7
pavel_viktorin
in reply to: Tomas_V_cz

import adsk.core, adsk.fusion, adsk.cam, traceback, adsk.drawing

app = adsk.core.Application.get()
ui  = app.userInterface
doc = app.activeDocument
products = doc.products
cam = adsk.cam.CAM.cast(products.itemByProductType("CAMProductType"))

def toolComp():

    global comp
    global messageText
    messageText = ""

    for setup in cam.setups:
        for op in setup.operations:
            
            getStrategy = op.strategy
            text = op.name
            comp =""
            
            if getStrategy == "contour2d":

                # compensation check
                getCompensation = op.parameters.itemByName('compensationType')
                compVal: adsk.cam.ChoiceParameterValue = getCompensation.value

                if compVal.value == "control":
                    comp = "-COMPENSATION"
                elif compVal.value == "off":
                    comp = "-TOOL CENTER"
                else:
                    comp = ""
            
            # coolant check
            getCoolant = op.parameters.itemByName('tool_coolant')
            coolantVal: adsk.cam.ChoiceParameterValue = getCoolant.value

            if coolantVal.value == "flood":
                coolant = "-flood"
            elif coolantVal.value == "mist":
                coolant = "-mist"
            elif coolantVal.value == "tool":
                coolant = "-tool"
            elif coolantVal.value == "air":
                coolant = "-air"
            elif coolantVal.value == "air through tool":
                coolant = "-air through tool"
            elif coolantVal.value == "suction":
                coolant = "-suction"
            elif coolantVal.value == "flood mist":
                coolant = "-flood mist"
            elif coolantVal.value == "flood tool":
                coolant = "-flood tool"                                               
            else:
                coolant = "-without cooling"

            messageText = messageText + text + coolant + comp + '\n'

    ui.messageBox(messageText)

def run(context):
    try:
        toolComp()
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report