api-issue-tracker icon indicating copy to clipboard operation
api-issue-tracker copied to clipboard

The SketchUp C API does not allow setting color for newly created layers

Open rmtchs opened this issue 1 year ago • 6 comments

After creating a layer, I am unable to set its color

rmtchs avatar May 13 '24 03:05 rmtchs

Do you have a code snippet to reproduce?

Are you trying to modify properties before you have attached the layer (or any entity) to the model?

thomthom avatar May 13 '24 10:05 thomthom

Do you have a code snippet to reproduce?

Are you trying to modify properties before you have attached the layer (or any entity) to the model?

There's nothing special in the code, just created a new layer, but couldn't find an API interface to modify its material

rmtchs avatar May 14 '24 02:05 rmtchs

Please provide a code example. We often find that we cannot reproduce due to subtle differences in how we try to recreate an issue from description alone vs what the reporter is doing.

thomthom avatar May 15 '24 11:05 thomthom

Oh, I see, you're saying you were looking for a way to set the layer material.

You are right, we don't have a setter. Materials owner by layers have some unusual ownership that makes this quirkly. But you should be able to set the properties on the material retrieved from SULayerGetMaterial: https://extensions.sketchup.com/developers/sketchup_c_api/sketchup/struct_s_u_layer_ref.html#acb1bdd418a35ee45aa165f60a34f79dd`

thomthom avatar May 15 '24 11:05 thomthom

Oh, I see, you're saying you were looking for a way to set the layer material.

You are right, we don't have a setter. Materials owner by layers have some unusual ownership that makes this quirkly. But you should be able to set the properties on the material retrieved from SULayerGetMaterial: [https://extensions.sketchup.com/developers/sketchup_c_api/sketchup/struct_s_u_layer_ref.html#acb1bdd418a35ee45aa165f60a34f79dd`]

You mentioned that you can only retrieve material data but not change it. Is there another way to modify the material data of a layer?

rmtchs avatar May 16 '24 03:05 rmtchs

The docs only says not to deallocate it:

The retrieved material object must not be deallocated by the caller since it is owned by the layer object.

Meaning not calling SUMaterialRelease on it.

You should be able to modify the material.

thomthom avatar May 16 '24 12:05 thomthom