The aspect ratio is always the same when applying the. jpg material

Why do my materials have different aspect ratios, but the aspect ratios become the same after applying materials. I used the following operations to apply the material(Materials in. jpg format):

materials = Sketchup.active_model.materials
material = materials.add(materialName)
material.texture = materialPath

You should probably attach the JPG to the above post.

Can you explain how they are different, … and then what are they when they “become the same” ?

Are you setting the texture’s size after creating it?

Try not to use send actions in code with other statements. They are really meant for menu item or toolbar button commands. They are also slow and following statements can execute before the action is complete

In this case, to show the “Materials” inspector, instead use:


The effect is like this. The aspect ratio of my pictures is different, but they are the same:

SketchUp have no way of knowing what the desired real world size of the pixel dimensions of a texture should be. So when you assign a texture to a material it’ll default to 1.0 x 1.0. (which means 1 inch by one inch - which is what you see in the UI). (Maybe that would have been better to default to sizes the take into account the bitmap ratio, but this is what it has been doing for years so we’re stuck with it. Changing this now might break extensions that might rely on that behaviour.)

After creating a material via the API with a texture you should set the width and height yourself to be of the desired size.

1 Like

This is the nearest API equivalent of what DaveR recommends when importing via the GUI (though the order of operations is slightly rearranged): draw a rectangle of the desired material dimensions and then when importing the image drag it out to cover the rectangle.

Thank you for your answer, which makes me understand this better. After setting the width and height, the effect can meet my expectations

Thank you for your attention. I found a solution.

Thanks for your help. I noticed some other parameters of the interface.