Why this method is removed in 2024. And how to get the definition of an image?
It was never there, so it wasnāt removed.
However the ComponentDefinition #image? method can be used to determine if a component definition is used to define an image.
So a method to find the image definition can be done like e.g.:
def image_definition(image)
return unless image.is_a?(Sketchup::Image)
Sketchup.active_model.definitions.find { |definition|
definition.image? && definition.instances.include?(image)
}
end
Manipulating an image objectās definition can crash SketchUp.
Why do you need to get a reference to an imageās definition?
I am sure that the ādefinitionā method for image is avaliable in SketchUp 2023 and before. But maybe not in the API docs. Also I can understand an image is treated like a component instance. But I can not directly get the definition of image in 2024 now, itās weird for me. Thanks anyway.
You are not supposed to directly modify Ruby or SketchUp API classes.
Instead, use a refinement that only your code can see.
Again, ā¦
Manipulating an image objectās definition can crash SketchUp.
Why do you need to get a reference to an imageās definition?
To determine if two image the same, and reuse their mesh data.
I didnāt modified. The method is just there. You can use ruby āmethodsā to see the ādefinitionā method in SketchUp 2023 and before. Besides there is āSUImageGetDefinitionā in C API.
In this case, there is an extension (orphan rb file or whatever) in your SU2023 Plugin directory(ies) that modified the Sketchup::Image class, when SU loaded, or you manually loaded such a modification, but forgot aboutā¦
The C API nothing to do with this.
SU2021:
Thank you very much. I found the ācriminalā. Itās one of the installed plugin on my machine.
āCulpritā not ācriminalā ā¦ haha
Mesh data? An image is a flat face with 4 vertices.
You can get the origin
, height
and width
from the instance to compare the size if not scaled. If scaled you can get the unscaled pixel width
and height
from the instanceās image_rep
.
You can compare the pixel data gotten from the instanceās image_rep
to determine if they use the same graphic.
image1.image_rep.data == image2.image_rep.data
Or you could also compare the file path
from the instances.
You can iterate over the modelās DefinitionList and check the instances of each definition to find the one used by your Image. That said, Image objects are not designed to function like components. Their definition is really an implementation detail leaking out.