Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to save active section plane to a scene using the SketchUp C API #1015

Open
Whaat opened this issue Nov 25, 2024 · 6 comments
Open

Unable to save active section plane to a scene using the SketchUp C API #1015

Whaat opened this issue Nov 25, 2024 · 6 comments

Comments

@Whaat
Copy link

Whaat commented Nov 25, 2024

Using current version of SketchUp C API as of today (Nov 25, 2024). SDK_WIN_x64_2024-0-594 - Windows 11

It does not seem possible to save the active section plane to a scene using the C API. I have tried doing it multiple ways (order of operations) and it never works so I suspect a bug.

I HAVE been able to save camera properties to a scene using the C API but using a similar approach does not work when saving an active section to a scene.

The test program is a simple modification of one of the sample projects 'WritingToAskpFile'.

In my test program, I create two section cuts and two scenes. The expected result is that one scene will have an active cut and the other scene will have the other active cut.

But the actual result is that both scenes have NO active section cut. The sections are created but are not made active when the scene is activated.

See attached main.cpp which is a simple modification to the sample project 'WritingToAskpFile'. You should be able to recreate by opening the sample project and replacing main.cpp with the attached version.

The output skp created is called 'new_model.skp'. Inspect this file after running the program to see the results which will show that when clicking on scene, there is no active section cut.

image

This bug is a problem for me because I am working on a feature to export components as individual SKP files and then automatically add section cuts / scenes to the SKP using the C API so I can then reference these SKP files / models in a Layout Document that is generated using the Layout Ruby API. This bug is preventing me from being able to implement this feature.

main.zip

@sketchup
Copy link

sketchup bot commented Dec 2, 2024

Logged as: SKEXT-4414

@sketchup sketchup bot added the logged label Dec 2, 2024
@thomthom
Copy link
Member

thomthom commented Dec 6, 2024

@Whaat - just making sure I understand the issue correctly. If the C API had something similar to to Ruby's page.update(flags) - that would work, right?

Something like:

SUSceneUpdate(scene_ref, SU_SCENE_UPDATE_SECTION_PLANES | SU_SCENE_UPDATE_CAMERA);

?

@Whaat
Copy link
Author

Whaat commented Dec 6, 2024

Yes, that would be ideal. However, as I said, it is possible to set the Camera to the scene using the currently available C API calls. But doing the equivalent steps for section planes is not working.

So I don't think a new function needs to be created. Just need to fix the current ones.

@thomthom
Copy link
Member

thomthom commented Dec 9, 2024

Setting active section planes per scene is a little bit more tricky than camera. There is only one camera per scene. But in a model there can be multiple active section cuts in various entities collections.

Setting section planes as active throughout the model and then doing an "update" seems to be a simple way to allow this ability.

@thomthom
Copy link
Member

thomthom commented Dec 19, 2024

@Whaat - I just realized that SUModelAddScenes will also do an "update" - same as what my proposed SUSceneUpdate would do.

But I also now understand why your code isn't working. We realized last week what SUSceneCreate creates a scene that have none of the SUSceneFlags set. (https://extensions.sketchup.com/developers/sketchup_c_api/sketchup/scene_8h.html#SUSceneFlags)

You can observe this if you open a model create from your script and inspect the Scene properties in the UI.

It's a poor API design. Something we could risk breaking existing users if we correct now. But we've already updated the documentation internally to clarify how to create a scene that will remember all properties, similar to what the UI and the Ruby API does by default:

SUSceneRef scene = SU_INVALID;
SUSceneCreate(&scene);
SUSceneSetFlags(scene, FLAG_USE_ALL); // <- Set which properties the scene should remember
SUSceneSetName(scene, "Hello World");
SUModelAddScenes(model, 1, &scene);

@Whaat
Copy link
Author

Whaat commented Dec 20, 2024

@thomthom Thanks so much for this. I've moved on to other tasks but will get back to this at some point and let you know if it works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants