Forum

get_object_by_name() returning a not found error

09 February 2016 15:52
Hi,

I'm very new here so forgive my lack of knowledge.

When I typed this in my javascript code:
m_scenes.hide_object(m_scenes.get_object_by_name("selectedPlane"));


This returns an error saying:

B4W ERROR: get object selectedPlane: not found.

Now there is 'selectedPlane' in my blend file. I'm probably overlooking the obvious but is there something I'm missing? Possibly in the blend file too? Thanks in advance
09 February 2016 16:25
Did you dynamically load "selectedPlane"? If you use dynamic loading this topic helps you.
Blend4Web Team
kirill@blend4web.com
09 February 2016 17:29
Hello.

Does selectedPlane belong to dupli group? Also could you send us your .blend file with this object, if the issue occurs.
Blend4Web developer
11 February 2016 13:21
Thanks for your replies
Did you dynamically load "selectedPlane"? If you use dynamic loading this topic helps you.
Yes, I just followed the furnishing the room tutorial.

I have attached the blend file from the furnishing the room tutorial. It has an object called 'spawner'. It works fine for their example but if I copy this object into my scene it doesn't pick up on it. Please let me know if you can find an answer.
12 February 2016 12:53
Hi,
I have attached the blend file from the furnishing the room tutorial. It has an object called 'spawner'.
So the function call
m_scenes.get_object_by_name("spawner");

doesn't work in your case?
The Founder | Twitter
23 February 2016 11:38
I can give you a more detailed example:

var obname = "ItaliaMateArmchairMain";
    var _objs = [];
    _objs = m_scenes.get_all_objects("MESH");


    for(var i = 0 ; i < _objs.length; ++i)
    {
        if(_objs[i].name == obname) {
            console.log(_objs[i].name);
            var materials = m_mat.get_materials_names(m_scenes.get_object_by_name(_objs[i].name));
            console.log(materials);
        }
    }


Here I'm searching for an object with name - obname. And _objs is storing all the objects in the scene. I am then looking for the object in the array and printing its name out. Please check the screenshot attached. The objects is found and its name is printed. But when I use get_object_by_name() it says that its not found.

Any help would be appreciated. :)
24 February 2016 16:07
Hi! What does the m_scenes.get_object_name() return for this object?
Blend4Web Team
25 February 2016 08:19
It prints the following:

B4W ERROR: get object ItaliaMateArmchairMain: not found
TypeError: a is undefined
25 February 2016 10:23
No, not get_object_by_name(), but get_object_name(_objs[j]). They're easy to confuse .
Blend4Web Team
25 February 2016 11:28
Oh right, sorry.

It returns - ItaliaMateArmchairMain
Same as before.

Could it be a problem with my .blend file?
 
Please register or log in to leave a reply.