Coding

You can create your own plugins easily.


Take a look at 'plugins' directory from graphscad. It contains code of all basic plugins provided with Graphscad.

- Files in 'graphscadsettings' directory allow customization of Node and Plugs types
- Node Icons can be created/updated in icons directory (a plugins  called 'node_mycustom.py' will load the icon 'node_mycustom.png').

The code to create a 'Cube' node is very simple. Try to create your own nodes and share the code ;-)

import core as gc


class Node_cube(gc.Dagnode):

    def getcomment(self):
        return 'this node is used to create a cube'

    def getdisplaytype(self):
        return 'object'

    def getinputplugs(self):
        return [
                {'name': 'sizex', 'value': '1', 'type': 'str'},
                {'name': 'sizey', 'value': '1', 'type': 'str'},
                {'name': 'sizez', 'value': '1', 'type': 'str'},
                {'name': 'tx', 'value': '0', 'type': 'str'},
                {'name': 'ty', 'value': '0', 'type': 'str'},
                {'name': 'tz', 'value': '0', 'type': 'str'},
                {'name': 'center', 'value': 'false', 'type': 'str', 'combo' : ['true','false']}
                ]

    def getoutputplugs(self):
        return [{'name': 'object', 'value': '', 'type': 'object'}]


    def evaluate(self):
        x = self.getinputplugvalue('sizex')
        y = self.getinputplugvalue('sizey')
        z = self.getinputplugvalue('sizez')
        tx = self.getinputplugvalue('tx')
        ty = self.getinputplugvalue('ty')
        tz = self.getinputplugvalue('tz')
        center = self.getinputplugvalue('center')
       
        self.modulebegin(self.name,tx=tx,ty=ty,tz=tz)
        self.moduleaddcode('cube(['+x+','+y+','+z+'],center='+center+');')
        self.moduleend()
       
        self.setoutputplugvalue('object', self.modulename(self.name))
        return

2 comments:

  1. Note that the node and icon filenames must be node_xxxxx where xxxxx are lower case characters, digits or underscores. The class it contains must be Node_xxxxx where xxxxx matches the filename.
    By the way, the language is python.

    ReplyDelete
  2. Which version of Python should be used? Is the new v3 okay?

    ReplyDelete

Thanks for your comments. It will help to get a better tool.