Print inputs from TableCommandInput into CSV file

Print inputs from TableCommandInput into CSV file

tomas.bangoA2EPZ
Advocate Advocate
979 Views
5 Replies
Message 1 of 6

Print inputs from TableCommandInput into CSV file

tomas.bangoA2EPZ
Advocate
Advocate

Hello, I'm creating an addin that allows the user to use TableCommandInput to create a table with an arbitrary number of rows and 3 columns to be filled with a value. The table contains 2x BoolValueInput (add/delete) to add or delete a row as the user needs.

 

I add rows using the function:

import adsk.core
import adsk.fusion

_rowNumber = 0

def addRowTTable(tableInput):
    global _rowNumber
    # Get the CommandInputs object associated with the parent command.
    cmdInputs = adsk.core.CommandInputs.cast(tableInput.commandInputs)
    
    # Vytvoření com inputs
    NMinp = cmdInputs.addStringValueInput('TableInput_string{}'.format(_rowNumber), 'String', str(0))
    Maxinp =  cmdInputs.addValueInput('TableInput_value{}'.format(_rowNumber), 'Value', 'mm', adsk.core.ValueInput.createByReal(0))
    Mininp =  cmdInputs.addValueInput('TableInput_value{}'.format(_rowNumber), 'Value', 'mm', adsk.core.ValueInput.createByReal(0))
    
    # Add the inputs to the table.
    row = tableInput.rowCount
    #tableInput.addCommandInput(valueInput, row, 0)
    tableInput.addCommandInput(NMinp, row, 0)
    tableInput.addCommandInput(Mininp, row, 1)
    tableInput.addCommandInput(Maxinp, row, 2)

    # Increment a counter used to make each row unique.
    _rowNumber = _rowNumber + 1

I would like to ask using what method am I able to insert the filled data from the table into a CSV file when I press OK? Since the API for TableCommandInput does not include a ListItems property.

 

Thank you for any advice

 

0 Likes
Accepted solutions (1)
980 Views
5 Replies
Replies (5)
Message 2 of 6

BrianEkins
Mentor
Mentor
Accepted solution

I think you want to use getInputAtPosition, which allows you to get the input at a specified row and column. You can then get the value from the input and write it out to a CSV file.

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

tomas.bangoA2EPZ
Advocate
Advocate

Hello again thank you for the advice I am currently using for and row count to sequentially print "input" from each column on each row. Unfortunately the result pasted into CSV looks like this:

 

3 collumns and 2 rows:
<adsk.core.ValueCommandInput; proxy of <Swig Object of type 'adsk::core::Ptr< adsk::core::ValueCommandInput > *' at 0x00000171BB2D7630> >,<adsk.core.ValueCommandInput; proxy of <Swig Object of type 'adsk::core::Ptr< adsk::core::ValueCommandInput > *' at 0x00000171BB3BA420> >,
<adsk.core.ValueCommandInput; proxy of <Swig Object of type 'adsk::core::Ptr< adsk::core::ValueCommandInput > *' at 0x00000171BB2D7F90> >,<adsk.core.ValueCommandInput; proxy of <Swig Object of type 'adsk::core::Ptr< adsk::core::ValueCommandInput > *' at 0x00000171BB3BA0F0> >,

 

How exactly to get the value inside the input? Thank you very much.

0 Likes
Message 4 of 6

BrianEkins
Mentor
Mentor

It depends on what you want and the type of input you're using.

 

For example, if you are using a BoolValueCommandInput, it has a "value" property that returns a Boolean value, so you'll probably want to convert it to a string to save to the CSV. The TextBoxCommandInput has a "text" property that returns a string containing the current value of the text box.

 

The ValueCommandInput is a bit more complicated. It has both a "value" and an "expression" property. The "expression" property returns what you see in the input. It could be something simple like "2.5 in" or more complex like "Length / 2.0". The "value" property returns the result of evaluating the expression and uses internal database units. For example, the value of the "2.0 in" expression will be a double value of 5.08 since the internal unit for length is Centimeters.

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

tomas.bangoA2EPZ
Advocate
Advocate

But how to get from for example  pwatch.getInputAtPosition(i,1) (Where pWatch=inputs.addTableCommandInput('Bay Watch','Tvorba Hlidaných parametru',3,'2:1:1')) to ValueCommandInput.value? 

 

Do I understand correctly that I have created a table using TableCommandInput which has 3 columns and x rows where in 1 column I have StrignValueInput in 2 and 3 I have ValueInput? The function getInputAtPosition returns me the Command Input. By using parentCommand I got one level up but I need one level down to be able to look into ValueInput.value for example. But how to do that?

 

 

 

 

0 Likes
Message 6 of 6

tomas.bangoA2EPZ
Advocate
Advocate

Because I made the function to add a row to the table in a separate file I did not see the properties of the returned object and therefore I was not able to find the .value in the function menu. The getInputAtPosition property is the solution.