def execute(self, context): if not context.node: Debug.PrintError("No active node!") return {'CANCELLED'} if context.node.bl_idname != "VRayNodeMtlVRmat": Debug.PrintError("Selected node is not of type VRayNodeMtlVRmat!") return {'CANCELLED'} MtlVRmat = context.node.MtlVRmat if not MtlVRmat.filename: Debug.PrintError("Filepath is not set!") return {'CANCELLED'} filePath = os.path.normpath(bpy.path.abspath(MtlVRmat.filename)) if not os.path.exists(filePath): Debug.PrintError("File doesn't exist!") return {'CANCELLED'} if filePath.endswith(".vrscene"): VRAY_MT_MaterialName.ma_list = GetMaterialsNames(filePath) else: VRAY_MT_MaterialName.ma_list = GetXMLMaterialsNames(filePath) bpy.ops.wm.call_menu(name=VRAY_MT_MaterialName.bl_idname) return {'FINISHED'}
def execute(self, context): node = context.node if not node: Debug.PrintError("No active node!") return {'CANCELLED'} if node.bl_idname != "VRayNodeMtlVRmat": Debug.PrintError("Selected node is not of type VRayNodeMtlVRmat!") return {'CANCELLED'} MtlVRmat = node.MtlVRmat if not MtlVRmat.filename: Debug.PrintError("Filepath is not set!") return {'CANCELLED'} if not MtlVRmat.mtlname: Debug.PrintError("Material is not chosen!") return {'CANCELLED'} filePath = os.path.normpath(bpy.path.abspath(MtlVRmat.filename)) if not os.path.exists(filePath): Debug.PrintError("File doesn't exist!") return {'CANCELLED'} namePrefix = "" vrsceneDict = [] if filePath.endswith(".vrscene"): vrsceneDict = ParseVrscene(filePath) else: vrsceneDict = ParseVrmat(filePath) namePrefix = "/" # Preview data from the file # # for pluginDesc in vrsceneDict: # pluginID = pluginDesc['ID'] # pluginName = pluginDesc['Name'] # pluginAttrs = pluginDesc['Attributes'] # # print("Plugin:") # print(" Type: %s" % pluginID) # print(" Name: %s" % pluginName) # print(" Attributes:") # for attrName in pluginAttrs: # print(" %s = %s" % (attrName, pluginAttrs[attrName])) # Find requested material plugin # mtlName = namePrefix + MtlVRmat.mtlname mtlPlugDesc = NodesImport.getPluginByName(vrsceneDict, mtlName) if not mtlPlugDesc: print("Requested material is not found!") return {'CANCELLED'} ntree = context.space_data.edit_tree # Now lets start creating nodes # mtlNode = NodesImport.createNode(ntree, node, vrsceneDict, mtlPlugDesc) # Connect material output to our node # ntree.links.new(mtlNode.outputs['Material'], node.inputs['Material']) NodesTools.rearrangeTree(ntree, node) return {'FINISHED'}