ApexScript Userfunction allowed types

   693   12   2
User Avatar
Member
18 posts
Joined: Feb. 2021
Offline
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
Edited by mmassloh_houd - Jan. 23, 2025 13:40:47
User Avatar
Staff
78 posts
Joined: Oct. 2023
Offline
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

Attachments:
apexscript_funtion.hip (148.5 KB)

User Avatar
Member
7923 posts
Joined: July 2005
Online
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')
User Avatar
Member
8986 posts
Joined: July 2007
Offline
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?
Edited by tamte - Jan. 27, 2025 18:46:20
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
18 posts
Joined: Feb. 2021
Offline
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
Edited by mmassloh_houd - Jan. 27, 2025 19:07:36
User Avatar
Member
7923 posts
Joined: July 2005
Online
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?
User Avatar
Member
8986 posts
Joined: July 2007
Offline
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
Edited by tamte - Jan. 27, 2025 19:16:13
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
8986 posts
Joined: July 2007
Offline
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
Edited by tamte - Jan. 27, 2025 19:25:55

Attachments:
h20.5.487_apex_type_autocomplete_missing_functions.gif (37.6 KB)

Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
7923 posts
Joined: July 2005
Online
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().
User Avatar
Member
8986 posts
Joined: July 2007
Offline
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?
Edited by tamte - Jan. 27, 2025 19:48:50
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
18 posts
Joined: Feb. 2021
Offline
Thanks Tamte for your input, for me autocomplete works on object oriented access so far.
User Avatar
Member
7923 posts
Joined: July 2005
Online
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!
User Avatar
Member
7923 posts
Joined: July 2005
Online
This should now be fixed in 20.5.495. Thanks!
  • Quick Links