37 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
from lnx.logicnode.lnx_nodes import *
 | 
						|
 | 
						|
 | 
						|
class ReadJsonNode(LnxLogicTreeNode):
 | 
						|
    """Reads the given JSON file and returns its content.
 | 
						|
 | 
						|
    @input File: the asset name of the file as used by Kha.
 | 
						|
    @input Use cache: if unchecked, re-read the file from disk every
 | 
						|
        time the node is executed. Otherwise, cache the file after the
 | 
						|
        first read and return the cached content.
 | 
						|
 | 
						|
    @output Loaded: activated after the file has been read.
 | 
						|
    @output Not Loaded: If the file doesn't exist the output is activated.
 | 
						|
    @output Dynamic: the content of the file.
 | 
						|
 | 
						|
    @seeNode Write JSON
 | 
						|
    """
 | 
						|
    bl_idname = 'LNReadJsonNode'
 | 
						|
    bl_label = 'Read JSON'
 | 
						|
    lnx_section = 'file'
 | 
						|
    lnx_version = 2
 | 
						|
 | 
						|
    def lnx_init(self, context):
 | 
						|
        self.add_input('LnxNodeSocketAction', 'In')
 | 
						|
        self.add_input('LnxStringSocket', 'File')
 | 
						|
        self.add_input('LnxBoolSocket', 'Use cache', default_value=1)
 | 
						|
 | 
						|
        self.add_output('LnxNodeSocketAction', 'Loaded')
 | 
						|
        self.add_output('LnxNodeSocketAction', 'Not loaded')
 | 
						|
        self.add_output('LnxDynamicSocket', 'Dynamic')
 | 
						|
 | 
						|
    def get_replacement_node(self, node_tree: bpy.types.NodeTree):
 | 
						|
        if self.lnx_version not in (0, 1):
 | 
						|
            raise LookupError()
 | 
						|
 | 
						|
        return NodeReplacement.Identity(self)
 |