検索 - User list
Full Version: ApexScript Userfunction allowed types
Root » Rigging » ApexScript Userfunction allowed types
mmassloh_houd
Hi everyone,

is it possible to do sth like this in ApexScript:
def test(a: ApexNodeID):
    b = a.name()
    return b


or even
def test(a: ApexNodeIDArray):
    then do something with it like printing all names as string etc for debugging
What would be the syntax?

Cheers and thanks,

Max
william_harley
That is exactly the syntax.

The apex script node needs to be set up in a specific way in order to compile the output.
Here Im am using the log viewer to view the debug output from apex.
Image Not Found
edward
For the first method, you'd need also the graph for the nodeid to determine it's name. Here's a quick example:
def exampleGraph() -> Float:
    value = Float(__name='value')
    return value

graph = exampleGraph
nodeid = apex.graph.findFirstNode(graph=graph, pattern='v*')
name = graphutils.nodeName(graph=graph, nodeid=nodeid)
BindOutput(name=name, __name='output')
tamte
mmassloh_houd
is it possible to do sth like this in ApexScript:
def test(a: ApexNodeID):
    b = a.name()
    return b
...

here is an example showing that you can use types like ApexNodeID or ApexGraphHandle in your custom functions

def test( graph: ApexGraphHandle, node_id: ApexNodeID) -> string :
    name = "hardcoded_prefix_"
    name += graph.nodeName( node_id )
    return name
    

graph: ApexGraphHandle = BindInput()   
node_id: ApexNodeID = BindInput()
name = test( graph, node_id )
BindOutput( name )


also some questions for Devs:
graph.nodeName( node_id )
works, but
ApexGraphHandle. autocomplete doesn't show that function, which makes it very difficult to discover Object oriented syntax, especially since that function is not even in apex.graph, but in apex.graphutils module
but even functions from apex.graph module don't show up in autocomplete, like the mentioned findFirstNode()
is this a known current autocomplete limitation similar to variables not being to show autocomplete at all?
mmassloh_houd
Hi william/edward,

thanks for your inputs. I was missing one thing for my code to work fine. I roughly understand the syntax now and was missing that the function was asking for the graph itself to properly find the items in an ApexNodeIDArray.
def printnames(nodes:ApexNodeIDArray, g:ApexGraphHandle) -> String:
    test = ""
    for node in nodes:
        name = node.name()
        test += "__"+name
    return test
By the way, is this the correct way to append strings, when I try to use the somestring.add(), which is available within the graph nodes, I get an error telling me that there is no add function available?

Thanks a lot, i really appreciate how helpful the community is.

Cheers,

Max
edward
tamte
ApexGraphHandle. autocomplete doesn't show that function, which makes it very difficult to discover Object oriented syntax, especially since that function is not even in apex.graph, but in apex.graphutils module

This is hard unfortunately because the types of the variables being completed are not known: The parameter code editor doesn't run any of the code being typed in. This is the same if you did something like "geo = hou.Geometry(); geo.<complete>" in a regular Python SOP. It only works if you're in a Python Shell where we've actually executed "geo = hou.Geometry()".

tamte
but even functions from apex.graph module don't show up in autocomplete, like the mentioned findFirstNode()
is this a known current autocomplete limitation similar to variables not being to show autocomplete at all?

This is a separate issue that should have been fixed in 20.5.482. Are you in an earlier build?
tamte
edward
This is hard unfortunately because the types of the variables being completed are not known: The parameter code editor doesn't run any of the code being typed in. This is the same if you did something like "geo = hou.Geometry(); geo.<complete>" in a regular Python SOP. It only works if you're in a Python Shell where we've actually executed "geo = hou.Geometry()".
I don't believe it's the same issue since in APEX script we use type hints quite a lot (if not all the time as it tends to complain if they are not provided, suggesting that APEX Script aims to emulate strongly typed language)
so I believe the types can be assumed ahead of time in case the hints are clearly provided to aid with helpful autocomplete
tamte
edward
This is a separate issue that should have been fixed in 20.5.482. Are you in an earlier build?
I am in 20.5.487
edward
tamte
I believe the types can be assumed ahead of time in case the hints are clearly provided to aid with helpful autocomplete

That still requires parsing everything in the parm to determine the types. Perhaps not insurmountable but that is why they don't autocomplete anyways.

tamte
I am in 20.5.487

Hmm, I just tried this and it works in my 20.5.491 (just my development builds are updated nightly). I did: "g = apex.graph.find" and the menu that came up included findFirstNode().
tamte
edward
Hmm, I just tried this and it works in my 20.5.491 (just my development builds are updated nightly). I did: "g = apex.graph.find" and the menu that came up included findFirstNode().
apex.graph.find
and
apex.graphutils.node
will show autocomplete
I'm talking about Object oriented access to those function from the type itself
ApexGraphHandle.
or does that run into similar parsing issues as if I wanted to autocomplete from variable with such type as a hint?
mmassloh_houd
Thanks Tamte for your input, for me autocomplete works on object oriented access so far.
edward
tamte
I'm talking about Object oriented access to those function from the type itself
ApexGraphHandle.
or does that run into similar parsing issues as if I wanted to autocomplete from variable with such type as a hint?

Ah sorry, for some reason, when I was looking at this before, the GIF didn't show (maybe it was because of Safari?). It seems that findFirstNode() is misplaced for autocompletion for the object-based syntax. It's currently put as a method for ApexNodeID when it should be a method for ApexGraphHandle. I'll look into this, thanks!
edward
This should now be fixed in 20.5.495. Thanks!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB