How to read .skp files in ruby?
-
Hi,
I have written some plugins and I have some .skp files containing some models.
I want to be able to read these files programmatically and run my plugins on those models. Is it possible?.
I read about Sketchup C API. This is C. My plugins in ruby. So I was not sure how to use them together. Is the ability to read .skp files and get models available in ruby? Any pointers to examples?
-
You can only read the open model in Ruby. To read SketchUp models on disk you need to use the C API. We have made a Ruby C++ extension example that can be used as a boilerplate for using C_libs - like the C API:
https://github.com/SketchUp/ruby-c-extension-examples -
Thank you
-
A workaround is to import the model.
The first added definition contains the loaded model, the other definitions are those of the nested components and groups.
Your plugin can retrieve information, or modify those definitions, write them back to disk and delete the instance and definition of the loaded model.But there can be name-conflicts (materials, components...) beween the loaded and the main model. EG: Sketchup will rename the materials of your model if ....
-
@pgarmyn said:
The first added definition contains the loaded model, the other definitions are those of the nested components and groups.
What do you mean by that?
The root model entities are only available frommodel.entities
. Everything inmodel.definitions
belongs to groups, components or images. -
When you import a model, the entities (edges, faces, groups,... ) don't go directly in model.entities. They are encapsulated in a new component....
Advertisement