Get CAM parameter value on a text box

Get CAM parameter value on a text box

pedro_babo
Advocate Advocate
706 Views
4 Replies
Message 1 of 5

Get CAM parameter value on a text box

pedro_babo
Advocate
Advocate

Im triyng to get the value one CAM parameter on a command input.

 

using 

 

        DiametroPeça =setup.parameters.itemByName('job_stockDiameter')
        ComprmentPeça = '100'
   
    # Create a simple text box input.
    inputs.addTextBoxCommandInput('Diametro', 'Diametro da Peça', DiametroPeça.value.objectType, 1, True)
    inputs.addTextBoxCommandInput('Comprimento', 'comprimento da Peça', ComprmentPeça, 1, True)
 
----
I get 
 
<adsk.cam.CAMParameter; proxy of <Swig Object of type 'adsk::core::Ptr< adsk::cam::CAMParameter > *' at 0x000002294ACD6C70> >
 
how should I get the correct value.
0 Likes
Accepted solutions (1)
707 Views
4 Replies
Replies (4)
Message 2 of 5

BrianEkins
Mentor
Mentor

I think this should do it. The value returned is a floating point value and is always in centimeters. You can convert it yourself to the unit of choice or use Fusion's Units of Measure functionality to help convert and format it. You might also consider using a ValueCommandInput instead of a TextBoxCommandInput because it will handle this automatically.

 

DiametroPeça = setup.parameters.itemByName('job_stockDiameter')
paramValue = DiametroPeça.value.value

# Create a simple text box input.
inputs.addTextBoxCommandInput('Diametro', 
                              'Diametro da Peça', 
                              f'{paramValue} cm', 
                              1, 
                              True)

  

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 5

pedro_babo
Advocate
Advocate

hi @BrianEkins ,

 

first thanks for the responce, I've ben beasy during the this time.

Ive implemented the code has you sogested but get

 

"Diametro da Peça nan cm" 

 

on the form.

I sopose that nan is not a number. possibly a string.

 

what does f'{paramValue} do?

0 Likes
Message 4 of 5

jeff.pek
Community Manager
Community Manager
Accepted solution

Hi -

 

Not sure if this helps, but the "job_stockDiameter" parameter will only be valid for "Fixed Cylinder" and "Fixed Tube" stock types. What is your setup using?

 

Jeff

0 Likes
Message 5 of 5

pedro_babo
Advocate
Advocate

it works now with the code:

 

------------------

                DiametroPeça =setup.parameters.itemByName('job_stockDiameter')
                ValorParametroDiametro = UnitsMnger.formatInternalValue(DiametroPeça.value.value,UnitsMnger.defaultLengthUnits,True)
------------------------
then it can be showed on
------------------
 inputs.addTextBoxCommandInput('Diametro', 'Diametro da Peça', f'{ValorParametroDiametro} ', 1, True)
------------------------------
thanks to @jeff.pek  and @BrianEkins 
 
0 Likes