def execute(self, context): preset_menu_class = getattr(bpy.types, self.preset_menu) preset_type = preset_menu_class.preset_subdir presetSubdir = PathUtils.CreateDirectory(os.path.join(SysUtils.GetUserConfigDir(), "presets")) exportPath = PathUtils.CreateDirectory(os.path.join(presetSubdir, preset_type)) presetName = preset_menu_class.bl_label if self.remove_active else self.name fileName = "%s.vrscene" % LibUtils.CleanString(bpy.path.display_name(presetName)) outputFilepath = os.path.normpath(os.path.join(exportPath, fileName)) if self.remove_active: # NOTE: Remove function is locked to user config directory, # so system settings are safe debug.PrintInfo('Removing preset file: "%s"' % outputFilepath) if not os.path.exists(outputFilepath): return {'CANCELLED'} try: os.remove(outputFilepath) except: debug.PrintError('Error removing preset file: "%s"!' % outputFilepath) # Set default menu name preset_menu_class.bl_label = bpy.path.display_name(preset_type) else: bus = { 'output' : VRayStream.VRaySimplePluginExporter(outputFilepath), 'scene' : context.scene, 'camera' : context.scene.camera, 'preview' : False, } pluginPresetIDs = None if preset_type == 'global': pluginPresetIDs = (pID for pID in sorted(PLUGINS['SETTINGS'])) else: pluginPresetIDs = PresetTypePlugins[preset_type] for pluginID in pluginPresetIDs: pluginModule = PLUGINS_ID.get(pluginID) if pluginModule is None: continue if not hasattr(context.scene.vray, pluginID): continue propGroup = getattr(context.scene.vray, pluginID) ExportUtils.WritePlugin(bus, pluginModule, pluginID.lower(), propGroup, {}) return {'FINISHED'}
def execute(self, context): VRayScene = context.scene.vray VRayDR = VRayScene.VRayDR nodesFilepath = os.path.join(SysUtils.GetUserConfigDir(), "render_nodes.txt") with open(nodesFilepath, 'w') as nodesFile: for item in VRayDR.nodes: item_data = "{item.name}:{item.address}:{item.use:d}:{item.port_override:d}:{item.port:d}".format( item=item) nodesFile.write("%s\n" % item_data) return {'FINISHED'}
def draw(self, context): presetPaths = { os.path.join(SysUtils.GetExporterPath(), "presets", self.preset_subdir), os.path.join(SysUtils.GetUserConfigDir(), "presets", self.preset_subdir), } paths = [] for path in presetPaths: if os.path.exists(path): paths.append(path) if hasattr(self, 'menu_item_save') and self.menu_item_save: op = self.layout.operator('vray.export_asset', text="Save Selected", icon='FILE_TICK') op.asset_type = self.preset_subdir self.layout.separator() self.path_menu(paths)
def execute(self, context): VRayScene = context.scene.vray VRayDR = VRayScene.VRayDR nodesFilepath = os.path.join(SysUtils.GetUserConfigDir(), "render_nodes.txt") if not os.path.exists(nodesFilepath): return {'CANCELLED'} with open(nodesFilepath, 'r') as nodesFile: VRayDR.nodes.clear() for line in nodesFile.readlines(): l = line.strip() if not l: continue item = VRayDR.nodes.add() nodeSetup = l.split(":") # Initial format if len(nodeSetup) == 2: item.name, item.address = nodeSetup # "Use" added elif len(nodeSetup) == 3: item.name = nodeSetup[0] item.address = nodeSetup[1] item.use = int(nodeSetup[2]) # Port override added elif len(nodeSetup) == 5: item.name = nodeSetup[0] item.address = nodeSetup[1] item.use = int(nodeSetup[2]) item.port_override = int(nodeSetup[3]) item.port = int(nodeSetup[4]) VRayDR.nodes_selected = 0 return {'FINISHED'}
def execute(self, context): if not self.asset_name: self.report({'ERROR'}, "Asset name is not set!") return {'CANCELLED'} presetsPath = PathUtils.CreateDirectory(os.path.join(SysUtils.GetUserConfigDir(), "presets")) userNodeAssetPath = PathUtils.CreateDirectory(os.path.join(presetsPath, self.asset_type)) fileName = "%s.vrscene" % LibUtils.CleanString(bpy.path.display_name(self.asset_name)) outputFilepath = os.path.normpath(os.path.join(userNodeAssetPath, fileName)) # Create exporter (output) o = VRayStream.VRaySimplePluginExporter(outputFilepath) exporter = _vray_for_blender.init( engine = 0, context = bpy.context.as_pointer(), scene = bpy.context.scene.as_pointer(), data = bpy.data.as_pointer(), mainFile = o.output, objectFile = o.output, envFile = o.output, geometryFile = o.output, lightsFile = o.output, materialFile = o.output, textureFile = o.output, drSharePath = "", ) # Get selected nodes ntree = context.space_data.edit_tree selectedNode = context.selected_nodes[0] if selectedNode.bl_idname == 'VRayNodeRenderChannels': pluginNames = [] for inSock in selectedNode.inputs: pluginNames.append(NodesExport.WriteConnectedNode(None, ntree, inSock)) pluginName = "List(%s)" % ",".join(pluginNames) else: if selectedNode.bl_idname == 'VRayNodeOutputMaterial': selectedNode = NodesExport.GetConnectedNode(ntree, selectedNode.inputs['Material']) pluginName = _vray_for_blender.exportNode( ntree.as_pointer(), selectedNode.as_pointer(), None ) # Write fake Asset node o.set('MAIN', 'Asset', self.asset_type.capitalize()) o.writeHeader() o.writeAttibute(self.asset_type, pluginName) o.writeFooter() o.done() _vray_for_blender.exit(exporter) return {'FINISHED'}