Hiding and grouping objects + default FileSelector path

Hi,

How can I hide an object using the blender API?

Also how can I make blender remember the last import path or more specifically, the last path/file selected using “Blender.Window.FileSelector”?
I don’t want to navigate all the time if I do multiple imports from the same folder.

Another problem I have is grouping objects, so that they appear grouped in the outliner and can all be hidden/unhidden together (folder like structure). But there doesn’t even seem to be a way of doing that in the blender GUI itself. Closest is parenting. Joining is not an option.

In 2.49 - setting the layers list of an object to an empty one would make it invisible… Something like this:

ob.layers = []

Dont forget to add some values to the list so that make it visible in certain layers at a later stage :wink:

Look at this thread… In my example given there, you’d need to keep track to fPath variable and supply it unchanged to the Open/Save dialog when needed.

Regards,

Thanks. The layer trick works great and even solves my grouping problem. I can just select the layers I want to see to hide/unhide groups of objects placed in them. :smiley:

I ended up using something like this:

Blender.Window.SetActiveLayer(1<<0);
# create objects of type 0
Blender.Window.SetActiveLayer(1<<1);
# create objects of type 1
Blender.Window.SetActiveLayer(1<<2);
# create objects of type 2
  
# set only layers 1 and 3 (type 0 and 2) on, so that objects of type 1 are not visible
Blender.Scene.GetCurrent().setLayers([1,3]);

But using “obj.layers = [ x ];” works too of course.

I also figured out how to select objects in the same group now to be able to hide them together:
-select one of the objects in the group
-press shift+G, then 7 (or “Select -> grouped -> objects in same group”)

Now I just need to figure out how to group the objects in the script. :slight_smile:

For the path problem, I ended up using the following:

def importFunc(filename):
       Blender.Set('tempdir',os.path.dirname(filename));
       # rest of import script

default_path = Blender.Get('tempdir');
if not default_path:
       default_path = 'H:\DATA';
    
Blender.Window.FileSelector(importFunc, "Import...", default_path);

The problem is that once “File->New” is used, everything gets reset and I need to navigate again.

I’ll try the method you suggested eventually.

Your script puts the user ALWAYS in the ‘tmp’ directory… or in H:/DATA, but it never happened at me cause beforehand the tmp dir is set OK… Why using File–>New? Isnt it for opening a completely new blender file, i.e. without THIS script, meaning that the user cant run it any more???

Regards,

It’s an import script, so it’s always usable, even after using “file->new”.
I would just like Blender to remember the last import source used since it is the same most of the time.

Well, to keep the values between two runs if the script would only be possible if you store it in an external storage such as an external file. Then, when running the script read the previously stored value and propose the user to work with it… Then store it again (in case of changes)…

Regards,

Just a small (very late) update: I did it like you suggested, by creating a temporary file, but also using Blender’s default directory for script related data:

Loading:

cfg = Blender.Get("datadir")+'/import.cfg';

default_path = os.getenv('HOME')
if os.path.isfile(cfg) and os.path.getsize(cfg) > 0:
            with open(cfg, 'r') as FILE:
                 default_path = cPickle.load(FILE);

Saving:


FILE = open(cfg, 'w');
cPickle.dump(filename, FILE);
FILE.close();

cf:
http://www.blender.org/documentation/249PythonDoc/Blender-module.html#Get

  •            'datadir' : the path to the dir where scripts should store                and retrieve their data files, including saved configuration                (can be None, if not found).
    

That’s ~/.blender/bpydata/ on GNU/Linux.