User Tools

Site Tools


blender:python:addonnotes:start

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
blender:python:addonnotes:start [2022/02/07 18:50]
dwheele [Creating a mesh]
blender:python:addonnotes:start [2022/02/19 18:19] (current)
dwheele [Blender Python Addon Notes]
Line 1: Line 1:
 ====== Blender Python Addon Notes ====== ====== Blender Python Addon Notes ======
   * [[..start|Full Blender Python notes]]   * [[..start|Full Blender Python notes]]
 +  * [[https://b3d.interplanety.org/en/working-with-uv-maps-through-the-blender-api/|Info about UV Meshes]]
  
 Doing research to make a panel to control Baking Texture assignments. Doing research to make a panel to control Baking Texture assignments.
Line 44: Line 45:
  
 from https://youtu.be/mljWBuj0Gho (Curtis Holt) from https://youtu.be/mljWBuj0Gho (Curtis Holt)
 +
 +This is how to do it without using BMesh.
  
 <code python> <code python>
Line 113: Line 116:
 obj = bpy.data.objects.new(name, mesh) # Object contains meta data, not just the mesh obj = bpy.data.objects.new(name, mesh) # Object contains meta data, not just the mesh
 col = bpy.data.collections.get("Objects") col = bpy.data.collections.get("Objects")
-col.objects.link(obj) +col.objects.link(obj) # This will make the object actually display 
-bpy.context.view_layer.objects.active = obj +bpy.context.view_layer.objects.active = obj # makes the object active (isn't working for me) 
-mesh.from_pydata(verts, edges, faces)+mesh.from_pydata(verts, edges, faces) # actually makes the mesh
 </code> </code>
  
 +===== Blender member variables =====
  
 +^BL Variable^Example^Description^
 +|bl_context|uv|The context in which the panel belongs to|
 +|bl_idname|VIEW3D_PT_test_1|Name of the object. Unique identifier for buttons and menu items to reference.. If this is set, the panel gets a custom ID, otherwise it takes the name of the class used to define the panel. For example, if the class name is “OBJECT_PT_hello”, and bl_idname is not set by the script, then bl_idname = “OBJECT_PT_hello”|
 +|bl_label|Panel One|Display name in the interface. Name of the object, shows up in a menu. The panel label, shows up in the panel header at the right of the triangle used to collapse the panel|
 +|bl_space_type|VIEW_3D|The space the panel will be used in. enum in [‘EMPTY’, ‘VIEW_3D’, ‘IMAGE_EDITOR’, ‘NODE_EDITOR’, ‘SEQUENCE_EDITOR’, ‘CLIP_EDITOR’, ‘DOPESHEET_EDITOR’, ‘GRAPH_EDITOR’, ‘NLA_EDITOR’, ‘TEXT_EDITOR’, ‘CONSOLE’, ‘INFO’, ‘TOPBAR’, ‘STATUSBAR’, ‘OUTLINER’, ‘PROPERTIES’, ‘FILE_BROWSER’, ‘SPREADSHEET’, ‘PREFERENCES’], default ‘EMPTY’|
 +|bl_region_type|UI|The region where the panel is going to be used in. enum in [‘WINDOW’, ‘HEADER’, ‘CHANNELS’, ‘TEMPORARY’, ‘UI’, ‘TOOLS’, ‘TOOL_PROPS’, ‘PREVIEW’, ‘HUD’, ‘NAVIGATION_BAR’, ‘EXECUTE’, ‘FOOTER’, ‘TOOL_HEADER’, ‘XR’], default ‘WINDOW’|
 +|bl_category|Tool|The category (tab) in which the panel will be displayed, when applicable. Leave blank if panel doesn't have tabs.|
 +|bl_options|DEFAULT_CLOSED|One of DEFAULT_CLOSED, HIDE_HEADER, INSTANCED, HEADER_LAYOUT_EXPAND - Formatting for this panel, set to <nowiki>{'REGISTER', 'UNDO'}</nowiki> to enable undo|
 +|bl_region_type|WINDOW|enum in [‘WINDOW’, ‘HEADER’, ‘CHANNELS’, ‘TEMPORARY’, ‘UI’, ‘TOOLS’, ‘TOOL_PROPS’, ‘PREVIEW’, ‘HUD’, ‘NAVIGATION_BAR’, ‘EXECUTE’, ‘FOOTER’, ‘TOOL_HEADER’, ‘XR’], default ‘WINDOW’|
 +
 +
 +===== register, unregister =====
 +
 +**To register a Python class,** so that it can be used within Blender, this function needs to run when the Python file is loaded. This means it is at the same level as the class defintion, that is, not indented.
 +
 +<code python>
 +def register():
 +    bpy.utils.register_class(LayoutDemoPanel)
 +</code>
 +
 +**To unregister a Python class,** so that it disappears from the menuing, you typically use something like this:
 +
 +<code python>
 +def unregister():
 +    bpy.utils.unregister_class(LayoutDemoPanel)
 +</code>
 +
 +but when run **from the Blender Python text editor**, the class doesn't have any name space, so you have to find it first.
 +
 +Note that "Panel" needs to be the type that this class is, one of Panel, UIList, Menu, Header, Operator, KeyingSetInfo, RenderEngine.
 +
 +<code python>
 +def unregister():
 +    myPanelClass = bpy.types.Panel.bl_rna_get_subclass_py("SCENE_PT_layout")
 +    bpy.utils.unregister_class(myPanelClass )
 +</code>
 +
 +===== Python's automatic script variables =====
 +
 +^Variable^Description^
 +|<nowiki>__name__</nowiki>|Contains "<nowiki>__main__</nowiki>" if run from the Blender text editor, otherwise, it contains the Python class which calls this|
 +
 +So we include this at the end of a Python script so that when running inside of Blender, it registers this class. Otherwise it doesn't need to, because the Script runner takes care of this. 2/15/2022
 +
 +<code python>
 +if __name__ == "__main__":
 +    register()
 +</code>
  
  
blender/python/addonnotes/start.1644259814.txt.gz · Last modified: 2022/02/07 18:50 by dwheele