Why this TypeError in addValueInput

Why this TypeError in addValueInput

RubyRedRick
Enthusiast Enthusiast
1,269 Views
11 Replies
Message 1 of 12

Why this TypeError in addValueInput

RubyRedRick
Enthusiast
Enthusiast
I'm getting this error message:
 

 

Execute: Traceback (most recent call last):
  File "/Users/rick/Library/Application Support/Autodesk/Autodesk Fusion 360/API/AddIns/ThreadedInsert/ThreadedInsert.py", line 336, in notify
    self.createInputs()
  File "/Users/rick/Library/Application Support/Autodesk/Autodesk Fusion 360/API/AddIns/ThreadedInsert/ThreadedInsert.py", line 127, in createInputs
    self.diameter1Input = self.inputs.addValueInput('diameter1', 'A', linearUnits, self.diameter1)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rick/Library/Application Support/Autodesk/webdeploy/production/86922b6f4858f413cf43758ea700aed2f7ddd881/Autodesk Fusion 360.app/Contents/Api/Python/packages/adsk/core.py", line 6856, in addValueInput
    return _core.CommandInputs_addValueInput(self, id, name, unitType, initialValue)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: in method 'CommandInputs_addValueInput', argument 5 of type 'adsk::core::Ptr< adsk::core::ValueInput > const &'

 

 
Line 127 is 

 

self.diameter1Input = self.inputs.addValueInput('diameter1', 'A', linearUnits, self.diameter1)

 

 
Just prior to executing line 127 the debug console shows:

 

self.inputs
<adsk.core.CommandInputs; proxy of <Swig Object of type 'adsk::core::Ptr< adsk::core::CommandInputs > *' at 0x3b0f30c00> >
linearUnits
'mm'
self.diameter1
0.5

 

 
 I'm at a loss. Can anyone enlighten me?
0 Likes
Accepted solutions (1)
1,270 Views
11 Replies
Replies (11)
Message 2 of 12

Jorge_Jaramillo
Collaborator
Collaborator
Hi,
Fourth parameter should be a instance of ValueInput.
So replace
self.diameter1
by
adsk.core.ValueInput.createByReal(self.diameter1)

0 Likes
Message 3 of 12

RubyRedRick
Enthusiast
Enthusiast

Now I get

CommandCreated failed: Traceback (most recent call last):
  File "/Users/rick/Library/Application Support/Autodesk/Autodesk Fusion 360/API/AddIns/ThreadedInsert/ThreadedInsert.py", line 160, in notify
    self.createInputs()
  File "/Users/rick/Library/Application Support/Autodesk/Autodesk Fusion 360/API/AddIns/ThreadedInsert/ThreadedInsert.py", line 127, in createInputs
    self.diameter1Input = self.inputs.addValueInput('diameter1', 'A', linearUnits, adsk.core.ValueInput.createByReal(self.diameter1))
                                                                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rick/Library/Application Support/Autodesk/webdeploy/production/86922b6f4858f413cf43758ea700aed2f7ddd881/Autodesk Fusion 360.app/Contents/Api/Python/packages/adsk/core.py", line 22214, in createByReal
    return _core.ValueInput_createByReal(realValue)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: in method 'ValueInput_createByReal', argument 1 of type 'double'

I found some things about swig in google but don't really understand them. 

0 Likes
Message 4 of 12

Jorge_Jaramillo
Collaborator
Collaborator

Don't care about swig.
Without your code is very complex to help you.
How is diameter1 defined in your class?

0 Likes
Message 5 of 12

RubyRedRick
Enthusiast
Enthusiast

Well I figured that one out.  I've been refactoring my code. I'm trying to make my custom feature able to produce multiple sub-features at multiple points.  

 

Jorge, you've been a big help with this so far. I really appreciate it. 

 

I'm a very experienced developer (over 35 years with C, Smalltalk, Ruby, Lisp, Swift etc.)  My Python knowledge is an inch deep though.

 

My current problem is that I can't figure out why a for loop to iterate over the selections in a selection input isn't being entered.  Here's a simplified code snippet. The first for loop is just for experimentation, the second is the beginning of the real loop, but what's after shouldn't be important here.

        for i in range(_pointSelectInput.selectionCount):    
            showMessage(f'Creating feature {i}')
        for i in range(_pointSelectInput.selectionCount):
            skPoint = _pointSelectInput.selection(i).entity
            threadedInsertBody = self.makeThreadedInsertBody(skPoint.worldGeometry)

I set breakpoints on lines 1, 2, 3, and 4.  When I stop at the first breakpoint, the debugger shows:

 

 

_pointSelectInput
<adsk.core.SelectionCommandInput; proxy of <Swig Object of type 'adsk::core::Ptr< adsk::core::SelectionCommandInput > *' at 0x370373390> >

_pointSelectInput.selectionCount
0
range(_pointSelectInput.selectionCount)
range(0, 0)

 

When I run it stops on line 3, I run again and it doesn't stop. So neither for loop is being entered and I can't figure out why.

 

0 Likes
Message 6 of 12

Jorge_Jaramillo
Collaborator
Collaborator
It seems to me that _pointSelectInput.selectionCount is 0.
A for loop with "range(0, 0)" doesn't iterate anytime since it means: start "i" at 0 and iterate while "i" < 0.
0 Likes
Message 7 of 12

RubyRedRick
Enthusiast
Enthusiast

ahh I understand range is an open range in python, like a...b in Ruby or a ..<b in Swift.

 

Now the next mystery when I get to the first line inside the for loop:

skPoint = _pointSelectInput.selection(i).entity

 

It blows up with 

 

/Users/rick/Library/Application Support/Autodesk/Autodesk Fusion 360/API/AddIns/ThreadedInsert
_pointSelectInput.selection(i)
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/rick/Library/Application Support/Autodesk/webdeploy/production/86922b6f4858f413cf43758ea700aed2f7ddd881/Autodesk Fusion 360.app/Contents/Api/Python/packages/adsk/core.py", line 35298, in selection
    return _core.SelectionCommandInput_selection(self, index)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: 3 : invalid argument index

 I then tried both 0 and 1 in the debugger with the same result.

_pointSelectInput.selection(0)
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/rick/Library/Application Support/Autodesk/webdeploy/production/86922b6f4858f413cf43758ea700aed2f7ddd881/Autodesk Fusion 360.app/Contents/Api/Python/packages/adsk/core.py", line 35298, in selection
    return _core.SelectionCommandInput_selection(self, index)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: 3 : invalid argument index
_pointSelectInput.selection(1)
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/rick/Library/Application Support/Autodesk/webdeploy/production/86922b6f4858f413cf43758ea700aed2f7ddd881/Autodesk Fusion 360.app/Contents/Api/Python/packages/adsk/core.py", line 35298, in selection
    return _core.SelectionCommandInput_selection(self, index)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: 3 : invalid argument index

So I don't understand why it's blowing up when the index is 0 and the SelectionCount is positive.

0 Likes
Message 8 of 12

Jorge_Jaramillo
Collaborator
Collaborator
I'd suggest you to post the piece of code where it fails.
Otherwise it is impossible to guess what the problem could be.
0 Likes
Message 9 of 12

RubyRedRick
Enthusiast
Enthusiast

Well that is the code which is failing.  In a little more context:

    for i in range(0, _pointSelectInput.selectionCount + 1):
            skPoint = _pointSelectInput.selection(i).entity

 

From the debugger I can see the type of _pointSelectInput, its selectionCount, and the value of i

 

/Users/rick/Library/Application Support/Autodesk/Autodesk Fusion 360/API/AddIns/ThreadedInsert
_pointSelectInput
<adsk.core.SelectionCommandInput; proxy of <Swig Object of type 'adsk::core::Ptr< adsk::core::SelectionCommandInput > *' at 0x3b5a06190> >

_pointSelectInput.selectionCount
1

i
0

 

I don't know what other context would help.

0 Likes
Message 10 of 12

Jorge_Jaramillo
Collaborator
Collaborator

Hi,

 

It's  incorrect to add 1 to the superior limit in the range, because in python the first element of an array has index equal to 0.

Try this way:

for i in range(_pointSelectInput.selectionCount):
    app.log(f'{i=} : {_pointSelectInput.selection(i).entity=}')
    skPoint = _pointSelectInput.selection(i).entity

 

Look for the output of the app.log() call in the Text Command window (you can activate it from File > View > Show Text Commands in the menu):

Jorge_Jaramillo_0-1723145944843.png

 

I hope it can help.

 

Regards,

Jorge

 

0 Likes
Message 11 of 12

RubyRedRick
Enthusiast
Enthusiast

That was my goof I was trying to recreate and screwed it up.

ode 

def updateFeature(self):
        for i in range(_pointSelectInput.selectionCount + 1):
            skPoint = _pointSelectInput.selection(i).entity

This is the actual code now.  The same thing is happening.

 

The VS Code debugger show:

 

/Users/rick/Library/Application Support/Autodesk/Autodesk Fusion 360/API/AddIns/ThreadedInsert
_pointSelectInput
<adsk.core.SelectionCommandInput; proxy of <Swig Object of type 'adsk::core::Ptr< adsk::core::SelectionCommandInput > *' at 0x3b6159b30> >

_pointSelectInput.selectionCount
1

i
0

and when I go from the breakpoint.  Fusion 360 shows:

Traceback (most recent call last):
  File "/Users/rick/Library/Application Support/Autodesk/Autodesk Fusion 360/API/AddIns/ThreadedInsert/ThreadedInsert.py", line 514, in notify
    self.updateFeature()
  File "/Users/rick/Library/Application Support/Autodesk/Autodesk Fusion 360/API/AddIns/ThreadedInsert/ThreadedInsert.py", line 297, in updateFeature
    skPoint = _pointSelectInput.selection(i).entity
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rick/Library/Application Support/Autodesk/webdeploy/production/86922b6f4858f413cf43758ea700aed2f7ddd881/Autodesk Fusion 360.app/Contents/Api/Python/packages/adsk/core.py", line 35298, in selection
    return _core.SelectionCommandInput_selection(self, index)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: 3 : invalid argument index
0 Likes
Message 12 of 12

Jorge_Jaramillo
Collaborator
Collaborator
Accepted solution

Please REMOVE the "+1" that you have inside the range() function:

Jorge_Jaramillo_0-1723158864633.png

It is not correct that way because will rich 1 in the second iteration, and _pointSelectInput.selection(1) will raise an exception.

You can also in you code can try to get selections with index 0 and 1, just to make a debug, and see which of the two sentences rise an exception.

 

0 Likes