Problem making layout from different scenes

I have a .skp file containing a wall (I isolated it from a bigger file using SUComponentInstanceSaveAs) made of different components.

I sort the components using the name of their component definition name (which I know for sure is representative of what instances actually represents), so I get 3 vectors containing:

  • wood instances
  • outer side panels instances
  • inner side panels instances.

Then I create 3 corresponding layers that I add to the model.
I define 2 different scenes with 2 different cameras (both having the same orientation), and add these 3 layers to both scenes.

Then I create a layout document with 2 pages (one page per scene), and only one unshared LOLayerRef.

The thing is: I would like to hide the inner panels in the first scene, and show them in the second, but (seemingly) no matter in what order I toggle layers in both scenes, both pages will be the same, i.e. I can get 2 views without the inner panels or 2 views with them, but not 1 with and the other without.

I can provide you with .skp file and code if it can be of any help.

Did you then call SUSceneGetUseHiddenLayers with a true argument to set this flag on each of the layers/tags ?

Did you first save the model to a file ?

I’ll try to summarize, there is quite a lot of code, I did my best to put useful comments.
I have a litte workaround which consists in calling PTClayWall 2 times and creating only one scene per call, and hiding the inner panels in the second call. It then gives me the result I want but still that is quite unsatisfactory. Thanks for your help anyway.

//++++++++++++++++++++++++++++++++++++++++++++++++++++
// this is the function called to generate the LODocument
//++++++++++++++++++++++++++++++++++++++++++++++++++++
int PTClayWall::makeLayout(PTLayoutMaker& maker)
{
    std::string zou = PTString::getFileNameWithoutExtension(maker.getFileName());
    std::string num = std::to_string(maker.getElemCounter());
    std::string file1 = zou + "_tmp" + num + ".skp";
    std::string file2 = zou + "_new" + num + ".skp";
   
    // that's the group representing the wall I want to isolate
    SUGroupRef g = getProductionGroup();
    SUComponentInstanceRef c = SUGroupToComponentInstance(g);
    SUComponentInstanceSaveAs(c, file1.c_str());

    SUModelRef newModel = SU_INVALID;
    SUModelCreateFromFile(&newModel, file1.c_str());

// see function hereunder. As explained in my first topic, I basically create 3 layers, one for the woods, another one for the outer panels, and a last one for the inner panels(actually it is composed of clay)
    PTLayoutMaker::createLayers(newModel);

// first scene without the inner panel(clay)
    SUSceneRef frontScene = SU_INVALID;
    SUSceneCreate(&frontScene);
//see function hereunder
    defineFrontScene(newModel,frontScene, "assemblage");
    std::string prd = PTMaterial::getClayCode();
    PTLayoutMaker::hideLayer(frontScene, prd);
    

//second scene with the inner panel(nothing gets hidden). My first guess would be that as both scenes share the same layers, the issue comes from here
    SUSceneRef frontScene2 = SU_INVALID;
    SUSceneCreate(&frontScene2);
    defineFrontScene(newModel, frontScene2,"enduit");

    SUResult saved = SUModelSaveToFile(newModel, file2.c_str());
    if (saved != SU_ERROR_NONE) std::cout << "time for bed" << std::endl;

    SUModelRelease(&newModel);
    std::remove(file1.c_str());

// this is the function used to generate the LODOcumentRef, which is a member variable of object maker. This is the last function I quote
    maker.makeLayouts(file2);
    std::remove(file2.c_str());

 return 0;
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++
//After this call, i generate a .pdf file using LODocumentExportToPDF
//The LODocumentRef I use contains only one LOLayerRef:
//    LODocumentCreateEmpty(&_document);
//    LODocumentAddLayer(_document, false /* shared */, &_defaultLayer);
//    LOLayerSetName(_defaultLayer, "Default");

//++++++++++++++++++++++++++++++++++++++++++++++++++++

//This is the functions used to create my 3 layers. The model passed in argument is the one containing the single wall.
void PTLayoutMaker::createLayers(SUModelRef& model)
{
    size_t oldnlayer;
    SUModelGetNumLayers(model, &oldnlayer);
    std::vector<SULayerRef> oldlayers(oldnlayer);
    SUModelGetLayers(model, oldnlayer, &oldlayers[0], &oldnlayer);
    SUModelRemoveLayers(model, oldnlayer, &oldlayers[0]);

    std::vector<SUGroupRef> groups;
    std::vector<SUComponentInstanceRef> instances;
    PT_skpFileReader::getModelGroupsAndInstances(model, groups, instances);

    std::vector<std::string> componentNames;
    PT_skpFileReader::getComponentNames(groups, instances, componentNames);
    size_t nlayers = componentNames.size();
    std::vector<SULayerRef> newLayers(nlayers);
    for (size_t i = 0; i < nlayers; i++)
    {
        SUSetInvalid(newLayers[i]);
        SULayerCreate(&newLayers[i]);
    }
    SUModelAddLayers(model, nlayers, &newLayers[0]);

    for (size_t i = 0; i < nlayers; i++)
    {
        std::string name = componentNames[i];
        int ncomp = 0;
        PT_skpFileReader::getNumComponent(groups, instances, name, ncomp);
        std::vector<SUDrawingElementRef> draws(ncomp);
        ncomp = 0;
        PT_skpFileReader::getDrawingElements(groups, instances, name, draws, ncomp);

        for (size_t j = 0; j < ncomp; j++)
        {
            SUDrawingElementSetLayer(draws[j], newLayers[i]);
        }

        SULayerSetVisibility(newLayers[i], true);
        std::string layerName = componentNames[i];
        SULayerSetName(newLayers[i], layerName.c_str());
    }
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++

// this is the function used to create both scenes
void PTClayWall::defineFrontScene(SUModelRef& model, SUSceneRef& scene, std::string sceneName)
{
    int outIndex;
    SUModelAddScene(model, -1, scene, &outIndex);

    std::vector<SUGroupRef> groups;
    std::vector<SUComponentInstanceRef> instances;
    PT_skpFileReader::getModelGroupsAndInstances(model, groups, instances);

    PTCamera2 camera = defineFrontCamera(groups, instances);

    SUSceneSetCamera(scene, camera.getCamera());
    SUSceneSetUseCamera(scene, true);
    SUSceneSetName(scene, sceneName.c_str());
    SUSceneSetUseSectionPlanes(scene, false);
    //tmp test: it gets even worst: blank pages
    SUSceneSetUseHiddenLayers(scene, true);

    PTLayoutMaker::copyModelLayersToScene(model, scene);
    PTLayoutMaker::showAllLayers(scene);
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++

void PTLayoutMaker::makeLayouts(const std::string& skpfileName)
{
    _elemCounter++;

    _ptdoc.setFileName(skpfileName);
    LOSketchUpModelRef lo_model_ref = _ptdoc.getModel();

    // Get the scene count so we know how many pages we'll need in our LayOut document.
    size_t scene_count = 0;
    LOSketchUpModelGetNumberOfAvailableScenes(lo_model_ref, &scene_count);


    std::vector<SUStringRef> scene_names(scene_count);
    for (size_t count = 0; count < scene_count; ++count) 
    {
        SUSetInvalid(scene_names[count]);
        SUStringCreate(&scene_names[count]);
    }

    LOSketchUpModelGetAvailableScenes(lo_model_ref, scene_count, &scene_names[0], &scene_count);

    // The first name from available scenes is the default scene, we want to skip
    //for (size_t count = 1; count < scene_count; count++)
    size_t start = 1;
    size_t end = scene_count;
    size_t step = 1;
    for (size_t i = start; i < end; i+=step)
    {
        std::string zou = PTString::getStandardString(scene_names[i]);
        std::cout << "scene name = " << zou << std::endl;


        LOPageRef page_ref = _ptdoc.createEmptyPage();
        std::string sceneName = PTString::getStandardString(scene_names[i]);
        LOPageSetName(page_ref, sceneName.c_str());
        _ptdoc.addEntity(page_ref,i);

        LOSketchUpModelSetCurrentScene(lo_model_ref, i);
    }

    for (size_t i = 0; i < scene_count; i++)
    {
        SUStringRelease(&scene_names[i]);
    }
}


By the way this is what the result should look like (generated with my workaround)

prisonnier_plan_prod.pdf (118.8 KB)