I am new to skecthup, I wanted to know if it is currently possible to lock a group using 2016 C++ SDK similar to what it is possible to do with Ruby SDK :
Add a group to the model using Ruby code.
group = Sketchup.active_model.entities.add_group
group.entities.add_line([0,0,0],[100,100,100])
status = group.locked = true
I am not able to reproduce this. The functions locks the group as expected in my test.
You say āblueā - the default style in SU display a red boundingbox when you select a locked instance. However this is style dependant. Please check the Entity Info.
If you still see it doesnāt working, please provide a full example that reproduce the issue. Including any models that might be needed.
Here is the test snipped I used:
// SLAPI-Test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <array>
#include <assert.h>
#include <iostream>
#include <vector>
#include "SketchUpAPI/sketchup.h"
int _tmain(int argc, _TCHAR* argv[])
{
SUInitialize();
SUModelRef model = SU_INVALID;
SUResult result = SUModelCreateFromFile(&model, "C:\\Users\\tthomas2\\SourceTree\\SLAPI-Test\\models\\SU-31417.skp");
assert(result == SU_ERROR_NONE);
SUEntitiesRef entities = SU_INVALID;
result = SUModelGetEntities(model, &entities);
assert(result == SU_ERROR_NONE);
size_t num_groups = 0;
result = SUEntitiesGetNumGroups(entities, &num_groups);
assert(result == SU_ERROR_NONE);
std::vector<SUGroupRef> groups(num_groups, SU_INVALID);
size_t num_group_out = 0;
result = SUEntitiesGetGroups(entities, num_groups, &groups[0], &num_group_out);
assert(result == SU_ERROR_NONE);
SUGroupRef group = groups.back();
SUEntitiesRef group_entities = SU_INVALID;
result = SUGroupGetEntities(group, &group_entities);
assert(result == SU_ERROR_NONE);
// SUGroupToComponentInstance
SUComponentInstanceRef instance = SU_INVALID;
instance = SUGroupToComponentInstance(group);
assert(SUIsValid(instance));
// SUGroupFromComponentInstance
SUGroupRef group2 = SUGroupFromComponentInstance(instance);
assert(SUIsValid(group2));
// SUComponentInstanceIsLocked
bool is_locked = false;
result = SUComponentInstanceIsLocked(instance, &is_locked);
assert(result == SU_ERROR_NONE);
assert(!is_locked);
// SUComponentInstanceSetLocked
result = SUComponentInstanceSetLocked(instance, true);
assert(result == SU_ERROR_NONE);
result = SUComponentInstanceIsLocked(instance, &is_locked);
assert(result == SU_ERROR_NONE);
assert(is_locked);
// SUComponentInstanceSaveAs
result = SUModelSaveToFile(model, "C:\\Users\\tthomas2\\SourceTree\\SLAPI-Test\\models\\SUComponentInstanceSetLocked.skp");
assert(result == SU_ERROR_NONE);
SUModelRelease(&model);
SUTerminate();
return 0;
}
The resulting file:
And the SKP file it reads in: SU-31417.skp (30.2 KB)
I have tested the sample code with the input test file but when I open the generated output file in Sketchup Make 2016, the part is not locked. However if I test the same part to see whether there is or not a lot on the entities instance, it has a lockā¦
When I open this output file in SU2016, Zoom extents, then select the āUV Cubeā, I see a properly locked Solid Group, not a ComponentInstance. (And being a group, itās definition name is hidden in the EntityInfo inspector.)
My hidden select color is set to Red, so the boundingbox hilightes as Red.
So, why is the above screenshot showing a ComponentInstance ?
You lost me on this one ā¦ there isnāt a lock, but there is a lock?
Btw, are you opening the SKP, or are you importing it? If you import an SKP it will come in as a component. Your filename and screenshot indicate you have the āSU-31417_lock.skpā imported as a component.
Just to make sure, if you used my test script - it generated a file āSUComponentInstanceSetLocked.skpā. If you go to File > Open and then select that file in SketchUp you should get a group with a cube that is locked.
I have managed to have correct behavior in Sketchup with the sample, I have realized that the model I have built with my code appeared to be a surface when I open in Sketchup not a solid model.
I guess something is wrong in the way I am building the component. Iāll open a new topic for this one to understand what I missed to build a Sketchup model from a tessellated representation.
Entity Info will only show āSolid Groupā when you have the group selected. When you open the group/component and select the faces it will never say solid.
From the screenshot it looks like you have created a model with a cube - and opened that directly. Itās a bit unclear to what it is you are actually doing when you create and open/import these models. Maybe you can explain step by step what you do - or even better; a video?