4

I am writing an addon to help me manage my multi-file addons.

THIS IS HARD TO EXPLAIN

Its coming along really nicely, but I want it to work no matter what .blend file I have open, so I have it save each project's data to an xml file.

Not knowing that it wouldn't work, I had the panel call two functions, one to update the files for the project, and one to update the xml file. So whenever the UI updated the two functions were called. But I changed something in the 2nd function that actually changed a value in blender and it wouldn't let me because you can't edit blender data from a UI context.

So here is my question: What is the best way to continually update my list based on this external XML file. I really don't want a UI button to update from xml if possible.

Also, if there is a way for the two functions to be run whenever Blender opens that would work as well.

doomslug
  • 1,809
  • 1
  • 18
  • 31
  • Just out of interest: Why XML? – p2or Aug 09 '15 at 09:17
  • 1
    @poor because each project has a name, location, a boolean for whether it is an addon or a script, and a list of files in the project. I hadn't ever used XML before and I thought it would be an easy way to store/parse data. And it was. :D – doomslug Aug 09 '15 at 15:17
  • JSON is much simpler however. Anyway, how often are the updates supposed to happen? – CodeManX Aug 09 '15 at 19:06
  • @CoDEmanX I hadn't thought of JSON.. I will look into that once I fix this problem! But minimum it should update when the addon is enabled (the register function, I can already do this) and whenever blender is opened with the addon already enabled. It would be nice for it to be continually checking for new projects in the xml file, but it doesn't need it. – doomslug Aug 11 '15 at 16:15
  • @CoDEmanX Is it possible for a function to run when Blender opens with the addon enabled? Or am I going to have to use a manual update button. – doomslug Aug 15 '15 at 21:15
  • An update button is definitely the cleanest the solution. You can abuse a scene update handler however, to run an update automatically. It needs to unregister itself to only run once. It will execute after init, so that bpy.data and bpy.context are no longer restricted. – CodeManX Aug 16 '15 at 19:21
  • @CoDEmanX I will make a button for now. What do you mean abuse a scene update handler? Thanks! – doomslug Aug 17 '15 at 18:24
  • 1
    Have a look here: http://blender.stackexchange.com/a/7974/1363 (populate_coll() and register()) – CodeManX Aug 17 '15 at 19:18
  • Did you ever get this working? What types of files are you linking? obj, fbx, gltf? I would love to have this functionality. (for 2.8) – Matthew Perkins Aug 15 '19 at 15:16

1 Answers1

1

I ended up using a JSON file. I used handlers to import from the file when it opened just like in this answer: https://blender.stackexchange.com/a/7974/1363

doomslug
  • 1,809
  • 1
  • 18
  • 31