3
$\begingroup$

I am writing a Add-On which adds a panel to the 3d view. It should let users create primitive meshes and set details like name, subdivide, color or noise to manipulate the mesh.

Currently the used details are stored in a list per object as part of the add-on. The intention is to use the list to give the user the opportunity to see what the values are on existing objects created by the addon.

What I try to achieve:

I want the panel to be drawn always. Inside the panel are some properties which the user can manipulate and then press 'generate' so that a new object is generated with the new property values. A user should be able to select an already generated object, see the values of that object, manipulate them and generate a new object.

For example we have another object which has the name B. It has different values. If I select B, the values in the Panel need to change. The user should be able to change some of the values and generate a fully new object! The old object isn't manipulated. I only want to add some comforting behaviour.

The problem

bpy doesn't allow scene properties to be updated inside the scope of poll or draw, this means I can't automatically update the scene properies shown on the UI if one of my custom primitives is active.

The question

If there is no way to set properties from inside the draw-method, how would I achieve this?

Here's what the panel looks like.

enter image description here

$\endgroup$
  • 1
    $\begingroup$ Write a callback function, see: blender.stackexchange.com/questions/10910/… $\endgroup$ – p2or Jun 24 '15 at 12:02
  • $\begingroup$ @poor I am having a lot of properties inside the addon. Is there really no other way to do this? I don't want to write a own callback function for every property. Would be easier if I could change the value the properties the scene currently has. $\endgroup$ – Hamburml Jun 24 '15 at 12:25
  • $\begingroup$ You might want to try application handlers. $\endgroup$ – someonewithpc Jun 24 '15 at 12:42
  • 1
    $\begingroup$ @Michael have I correctly restated your question? $\endgroup$ – zeffii Jun 26 '15 at 6:22
  • 1
    $\begingroup$ let me encourage you to delete most of your comments in this area now, as they have been included in the question mostly, this leaves this comments area clean for additional questions.. $\endgroup$ – zeffii Jun 26 '15 at 19:13
1
$\begingroup$

If no object is active/selected display scene's properties which the user changes to generate geometry.

If some object is active/selected display the object's custom properties (which are saved to the object when generated) so the user can change them and re-generate the object or generate a new one.

Each generated objects should have 1 property group with all the properties inside, so there is no mess.

$\endgroup$
  • $\begingroup$ I wasn't able to use PropertyGroup but I was able to use ID Properties. Every property has now his own ID Property. Thanks! I think someone suggested ID Properties before but I didn't know that the custom properties were ID Properties. Anyways... Could you add a small PropertyGroup-Example to your answer to show how a PropertyGroup is added types.object and how these new properties are set? Would like to use these instead of lots of ID Properties. $\endgroup$ – Hamburml Jun 28 '15 at 11:14
  • $\begingroup$ @Michael Look into the link in my answer - it has this exact example. Also you can find examples here: blender.stackexchange.com/questions/6984/… and here: blender.stackexchange.com/questions/15479/… $\endgroup$ – Jaroslav Jerryno Novotny Jun 28 '15 at 14:52
0
$\begingroup$

The Blender API doesn't support that kind of event->response system (or event-signal). I think the best way would be:

  1. Store the active object in an internal variable in your addon, use that var to pick properties and draw the controls
  2. Add a handler to bpy.app.handlers.scene_update_post. This function will be run everytime the scene updates (which is a lot).
  3. Inside that callback watch the current active object, if it's different than the one in your internal variable, set the internal var to the new selected object.
  4. draw() will now use the selected object (as is set in the variable) and use different properties.

For more info on app handlers check this section of the API reference.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.