Set Occurrence Scale

I am attempting to scale multiple occurrences unevenly in a few dimensions. I’ve run into some problems doing that so I’ve tried a simple case:

However, this produces this:

Why is it rotating? Also, is there a good way to get the translation and rotation values to put into the matrix? Or is there a function that only affects the scale?

#get selection - fails if nothing is selected
sel = scene.getSelectedOccurrences()[0]
#use global matrix to get transform
mat_global = scene.getGlobalMatrix(sel)
#convert matrix into readable components
trans, rot, scale = geom.toTRS(mat_global)
#print gobal transform
print(f"translation: {trans}, rotation: {rot}, scale: {scale}")

use this code to get the global matrix.
Your problem is that you are using the global transform (i assume) from the inspector and then set the local matrix with these same values. You are not showing the prodcut structure but this can of course be problematic. You would have to use setglobalMatrix instead of setLocalMatrix, depending on your product structure.

Hi, I used this and perhaps some problems were fixed, but other problems also occurred.

My goal here is to flatten all of these boxes into flat squares oriented in the same direction as the bounding boxes. When I run that script I get this:

As you can see the square is turned in an unexpected direction.

Hi Steven,

I am a bit confused because you are still using “scene.setLocalMatrix” but the given transform parameters are derived from the global matrix. I think you should try to set the global matrix when you get the global matrix in the first place. Or decide to use local Matrix throughout your routine.

be aware that you can remove the [0] behind your selection to save the whole array of selected objects that you could then also feed into your replacebyPrimitive function without using the square brackets.

Anyway, I was also wondering if you could not just use the “replaceByBox” function because this function already has a parameter to locally align the boxes. That would probably save you from using any matrixes at all.

If this works, and your boxes are properly aligned, you can then just set a local identity matrix where you just set the scale to 0.1 on Y-axis. But then you do not have to cope with the transforms but just focus on squashing the already correctly aligned boxes.