Apex Script:Component: How to use subnets

   164   4   1
User Avatar
Member
604 posts
Joined: Nov. 2005
Online
Hello
I want to use Apex scriot for modifyin existing Apex graphs and also tied to use subnets to keep things tidy. With apex graph I get this results.



I end with this graph and subnet.



with a apex script like this:

I end up with this , obviously doing something wrong




So what I the correct way to use the addSubnet function. I do not want a graph input in the result, but I can not get addNode to work inside the subnet

thank You for Your time
Martin

Attachments:
ApexGraph.jpg (172.1 KB)
ApexGraph_result.jpg (127.0 KB)
ApexGraph_result_subnet.jpg (86.0 KB)
ApexScript_result.jpg (126.4 KB)
ApexScript_result_subnet.jpg (106.9 KB)
ApexScript.jpg (67.8 KB)

User Avatar
Member
284 posts
Joined: March 2011
Online
It's not correct. Your function (subnet) was designed to work on the code that generates the other graph (rig), not in the rig itself. One clue is that it needs a graph input.
You can design your subnet as if it were rig-code (with matrices and all the good stuff). Then you add your node to the target graph using addSubnet (to the graph). It the function was designed to work on current code (and thus, generate stuff in the target graph) you should use the function directly:
Subnet()

In the first picture, I'm using a custom function directly on the code (like right above). So the function is called directly - in my case:
graph, refXform = hcfx.GetRefXformHCFX(graph, targetName)
In the second image, I'm adding a custom function (subnet) into the target graph, thus, I'm using the addNode to add that to the graph.
refXformNode, exists = graph.findOrAddNode(f"{jointName}_ref_xform", "hcfx::RefXformHCFX", __name='create_ref_xform_node')

Finally, in the target graph (rig), you can see the custom function (3rd image) added as a subnet. This is the code for that node:
def RefXformHCFX(restlocal: Matrix4,
                 parent: Matrix4,
                 t: Vector3,
                 r: Vector3,
                 s: Vector3) -> Matrix4[xform]:

    combinedParmXform: Matrix4 = restlocal.rig.combineParmTransform(t, r, s, mode=7, __name='combine_parm_transform')
    combinedXform: Matrix4 = combinedParmXform * parent

    return combinedXform

As you can see, the code above is working directly on the rig's logic; that's why it works on transforms (matrices) and so on...
(of course, that doesn't mean you shouldn't work on matrices on the code targeting the graph...)

Attachments:
graph.png (187.8 KB)
graph2.png (96.3 KB)
graph3.png (214.4 KB)

User Avatar
Member
604 posts
Joined: Nov. 2005
Online
Thank You for the detailed explanation.


I still wonder how to create nodes in a subnet. The example code creates nodes in a subnet.
def test(a: vector3, b: float) -> tuple(vector3, float):
a = a * b
b = b + 1.0
return a, b

my_subnet = graph.addSubnet(test, 'my_test')
Result in the subnet:



But how do I create a TransformObject for example or any apex node in a subnet?

Martin

Attachments:
subnet.png (136.2 KB)

User Avatar
Member
284 posts
Joined: March 2011
Online
sanostol
Thank You for the detailed explanation.


I still wonder how to create nodes in a subnet. The example code creates nodes in a subnet.
def test(a: vector3, b: float) -> tuple(vector3, float):
a = a * b
b = b + 1.0
return a, b

my_subnet = graph.addSubnet(test, 'my_test')
Result in the subnet:
Image Not Found



But how do I create a TransformObject for example or any apex node in a subnet?

Martin

you should save a bookmark for this page: Apex Nodes [www.sidefx.com]. It has all apex functions, and there are several to work with subnets.
You can either use addNodeToSubnet to add a node to an existing subnet, create the node and then add it to the subnet, by getting the contents array, appending the new node, then setting the new content with setSubnetContents; or you can add all nodes and then pack them as a subnet.
But all of these functions will make your code more difficult to write. In my experience, the best approach is to define the function with everything you'll need upfront.
User Avatar
Member
604 posts
Joined: Nov. 2005
Online
Thank You,
I was looking more for something like this

def test():
node = TransformObject(__name='node')

graph.addSubnet(test, "test")

It sometimes helps to create the nework You need in a apex graph.
Then plug it in the second input of a Apex Script node and in the decompile tab set it to second imput
Then hit Create Snippet

it will return Your graph as code. subnets and all for You to learn or build with
maybe it helps someone

Martin
  • Quick Links