SUComponentInstanceSaveAs gives an empty file

Hi everyone,

I know this function is a bit shitty, but nevertheless i need to use it and it’s obviously not doing what it is supposed to do.

I have a SUComponentInstanceRef instance which is valid and represents a piece of wood. I use SUComponentInstanceSaveAs(instance,filename) to save it in a file, in order to get a model which contains only this instance.

When i try to create the corresponding model with SUModelCreateFromFile(filename), it gives me an empty model, no instances, no definitions, no groups, nothing.

I really don’t get it. This method hereabove works fine with groups, and I have used it to isolate the walls of a house into different .skp files.

Any idea? @tt_su?

What is needed is a proper SUComponentDefinitionSaveToFile method like the Ruby API has.

Every workaround we’ve tried to think up runs into a wall of a missing method (like lack of explode.)

Well, nevertheless, I would at least expect this function to create a file which actually contains an instance…

Well the only course is to open another issue in the Issue tracker, and perhaps give impetus to getting the situation(s) fixed in the next cycle (hopefully).

IMO, this should be labeled as the topmost priority issue for the C API.

For reference, I’m following up on this question in the github issue tracker: https://github.com/SketchUp/api-issue-tracker/issues/520

(I made a request for example code reproducing it.)

I have found a workaround, i’m saving the group that contains the instance i want, then create and hide a layer containing all the instances of the group, and create and show a layer which contains the only instance I want to visualize. I am pretty busy right now, i’ll try to complete the issue description (with reproducing code) next weekend.

Anyway thanks for your concern.

Donat

Re: SketchUp Layer-Tags ...

FTR, SketchUp layer-tags are not geometric collections. They do not “contain” anything.

They are display property sheets that can be shared among many objects regardless of position in the geometric hierarchy.

It goes a little off topic, but once it has been mentioned…

If you compare:
Definition#save_as(file_path)
Model#save(filename, version) (or similar #save_copy )
You will notice that the version is missing from the first one. The UI also allows you to select a version for the “Save as” component, but the Ruby API does not.
It would be great to be in it, then it will be even more proper.

BTW: file_path <> filename meaning same, can be more consistent in docu…

filepath vs filename ...

They are actually not the same thing. filepath is better as it contains a path as well as a filename.
(FYI, Ruby calls a filename a “basename”.)

But for the C API, C conventions should be followed.

1 Like
filepath vs filename ..vs Ruby API Docu

Sure you right. I prefer filepath too.
I wanted to say that it would be nice to be the same (or more consistent) in the Ruby API document.

(As you may know my mother never told this to me… in English :slight_smile: :blush: )

__

filename = File.join(ENV['Home'], 'Desktop', 'mysketchupcopy_v8.skp')

filename (String) —The name of the file to save the model copy.
__
vs:
__

success = my_definition.save_as "c:\\myComponent.skp"

file_path (String) — Local file path to save the .skp file to.

1 Like