How to access functions and structs written in .kl file to your canvas graph

him_mehim_me Posts: 16
edited June 2016 in Tutorials

I have written some utility functions and structs in a kl file. Now I am making a node inside canvas that is supposed to call a function written inside a separate kl file. How do I refer them inside canvas?

I tried to copy paste the structs from kl file to function editor in canvas but I got this error "cannot declare new types in DFG node"

Tagged:

Comments

  • malbrechtmalbrecht Fabric for Houdini Posts: 752 ✭✭✭

    Moin,

    if you want to use your own structs, you need to put them into an extension. Set up your own extensions directory and add that to Fabric's extension path environment variable FABRIC_EXTS_PATH. Have a look at the builtin extensions in Fabric's main directory about how to set up the json config file.
    Having done that you can call your function(s) and use your structs from inside a Canvas "function node" - and make a preset from that node afterwards.

    I hope this helps, if not, let me know - I am only looking for good reasons to do some video tutorials :wink:

    Marc


    Marc Albrecht - marc-albrecht.de - does things.

  • him_mehim_me Posts: 16

    Thanks for reply!
    I did as you mentioned and it is getting registered when canvas is getting loaded (from logs) but my folder name is not coming when the canvas is loading those extensions (from logs) and when using the struct from my extension in DFG it says type not registered.

  • malbrechtmalbrecht Fabric for Houdini Posts: 752 ✭✭✭

    Hmm ... not quite sure what might be going wrong, could you post your canvas boot log and tell where you installed the extension?


    Marc Albrecht - marc-albrecht.de - does things.

  • borjaborja Administrator, Fabric Employee Posts: 480 admin

    Hi @him_me

    As Marc mentions, would you mind to show how are you registering the extension, and how are you trying to use their structs inside canvas?

    Borja Morales
    Technical Product Manager
    Fabric Software Inc.

  • him_mehim_me Posts: 16

    E:\FabricEngine-2.2.1-Windows-x86_64\FabricEngine-2.2.1-Windows-x86_64>canvas

    WARNING: CANVAS IS DEPRECATED AND WILL BE REMOVED IN THE NEXT VERSION. PLEASE USE CANVAS.PY INSTEAD


    Will autosave to C:\Users\himan\AppData\Roaming\Fabric Engine\autosave\autosave.12000.canvas every 30 seconds
    [FABRIC:MT] Fabric Engine version 2.2.1 (Jun 09 2016 14:01:18 UTC)
    [FABRIC:MT] Loading DFG presets from E:\FabricEngine-2.2.1-Windows-x86_64\FabricEngine-2.2.1-Windows-x86_64\Presets\DFG
    [FABRIC:MT] Loading DFG presets from C:\Users\himan\Fabric\Presets
    [FABRIC:MT] Registered extensions {Alembic:1.0.0,AlembicWrapper:1.4.0,Animation:1.1.0,AttributeHelpers:1.0.1,Bullet:1.0.2,BulletHelpers:1.0.0,Characters:1.1.0,Containers:1.1.1,DFGHelpers,DFGWrapper:1.1.0,FabricInterfaces:1.1.0,FabricSynchronization:1.1.0,Fbx:1.1.0,FbxHelpers:1.0.2,FileIO:1.3.0,Geometry:1.4.0,Images:1.0.2,InlineDrawing:1.4.0,JSON:1.0.0,Manipulation:1.1.0,Math:1.3.0,FabricOBJ:1.1.0,FabricOGL:1.1.0,OpenImageIO:1.0.2,OSOGL:1.1.0,Parameters:1.0.0,Sampling2D:1.0.0,Singletons:1.1.0,FabricStatistics:1.1.0,Util:1.2.0} in directory: E:\FabricEngine-2.2.1-Windows-x86_64\FabricEngine-2.2.1-Windows-x86_64\Exts
    [FABRIC:MT] Ignored extension directory 'E:\FabricEngine-2.2.1-Windows-x86_64\FabricEngine-2.2.1-Windows-x86_64\Tests\Exts': unable to open directory 'E:\FabricEngine-2.2.1-Windows-x86_64\FabricEngine-2.2.1-Windows-x86_64\Tests\Exts': The system cannot find the path specified. (code 3 [0x3])
    [FABRIC:MT] IRCache: Not pruning since last prune was less than 24 hours ago
    [FABRIC:MT] Loaded extension Math in 147.250ms (cached)
    [FABRIC:MT] Loaded extension Singletons in 33.768ms (cached)
    [FABRIC:MT] Loaded extension Parameters in 52.693ms (cached)
    [FABRIC:MT] Loaded extension FabricSynchronization in 8.215ms (cached)
    [FABRIC:MT] Loaded extension Util in 53.244ms (cached)
    [FABRIC:MT] Loaded extension FabricStatistics in 46.549ms (cached)
    [FABRIC:MT] Loaded extension Containers in 255.773ms (cached)
    [FABRIC:MT] Loaded extension Geometry in 726.119ms (cached)
    [FABRIC:MT] Loaded extension FabricOGL in 104.667ms (cached)
    [FABRIC:MT] Loaded extension OpenImageIO in 208.447ms (cached)
    [FABRIC:MT] Loaded extension FabricInterfaces in 6.147ms (cached)
    [FABRIC:MT] Loaded extension FileIO in 30.061ms (cached)
    [FABRIC:MT] Loaded extension InlineDrawing in 480.712ms (cached)
    [FABRIC:MT] Loaded extension JSON in 21.854ms (cached)
    [FABRIC:MT] Loaded extension Manipulation in 145.481ms (cached)
    [FABRIC:MT] Fabric Engine version 2.2.1 (Jun 09 2016 14:01:18 UTC)
    [FABRIC:MT] Loading DFG presets from E:\FabricEngine-2.2.1-Windows-x86_64\FabricEngine-2.2.1-Windows-x86_64\Presets\DFG
    [FABRIC:MT] Loading DFG presets from C:\Users\himan\Fabric\Presets
    [FABRIC:MT] Registered extensions {Alembic:1.0.0,AlembicWrapper:1.4.0,Animation:1.1.0,AttributeHelpers:1.0.1,Bullet:1.0.2,BulletHelpers:1.0.0,Characters:1.1.0,Containers:1.1.1,DFGHelpers,DFGWrapper:1.1.0,FabricInterfaces:1.1.0,FabricSynchronization:1.1.0,Fbx:1.1.0,FbxHelpers:1.0.2,FileIO:1.3.0,Geometry:1.4.0,Images:1.0.2,InlineDrawing:1.4.0,JSON:1.0.0,Manipulation:1.1.0,Math:1.3.0,FabricOBJ:1.1.0,FabricOGL:1.1.0,OpenImageIO:1.0.2,OSOGL:1.1.0,Parameters:1.0.0,Sampling2D:1.0.0,Singletons:1.1.0,FabricStatistics:1.1.0,Util:1.2.0} in directory: E:\FabricEngine-2.2.1-Windows-x86_64\FabricEngine-2.2.1-Windows-x86_64\Exts
    [FABRIC:MT] Ignored extension directory 'E:\FabricEngine-2.2.1-Windows-x86_64\FabricEngine-2.2.1-Windows-x86_64\Tests\Exts': unable to open directory 'E:\FabricEngine-2.2.1-Windows-x86_64\FabricEngine-2.2.1-Windows-x86_64\Tests\Exts': The system cannot find the path specified. (code 3 [0x3])
    [FABRIC:MT] IRCache: Not pruning since last prune was less than 24 hours ago
    [FABRIC:MT] Loaded extension Math in 147.250ms (cached)
    [FABRIC:MT] Loaded extension Singletons in 33.768ms (cached)
    [FABRIC:MT] Loaded extension Parameters in 52.693ms (cached)
    [FABRIC:MT] Loaded extension FabricSynchronization in 8.215ms (cached)
    [FABRIC:MT] Loaded extension Util in 53.244ms (cached)
    [FABRIC:MT] Loaded extension FabricStatistics in 46.549ms (cached)
    [FABRIC:MT] Loaded extension Containers in 255.773ms (cached)
    [FABRIC:MT] Loaded extension Geometry in 726.119ms (cached)
    [FABRIC:MT] Loaded extension FabricOGL in 104.667ms (cached)
    [FABRIC:MT] Loaded extension OpenImageIO in 208.447ms (cached)
    [FABRIC:MT] Loaded extension FabricInterfaces in 6.147ms (cached)
    [FABRIC:MT] Loaded extension FileIO in 30.061ms (cached)
    [FABRIC:MT] Loaded extension InlineDrawing in 480.712ms (cached)
    [FABRIC:MT] Loaded extension JSON in 21.854ms (cached)
    [FABRIC:MT] Loaded extension Manipulation in 145.481ms (cached)

  • him_mehim_me Posts: 16

    Sampling2D:1.0.0 is the extension that I put in the "\Ext\Builtin\" dir

  • him_mehim_me Posts: 16

    contents of fpm file is exactly same (in structure) as other ext. I have just one .kl file inside this dir. (Not sure but do I have to run kl2dfg in this?)

  • malbrechtmalbrecht Fabric for Houdini Posts: 752 ✭✭✭

    Hi,

    I suggest setting up an extra directory for your own extensions, not using the "builtin", first off to make debugging easier (like right now), second: If you update the Fabric installation, with an external directory you don't have to take care of moving/copying your own extensions over.

    That said: Try "requiring" your extension (from the little text input gadget above the node-canvas), does that give you an error? Be sure to use the right uppercasing.

    KL2DFG is only needed when you want to create presets from your functions right away. So, no, you don't need to run it, if you want to use your extension from inside function-nodes.

    Marc


    Marc Albrecht - marc-albrecht.de - does things.

  • him_mehim_me Posts: 16

    Hey Marc,
    Thanks for your suggestions. I did the quick rearrangement and test as you mentioned.
    here is the output:

    [FABRIC:MT] Registered extension {Sampling2D:1.0.0} in directory: E:\fabric_ext
    [FABRIC:MT] IRCache: Not pruning since last prune was less than 24 hours ago
    [FABRIC:MT] Loaded extension Math in 145.092ms (cached)
    [FABRIC:MT] Loaded extension Singletons in 3.114ms (cached)
    [FABRIC:MT] Loaded extension Parameters in 52.475ms (cached)
    [FABRIC:MT] Loaded extension FabricSynchronization in 7.714ms (cached)
    [FABRIC:MT] Loaded extension Util in 21.917ms (cached)
    [FABRIC:MT] Loaded extension FabricStatistics in 17.965ms (cached)
    [FABRIC:MT] Loaded extension Containers in 265.367ms (cached)
    [FABRIC:MT] Loaded extension Geometry in 723.613ms (cached)
    [FABRIC:MT] Loaded extension FabricOGL in 76.586ms (cached)
    [FABRIC:MT] Loaded extension OpenImageIO in 13.518ms (cached)
    [FABRIC:MT] Loaded extension FabricInterfaces in 6.498ms (cached)
    [FABRIC:MT] Loaded extension FileIO in 28.949ms (cached)
    [FABRIC:MT] Loaded extension InlineDrawing in 507.198ms (cached)
    [FABRIC:MT] Loaded extension JSON in 21.825ms (cached)
    [FABRIC:MT] Loaded extension Manipulation in 148.064ms (cached)
    [FABRIC:MT] [Sampling2D] Error encountered while loading extension; extension disabled
    [FABRIC:MT] [Sampling2D] Error description:
    unable to open 'Sampling2D-Windows-x86_64.dll': The specified module could not be found. (code 126 [0x7E])
    unable to open 'Sampling2D.dll': The specified module could not be found. (code 126 [0x7E])
    unable to open 'Sampling2D': The specified module could not be found. (code 126 [0x7E])
    [FABRIC:MT] Loaded extension Sampling2D in 9.670ms
    [FABRIC:MT] unable to load extension Sampling2D:1.0.0

  • malbrechtmalbrecht Fabric for Houdini Posts: 752 ✭✭✭

    looks like there is an error in the extension, so it gets disabled right on start - that's a behavior of Canvas I have been moaning about a lot :-)

    What I usually do is create an empty function that has all properties set up (input/output ports) the way I know I want them, then boot up Canvas and THEN fill the function (in the extension directory in the KL file) with its actual content, use a node in Canvas that addresses the extension and right-mouse-button-menu "Reload Extensions". This way I can deal with errors in the extension without having to restart Canvas for every single typo I make (and I get paid very well for making lots of silly typos).

    If you want to post the extension as such, go ahead, I'll be happy to have a look!

    I hope this helps!

    Marc


    Marc Albrecht - marc-albrecht.de - does things.

  • him_mehim_me Posts: 16

    Can I load an empty kl file as an extension? I have a one struct and its 3 methods. I removed all the method and kept the struct definition but I am getting the same error?? Am I missing some boilerplate code to achieve this

  • him_mehim_me Posts: 16

    All this struct and code is I tested with kl tool. I got the required output so then I started to port them to DFG to visualize the output.

  • EricTEricT Administrator, Moderator, Fabric Employee Posts: 304 admin

    @him_me

    Can you start a command line via a bat or sh file that sources the fabric environment.bat / .sh and also adds your custom extension to FABRIC_EXTS_PATH.

    Then create a Sampling2D_Test.kl file that contains this:

    require Sampling2D;
    
    operator entry(){
      // Insert simple instance of your struct here
    }
    

    Then from the command prompt navigate to the directory with the Sampling2D_Test.kl file and run the following:

    kl Sampling2D_Test.kl --loadexts

    See if that prints out any errors.

    Eric Thivierge
    Kraken Developer
    Kraken Rigging Framework

  • malbrechtmalbrecht Fabric for Houdini Posts: 752 ✭✭✭

    @him_me - it might just be a typo in the way you construct your struct, that would explain the error. If you don't want to post the original code, could you strip it down to the basics that give you an error and post it here?

    Marc


    Marc Albrecht - marc-albrecht.de - does things.

  • him_mehim_me Posts: 16

    Hi Eric,
    Its giving the same output. I have attached all the files needed to reproduce it. Please let me know if need some thing else.
    Thanks,

    [FABRIC:MT] Ignored extension directory 'E:\FabricEngine-2.2.1-Windows-x86_64\FabricEngine-2.2.1-Windows-x86_64\Tests\Exts': unable to open directory 'E:\FabricEngine-2.2.1-Windows-x86_64\FabricEngine-2.2.1-Windows-x86_64\Tests\Exts': The system cannot find the path specified. (code 3 [0x3])
    [FABRIC:MT] Registered extension {Sampling2D:1.0.0} in directory: E:\fabric_ext
    [FABRIC:MT] IRCache: Not pruning since last prune was less than 24 hours ago
    [FABRIC:MT] Codegenned extension Math:1.3.0 in 17.183ms
    [FABRIC:MT] Loaded extension Math in 145.591ms (cached)
    [FABRIC:MT] Trying to load 'E:\fabric_ext\Sampling2D\Sampling2D-Windows-x86_64.dll'
    [FABRIC:MT] Trying to load 'E:\fabric_ext\Sampling2D\Sampling2D.dll'
    [FABRIC:MT] Trying to load 'E:\fabric_ext\Sampling2D\Sampling2D'
    [FABRIC:MT] [Sampling2D] Error encountered while loading extension; extension disabled
    [FABRIC:MT] [Sampling2D] Error description:
    unable to open 'Sampling2D-Windows-x86_64.dll': The specified module could not be found. (code 126 [0x7E])
    unable to open 'Sampling2D.dll': The specified module could not be found. (code 126 [0x7E])
    unable to open 'Sampling2D': The specified module could not be found. (code 126 [0x7E])
    [FABRIC:MT] Loaded extension Sampling2D in 11.340ms
    E:\FabricEngine-2.2.1-Windows-x86_64\Sampling2D_Test.kl:1:9: error: extension 'Sampling2D' has been disabled

  • him_mehim_me Posts: 16

    @malbrecht saw your comment after posting above. I did the same. I posted the basic set to reproduce it.

  • malbrechtmalbrecht Fabric for Houdini Posts: 752 ✭✭✭

    You are specifying a library "Sampling2D", that is not included in the files you attached.

    Try this json file instead (leaving out the lib-specification):

    {
      "version": "1.0.0",
      "code": [
        "Grid.kl"
      ],
    }
    

    Marc Albrecht - marc-albrecht.de - does things.

  • him_mehim_me Posts: 16

    :o Thanks Marc!!!

Sign In or Register to comment.