Misleading code sample #77715

Closed
opened 2020-06-10 10:14:07 +02:00 by B. User · 10 comments

May not be a bug, but it is potentially misleading. In the document, there is this

Menu Item

.... The method used for adding a menu item is to append a draw function into an existing class:

def menu_func(self, context):
    self.layout.operator(ObjectCursorArray.bl_idname)

def register():
    bpy.types.VIEW3D_MT_object.append(menu_func)

For docs on extending menus, see: bpy.types.Menu.

But using that register() function does not work, because it is not creating the ObjectCursorArray object first. This tutorial is for beginners, right? So, the reader would not have much knowledge about add-ons, and just follow the code. I have wasted a lot of time trying to add a menu with that code by installing a plugin (.py) file. After some time, that I figured out that it does not register the object, and sure enough, when I scrolled down furthur, there was "Bringing it all together" section which had

def register():
    bpy.utils.register_class(ObjectCursorArray)
    bpy.types.VIEW3D_MT_object.append(menu_func)

In my opinion, the code in the Menu Item section should have the line to register the class, too, in order the sample to work at that part of the document.

May not be a bug, but it is potentially misleading. In the document, there is this **Menu Item** .... The method used for adding a menu item is to append a draw function into an existing class: ``` def menu_func(self, context): self.layout.operator(ObjectCursorArray.bl_idname) def register(): bpy.types.VIEW3D_MT_object.append(menu_func) ``` For docs on extending menus, see: bpy.types.Menu. But using that `register()` function does not work, because it is not creating the `ObjectCursorArray` object first. This tutorial is for beginners, right? So, the reader would not have much knowledge about add-ons, and just follow the code. I have wasted a lot of time trying to add a menu with that code by installing a plugin (.py) file. After some time, that I figured out that it does not register the object, and sure enough, when I scrolled down furthur, there was "Bringing it all together" section which had ``` def register(): bpy.utils.register_class(ObjectCursorArray) bpy.types.VIEW3D_MT_object.append(menu_func) ``` In my opinion, the code in the Menu Item section should have the line to register the class, too, in order the sample to work at that part of the document.
Author

Added subscriber: @blender392349

Added subscriber: @blender392349
Member

Added subscriber: @JacquesLucke

Added subscriber: @JacquesLucke
Member

Changed status from 'Needs Triage' to: 'Needs User Info'

Changed status from 'Needs Triage' to: 'Needs User Info'
Member

Please add a link to the confusing docs in your first post.

Please add a link to the confusing docs in your first post.

Added subscriber: @antoine.grasset

Added subscriber: @antoine.grasset
Looks like this is the doc : https://docs.blender.org/manual/en/latest/advanced/scripting/addon_tutorial.html#menu-item

Removed subscriber: @antoine.grasset

Removed subscriber: @antoine.grasset
Member

Changed status from 'Needs User Info' to: 'Needs Triage'

Changed status from 'Needs User Info' to: 'Needs Triage'

This issue was referenced by 6754

This issue was referenced by 6754
Member

Changed status from 'Needs Triage' to: 'Resolved'

Changed status from 'Needs Triage' to: 'Resolved'
Jacques Lucke self-assigned this 2020-06-11 17:23:36 +02:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-manual#77715
No description provided.