PDA

View Full Version : Opening files from python scripts



dadeno
20-Jun-07, 15:17
Hello all,
I have been using Blender for a while but have a question concerning file opening and the configuration of the actual .blend file.

I have a python script that represents a GUI. This GUI allows the user to open certain .blend files of their choice; however, when you select the file, it opens it up and ends the GUI. I want the GUI to remain active and the file to only open in the 3DVIEW sub-window.

Can anyone please help me with this issue or point me into the right direction?

Thanks,
Drake

johannc
25-Jun-07, 08:39
Hi,

It's a long time from your question, but may be it's not too late.
I am newbie on Blender but I guess your solution is to avoid the Blender.Load() function (because it replaces everythings) and to use the Library.Load() (on the scenes) instead.

I guess something like that would work:
Library.Open(filename)
for scname in Library.Datablocks('Scene'):
___Library.Load(scname, 'Scene', 0)
Library.Update()
Library.Close()

then perform some windows update...
(sorry for my tab : '____' )

dadeno
26-Jun-07, 12:12
Johannc,
When you say use scname, what does this refer to? ( in the for loop and the Library.Load function)
Also, should this variable be defined first somewhere else?

Thanks for the help!

johannc
26-Jun-07, 14:21
scname is just a variable name. You can use any name instead: i, j, foo...

With python, like javascript for example, you don't need to define the variable first. They are automaticaly allocated by the langage.

dadeno
26-Jun-07, 16:11
I am still having a problem. I have implemented the code you suggested and I get no errors. However, the 3D view is till not updating with the objects from the Library I am opening. What needs to be called to view these or can you not view them?

Also, I am writing some information from this Library to a text file. Is there a way to clear this Library information within the Scene so to say open another Library with other information and write that without having the data from the previous Library present?

johannc
27-Jun-07, 02:53
First, when you perform the library import, you keep the current scene (called 'Scene' by default). Then, with the import, another scene(s) may be import. If you want to see them in the 3D view, you have to change the current scene. In the GUI the select tool is in the right of the menu tab, whereas with the API, you have to use Scene.Get(scname).makeCurrent()

The tricky point is: if you import a scene called 'Scene', it will be rename as 'Scene.001' (because of the existing one by default). Blender does that for every thing. It's a little bit annoying. Of course, you can't remove the default scene first (it would be too easy), because it is the current scene and you can not remove the current scene.

The solution may be :
1. In the loop, check if a scene with the same name than the imported one already exist. If yes, rename the existed one firt (that will avoid the imported scene to be rename)
2. Import the scname scene and (for example) if it is called Scene, make it the current scene.
3. Eventually, delete all the old scenes.

But it depends on what you want to do.

For your second part, you can do what you want with the text files in Blender. For removing its content, just use Text.Get(yourtextname).clear()