我们从Python开源项目中,提取了以下25个代码示例,用于说明如何使用bpy.props.StringProperty()。
def _create_id_property(field_name): def fn(*args, **kwargs): """ the main class. """ value_key = _create_value_key(kwargs["name"]) validator = kwargs.pop("validator", None) kwargs["get"] = create_getter(field_name, value_key) kwargs["set"] = create_setter(field_name, value_key, validator) payload = { "field_name": field_name, } kwargs["description"] = json.dumps(payload) prop = p.StringProperty(*args, **kwargs) return prop return fn
def register(): from bpy.types import Scene from bpy.props import (BoolProperty, IntProperty, StringProperty, ) Scene.pc_pc2_rotx = BoolProperty(default=True, name="Rotx = 90") Scene.pc_pc2_world_space = BoolProperty(default=True, name="World Space") Scene.pc_pc2_modifiers = BoolProperty(default=True, name="Apply Modifiers") Scene.pc_pc2_subsurf = BoolProperty(default=True, name="Turn Off SubSurf") Scene.pc_pc2_start = IntProperty(default=0, name="Frame Start") Scene.pc_pc2_end = IntProperty(default=100, name="Frame End") Scene.pc_pc2_group = StringProperty() Scene.pc_pc2_folder = StringProperty(default="Set me Please!") Scene.pc_pc2_exclude = StringProperty(default="*") bpy.utils.register_module(__name__) update_panel(None, bpy.context)
def register(): for c in classes: register_class(c) bpy.app.handlers.render_complete.append(slot_handler) bpy.types.Scene.record_settings = BoolProperty( name = "Record Render Settings", description="After eacher render save the render settings in current render slot", default=False) bpy.types.Scene.master_scene = BoolProperty( name = "Master Scene", description="When working with multiple scenes, make this the master scene to copy settings from", default=False) bpy.types.WindowManager.recent_render = StringProperty( name = "Recently Rendered Slot", description = "Shows the most recently rendered slot", default="" ) wm = bpy.context.window_manager km = wm.keyconfigs.addon.keymaps.new(name='Image', space_type='IMAGE_EDITOR') kmi = km.keymap_items.new('scene.render_slot_restore', 'J', 'PRESS', ctrl=True)
def setPropKeys(args): global theProperty if theProperty is None: return (name, tip, value) = theProperty if len(args) >= 2 and not isinstance(value, bool): if "BOOLEAN" in args[1]: value = bool(value) else: tip = tip + "," + args[1].replace(":", "=").replace('"', " ") #expr = "bpy.types.Object.%s = %sProperty(%s)" % (name, proptype, tip) if isinstance(value, bool): prop = BoolProperty(tip) elif isinstance(value, int): prop = IntProperty(tip) elif isinstance(value, float): prop = FloatProperty(tip) elif isinstance(value, string): prop = StringProperty(tip) setattr(bpy.types.Object, name, prop) theProperty = None
def register(): WindowManager.assethub_component = EnumProperty(name="Component", items = components_from_assethub) WindowManager.assethub_tag = EnumProperty(name="Tag", default=None, items = tags_from_assethub) WindowManager.assethub_asset = EnumProperty(name="Asset", items = previews_from_assethub) WindowManager.assethub_asset_url = StringProperty(name="Asset URL") client.Component.register("blender", "sverchok-sn1", SverchokSn1) client.Component.register("blender", "sverchok-layout", SverchokLayout) bpy.utils.register_class(ImportOperator) bpy.utils.register_class(SettingsPanel) bpy.utils.register_class(ImportPanel) bpy.utils.register_class(PostScriptPanel) bpy.utils.register_class(PostScriptOperator) bpy.utils.register_class(BrowseAssetOperator) bpy.types.INFO_MT_file_import.append(menu_func)
def register(): bpy.types.Object.ktx_object_id = bpy.props.StringProperty(name="KTX Object ID", description="Unique ID to 'link' one object to multiple meshes") bpy.types.Mesh.ktx_mesh_id = bpy.props.StringProperty(name="KTX Mesh ID", description="Unique ID to 'link' multiple meshes to one object") bpy.types.Scene.ktx_defpin = bpy.props.BoolProperty(name="Auto Pinning", description="When creating a new version, set pinning to ON automatically (FAKE_USER=TRUE)", default=False) bpy.utils.register_module(__name__)
def register(): bpy.utils.register_class(Dynapanel) bpy.utils.register_class(dsky) bpy.types.Scene.dynamic_sky_name = StringProperty( name="", default="Dynamic" )
def register(): bpy.utils.register_module(__name__) Scene = bpy.types.Scene for cls in View3DEditProps, SequencerEditProps: setattr(Scene, cls._PROP_STORAGE_ID, StringProperty( name="Scene Name", description="Name of POV-Ray scene to create. Empty " \ "name will use the name of the blend file", default=cls._PROP_STORAGE_DEFAULT, maxlen=1024), )
def register(NetRenderSlave): NetRenderSlave.name = StringProperty( name="Name of the slave", description="", maxlen = 64, default = "")
def invoke(self, context, event): return context.window_manager.invoke_props_dialog(self) # class CreateNewSegment(bpy.types.Operator): # """ # :term:`operator` for creating a new segment in the robot model. # # # """ # bl_idname = config.OPERATOR_PREFIX + "createbone" # bl_label = "Create new Bone" # # boneName = StringProperty(name="Enter new bone name:") # # def execute(self, context): # try: # parentBoneName = context.active_bone.name # except: # parentBoneName = None # # if not context.active_object.type == 'ARMATURE': # raise Exception("BoneCreationException") # # return{'FINISHED'} # armatureName = context.active_object.name # armatures.createBone(armatureName, self.boneName, parentBoneName) # # designer.ops.select_segment(boneName=self.boneName) # armatures.updateKinematics(armatureName, self.boneName) # # # TODO: set parentMode according to own parent # return {'FINISHED'} # # def invoke(self, context, event): # return context.window_manager.invoke_props_dialog(self)
def register(): bpy.types.Scene.MhFeetOnGround = BoolProperty(name="Feet on Ground", description="Model was exported with feet on ground. Checking this causes\nroot bone location translation to be cleared.", default=False) bpy.types.Scene.MhNoLocation = BoolProperty(name="No Location Translation", description="Some Expressions have bone translation on locked bones.\nChecking this causes it to be cleared. When false,\nALT-G will NOT clear these.", default=False) bpy.types.Scene.MhExprFilterTag = StringProperty(name="Tag:", description="", default="") bpy.utils.register_module(__name__)
def register(): Scene.archipack_progress = FloatProperty( options={'SKIP_SAVE'}, default=-1, subtype='PERCENTAGE', precision=1, min=-1, soft_min=0, soft_max=100, max=101, update=update) Scene.archipack_progress_text = StringProperty( options={'SKIP_SAVE'}, default="Progress", update=update) global info_header_draw info_header_draw = bpy.types.INFO_HT_header.draw def info_draw(self, context): global info_header_draw info_header_draw(self, context) if (context.scene.archipack_progress > -1 and context.scene.archipack_progress < 101): self.layout.separator() text = context.scene.archipack_progress_text self.layout.prop(context.scene, "archipack_progress", text=text, slider=True) bpy.types.INFO_HT_header.draw = info_draw
def register(): bpy.types.EditBone.bdst_sign = bpy.props.StringProperty(name="bone orientation sign") bpy.types.EditBone.bdst_center_point = bpy.props.FloatVectorProperty(name="bone center point") bpy.types.EditBone.bdst_end_point = bpy.props.FloatVectorProperty(name="bone end point") bpy.types.EditBone.bdst_orientation = bpy.props.FloatVectorProperty(name="bone orientation") bpy.types.EditBone.bdst_instance_id = bpy.props.StringProperty(name="bone node_instance id") bpy.utils.register_class(BdstAddonPreferences) asset_import.register() morph_import.register() pose_import.register() user_preferences = bpy.context.user_preferences addon_prefs = user_preferences.addons["bds-tools"].preferences configure_logging(addon_prefs.debug_file)
def register(): from bpy.props import StringProperty, IntProperty, PointerProperty class ApiNavProps(bpy.types.PropertyGroup): """ Fake module like class. bpy.context.window_manager.api_nav_props """ path = StringProperty(name='path', description='Enter bpy.ops.api_navigator to see the documentation', default='bpy') old_path = StringProperty(name='old_path', default='') filter = StringProperty(name='filter', description='Filter the resulting modules', default='') reduce_to = IntProperty(name='Reduce to ', description='Display a maximum number of x entries by pages', default=10, min=1) pages = IntProperty(name='Pages', description='Display a Page', default=0, min=0) bpy.utils.register_module(__name__) bpy.types.WindowManager.api_nav_props = PointerProperty( type=ApiNavProps, name='API Nav Props', description='') register_keymaps() #print(get_tree_level())
def register(NetRenderJob): NetRenderJob.name = StringProperty( name="Name of the job", description="", maxlen = 128, default = "")
def get_category(self, context): preferences = context.user_preferences.addons['ui_change_category'].preferences wm = context.window_manager name = wm.chosen_panel if name in preferences.tool_panels: category = preferences.tool_panels[name].category bpy.types.WindowManager.panel_category = bpy.props.StringProperty( name="Category", description="Choose a name for the category of the panel", default=preferences.tool_panels[name].defa_cat, update=update_category, ) wm.panel_category = category
def register(): # props bpy.types.Scene.NWBusyDrawing = StringProperty( name="Busy Drawing!", default="", description="An internal property used to store only the first mouse position") bpy.types.Scene.NWLazySource = StringProperty( name="Lazy Source!", default="x", description="An internal property used to store the first node in a Lazy Connect operation") bpy.types.Scene.NWLazyTarget = StringProperty( name="Lazy Target!", default="x", description="An internal property used to store the last node in a Lazy Connect operation") bpy.types.Scene.NWSourceSocket = IntProperty( name="Source Socket!", default=0, description="An internal property used to store the source socket in a Lazy Connect operation") bpy.utils.register_module(__name__) # keymaps addon_keymaps.clear() kc = bpy.context.window_manager.keyconfigs.addon if kc: km = kc.keymaps.new(name='Node Editor', space_type="NODE_EDITOR") for (identifier, key, action, CTRL, SHIFT, ALT, props, nicename) in kmi_defs: kmi = km.keymap_items.new(identifier, key, action, ctrl=CTRL, shift=SHIFT, alt=ALT) if props: for prop, value in props: setattr(kmi.properties, prop, value) addon_keymaps.append((km, kmi)) # menu items bpy.types.NODE_MT_select.append(select_parent_children_buttons) bpy.types.NODE_MT_category_SH_NEW_INPUT.prepend(attr_nodes_menu_func) bpy.types.NODE_PT_category_SH_NEW_INPUT.prepend(attr_nodes_menu_func) bpy.types.NODE_PT_backdrop.append(bgreset_menu_func) bpy.types.NODE_PT_active_node_generic.append(save_viewer_menu_func) bpy.types.NODE_MT_category_SH_NEW_TEXTURE.prepend(multipleimages_menu_func) bpy.types.NODE_PT_category_SH_NEW_TEXTURE.prepend(multipleimages_menu_func) bpy.types.NODE_MT_category_CMP_INPUT.prepend(multipleimages_menu_func) bpy.types.NODE_PT_category_CMP_INPUT.prepend(multipleimages_menu_func) bpy.types.NODE_PT_active_node_generic.prepend(reset_nodes_button) bpy.types.NODE_MT_node.prepend(reset_nodes_button)
def register(): from bpy.utils import register_class for mod in _modules_loaded: for cls in mod.classes: register_class(cls) # space_userprefs.py from bpy.props import StringProperty, EnumProperty from bpy.types import WindowManager def addon_filter_items(self, context): import addon_utils items = [('All', "All", "All Add-ons"), ('User', "User", "All Add-ons Installed by User"), ('Enabled', "Enabled", "All Enabled Add-ons"), ('Disabled', "Disabled", "All Disabled Add-ons"), ] items_unique = set() for mod in addon_utils.modules(refresh=False): info = addon_utils.module_bl_info(mod) items_unique.add(info["category"]) items.extend([(cat, cat, "") for cat in sorted(items_unique)]) return items WindowManager.addon_search = StringProperty( name="Search", description="Search within the selected filter", options={'TEXTEDIT_UPDATE'}, ) WindowManager.addon_filter = EnumProperty( items=addon_filter_items, name="Category", description="Filter add-ons by category", ) WindowManager.addon_support = EnumProperty( items=[('OFFICIAL', "Official", "Officially supported"), ('COMMUNITY', "Community", "Maintained by community developers"), ('TESTING', "Testing", "Newly contributed scripts (excluded from release builds)") ], name="Support", description="Display support level", default={'OFFICIAL', 'COMMUNITY'}, options={'ENUM_FLAG'}, ) # done...
def invoke(self, context, event): context.window_manager.fileselect_add(self) return {'RUNNING_MODAL'} # # # filepath = StringProperty(name="Filename", subtype='FILE_PATH') # gazebo = BoolProperty(name="Export Gazebo tags", default=True) # # package_url = BoolProperty(name="Package URL", default=True) # # base_link_name = StringProperty(name="Base link:", default="root_link") # # @RDOperator.OperatorLogger # @RDOperator.Postconditions(ModelSelected, ObjectMode) # def execute(self, context): # """ # Code snipped from `<http://stackoverflow.com/questions/1855095/how-to-create-a-zip-archive-of-a-directory>`_ # """ # import zipfile # # if os.path.isdir(self.filepath): # self.logger.debug(self.filepath) # self.report({'ERROR'}, "No File selected!") # return {'FINISHED'} # # def zipdir(path, ziph): # # ziph is zipfile handle # for root, dirs, files in os.walk(path): # self.logger.debug("%s, %s, %s,", root, dirs, files) # for file in files: # file_path = os.path.join(root, file) # ziph.write(file_path, os.path.relpath(file_path, path)) # # with tempfile.TemporaryDirectory() as target: # create_package(self, context, target, self.base_link_name) # # with zipfile.ZipFile(self.filepath, 'w') as zipf: # zipdir(target, zipf) # # return {'FINISHED'} # # def invoke(self, context, event): # context.window_manager.fileselect_add(self) # return {'RUNNING_MODAL'}
def register(): # props bpy.types.Scene.NWBusyDrawing = StringProperty( name="Busy Drawing!", default="", description="An internal property used to store only the first mouse position") bpy.types.Scene.NWLazySource = StringProperty( name="Lazy Source!", default="x", description="An internal property used to store the first node in a Lazy Connect operation") bpy.types.Scene.NWLazyTarget = StringProperty( name="Lazy Target!", default="x", description="An internal property used to store the last node in a Lazy Connect operation") bpy.types.Scene.NWSourceSocket = IntProperty( name="Source Socket!", default=0, description="An internal property used to store the source socket in a Lazy Connect operation") bpy.utils.register_module(__name__) # keymaps addon_keymaps.clear() kc = bpy.context.window_manager.keyconfigs.addon if kc: km = kc.keymaps.new(name='Node Editor', space_type="NODE_EDITOR") for (identifier, key, action, CTRL, SHIFT, ALT, props, nicename) in kmi_defs: kmi = km.keymap_items.new(identifier, key, action, ctrl=CTRL, shift=SHIFT, alt=ALT) if props: for prop, value in props: setattr(kmi.properties, prop, value) addon_keymaps.append((km, kmi)) # menu items bpy.types.NODE_MT_select.append(select_parent_children_buttons) bpy.types.NODE_MT_category_SH_NEW_INPUT.prepend(attr_nodes_menu_func) bpy.types.NODE_PT_category_SH_NEW_INPUT.prepend(attr_nodes_menu_func) bpy.types.NODE_PT_backdrop.append(bgreset_menu_func) bpy.types.NODE_MT_category_SH_NEW_TEXTURE.prepend(multipleimages_menu_func) bpy.types.NODE_PT_category_SH_NEW_TEXTURE.prepend(multipleimages_menu_func) bpy.types.NODE_MT_category_CMP_INPUT.prepend(multipleimages_menu_func) bpy.types.NODE_PT_category_CMP_INPUT.prepend(multipleimages_menu_func)
def register(): bpy.types.WindowManager.chosen_panel = bpy.props.StringProperty(update=get_category) bpy.utils.register_class(GroupNames) bpy.utils.register_class(ChangeCategoryPreferences) preferences = bpy.context.user_preferences.addons[__name__].preferences if bpy.context.user_preferences.addons[-1].module != __name__: cache = {} for k in preferences.tool_panels: cache[k.name] = k.idname, k.category, k.defa_cat # Register this addon last next startup module_name = __name__ addons = bpy.context.user_preferences.addons while module_name in addons: addon = addons.get(module_name) if addon: addons.remove(addon) addon = addons.new() addon.module = module_name preferences = bpy.context.user_preferences.addons[module_name].preferences for k, v in cache.items(): my_item = preferences.tool_panels.add() my_item.name = k my_item.idname = v[0] my_item.category = v[1] my_item.defa_cat = v[2] del cache #print(preferences.tool_panels) bpy.types.WindowManager.panel_category = bpy.props.StringProperty( name="Category", description="Choose a name for the category of the panel", default="My Category", update=update_category, ) bpy.utils.register_class(VIEW3D_PT_change_category) for panel in bpy.types.Panel.__subclasses__(): if hasattr(panel, 'bl_category'): name = panel.bl_category + ' (' + panel.bl_label + ', ' + panel.__name__ + ')' #if name not in preferences.tool_panels: for pref in preferences.tool_panels: if panel.__name__ == pref.idname: if panel.bl_category != pref.category and\ panel.is_registered: #print(name, ' to ', pref.category) panel.bl_category = pref.category bpy.utils.unregister_class(panel) bpy.utils.register_class(panel) break break else: my_item = preferences.tool_panels.add() my_item.name = name my_item.idname = panel.__name__ my_item.category = panel.bl_category my_item.defa_cat = panel.bl_category