Discussion:
[Bf-python] Scale in object_mode loss edges length
Giuseppe De Marco
2015-04-05 16:40:08 UTC
Permalink
Hi all,

I realized that an addon that I wrote wasn't so usefull as I tought in
the past, when I learned blender more in the deep I understand other
way to get it where's needed.

https://developer.blender.org/T43586

But there's a criticity in Blender, even in the last release.
If I scale a mesh in object mode it changes its dimensions but the
edit attributes, as edges length, remains the same !

This is the nightmare of every CAD users. They could kill for this...
I have to get a workaround because my life is in danger when I try to
explain this criticity to them.

Now I'm coding an addon that intercepts the S keypress in objectmode
to drive it in edit mode - do the things - and then return in object
mode, this because only if we scale in edit_mode the edges length
updates its values as expected.

I've a problem and I'm loosing my self in the API, so my question is:

how to simulate S keypress in blender ?
I don't need the bpy.ops.transform.resize(), I need the mouse
interaction to set new dimensions.
What I have to call to see it on the screen ? I mean the dotted line
linked to the origin of the mesh and the mouse movements that sets in
realtime the dimension of the mesh.

this is the code:


<code>

class ForceScale_EditMode(bpy.types.Operator):
bl_idname = 'object.force_scale_edit'
bl_label = 'force_scale_edit'
bl_description = bl_info['description']
#bl_options = {'REGISTER', 'UNDO'}


def execute(self, context):
self.report({'INFO'}, 'executed')
# force to go in edit mode
bpy.ops.object.mode_set(mode = 'EDIT')

# selects all vertices
bpy.ops.mesh.select_all(action="SELECT")

# call the scale trigger to play with mouse
# unknow function /event / whatever :(

# if scale committed returns in object_mode and then finish
# else: return to object_mode.

return {'FINISHED'}

</code>

any hint would be helpfull
cheers
Daniel Salazar - patazstudio.com
2015-04-05 16:59:44 UTC
Permalink
My gawd why don't you apply the scale of the object?
Daniel Salazar
patazstudio.com
Post by Giuseppe De Marco
Hi all,
I realized that an addon that I wrote wasn't so usefull as I tought in
the past, when I learned blender more in the deep I understand other
way to get it where's needed.
https://developer.blender.org/T43586
But there's a criticity in Blender, even in the last release.
If I scale a mesh in object mode it changes its dimensions but the
edit attributes, as edges length, remains the same !
This is the nightmare of every CAD users. They could kill for this...
I have to get a workaround because my life is in danger when I try to
explain this criticity to them.
Now I'm coding an addon that intercepts the S keypress in objectmode
to drive it in edit mode - do the things - and then return in object
mode, this because only if we scale in edit_mode the edges length
updates its values as expected.
how to simulate S keypress in blender ?
I don't need the bpy.ops.transform.resize(), I need the mouse
interaction to set new dimensions.
What I have to call to see it on the screen ? I mean the dotted line
linked to the origin of the mesh and the mouse movements that sets in
realtime the dimension of the mesh.
<code>
bl_idname = 'object.force_scale_edit'
bl_label = 'force_scale_edit'
bl_description = bl_info['description']
#bl_options = {'REGISTER', 'UNDO'}
self.report({'INFO'}, 'executed')
# force to go in edit mode
bpy.ops.object.mode_set(mode = 'EDIT')
# selects all vertices
bpy.ops.mesh.select_all(action="SELECT")
# call the scale trigger to play with mouse
# unknow function /event / whatever :(
# if scale committed returns in object_mode and then finish
# else: return to object_mode.
return {'FINISHED'}
</code>
any hint would be helpfull
cheers
_______________________________________________
Bf-python mailing list
http://lists.blender.org/mailman/listinfo/bf-python
Jenny
2015-04-05 17:09:13 UTC
Permalink
Hi Giuseppe,

If you transform/rotate/scale in Object mode, you need to apply the
transformation in order for the attributes to be reflected.

Take a look at `Apply Object transformations`:
http://wiki.blender.org/index.php/Doc:2.6/Manual/3D_interaction/Transform_Control/Reset_Object_Transformations

For scaling, after you scale, you can call:
bpy.ops.object.transform_apply(location=False, rotation=False, scale=True)

I don't think it's great to intercept keystrokes. I think the reason why
people might be frustrated (why scaling in Object mode doesn't behave as
they expect) comes from a lack of understanding of how the tools work.

Hope this helps,
Jenny
Post by Daniel Salazar - patazstudio.com
My gawd why don't you apply the scale of the object?
Daniel Salazar
patazstudio.com
Post by Giuseppe De Marco
Hi all,
I realized that an addon that I wrote wasn't so usefull as I tought in
the past, when I learned blender more in the deep I understand other
way to get it where's needed.
https://developer.blender.org/T43586
But there's a criticity in Blender, even in the last release.
If I scale a mesh in object mode it changes its dimensions but the
edit attributes, as edges length, remains the same !
This is the nightmare of every CAD users. They could kill for this...
I have to get a workaround because my life is in danger when I try to
explain this criticity to them.
Now I'm coding an addon that intercepts the S keypress in objectmode
to drive it in edit mode - do the things - and then return in object
mode, this because only if we scale in edit_mode the edges length
updates its values as expected.
how to simulate S keypress in blender ?
I don't need the bpy.ops.transform.resize(), I need the mouse
interaction to set new dimensions.
What I have to call to see it on the screen ? I mean the dotted line
linked to the origin of the mesh and the mouse movements that sets in
realtime the dimension of the mesh.
<code>
bl_idname = 'object.force_scale_edit'
bl_label = 'force_scale_edit'
bl_description = bl_info['description']
#bl_options = {'REGISTER', 'UNDO'}
self.report({'INFO'}, 'executed')
# force to go in edit mode
bpy.ops.object.mode_set(mode = 'EDIT')
# selects all vertices
bpy.ops.mesh.select_all(action="SELECT")
# call the scale trigger to play with mouse
# unknow function /event / whatever :(
# if scale committed returns in object_mode and then finish
# else: return to object_mode.
return {'FINISHED'}
</code>
any hint would be helpfull
cheers
_______________________________________________
Bf-python mailing list
http://lists.blender.org/mailman/listinfo/bf-python
_______________________________________________
Bf-python mailing list
http://lists.blender.org/mailman/listinfo/bf-python
Giuseppe De Marco
2015-04-07 09:33:34 UTC
Permalink
Post by Jenny
http://wiki.blender.org/index.php/Doc:2.6/Manual/3D_interaction/Transform_Control/Reset_Object_Transformations
Thank you, never seen it before ! Very exaustive.
Post by Jenny
bpy.ops.object.transform_apply(location=False, rotation=False, scale=True)
Ok, this is the method that apply transformation as the UI. I saw in
API and tested it in console without knowing conceptually what it
really does.
Post by Jenny
I don't think it's great to intercept keystrokes. I think the reason why people might be frustrated (why scaling in Object mode doesn't behave as they expect) comes from a lack of understanding of how the tools work.
You're right, together with the possibility that a user could
customize his shortcuts in every moment.
First of all I learned how to apply the transformation in object mode,
this is very important.

But, talking in python, if a day there will be the need to know this,
how to call, from pycode, the mouse pointer with the pivot point for
configuring the desidered value ? ... As the scale UI function does.
How to call the scale function, from console, in a way that it's as we
called it from UI.
Jenny
2015-04-14 15:17:25 UTC
Permalink
Hi Giuseppe,

I'm not sure if you'd asked a question in your last email, so I didn't
respond.
However, I just took a look again, and it seems you have.

I don't think there's a way to invoke the scale helper via the Python API.
If you want something more custom, you might need to check out the C/C++
source. https://developer.blender.org/diffusion/B/

If you want to set custom pivots, check out
http://blender.stackexchange.com/questions/5359/how-to-set-cursor-location-pivot-point-in-script

-Jenny
Post by Jenny
http://wiki.blender.org/index.php/Doc:2.6/Manual/3D_interaction/Transform_Control/Reset_Object_Transformations
Thank you, never seen it before ! Very exaustive.
Post by Jenny
bpy.ops.object.transform_apply(location=False, rotation=False,
scale=True)
Ok, this is the method that apply transformation as the UI. I saw in
API and tested it in console without knowing conceptually what it
really does.
Post by Jenny
I don't think it's great to intercept keystrokes. I think the reason why
people might be frustrated (why scaling in Object mode doesn't behave as
they expect) comes from a lack of understanding of how the tools work.
You're right, together with the possibility that a user could
customize his shortcuts in every moment.
First of all I learned how to apply the transformation in object mode,
this is very important.
But, talking in python, if a day there will be the need to know this,
how to call, from pycode, the mouse pointer with the pivot point for
configuring the desidered value ? ... As the scale UI function does.
How to call the scale function, from console, in a way that it's as we
called it from UI.
_______________________________________________
Bf-python mailing list
http://lists.blender.org/mailman/listinfo/bf-python
Campbell Barton
2015-04-20 01:59:43 UTC
Permalink
Normally if you want to scale in Python, its more flexible to
matrix-transform the data directly.

::
scale_mat = mathutils.Matrix.Scale(myscale, 4)
mesh.transform(scale_mat)

You can construct a matrix transform/rotate/scale, and can operate on
data, without first having to setup edit-mode.

We have this all data types.

http://www.blender.org/api/blender_python_api_2_74_release/bmesh.types.html?highlight=transform#bmesh.types.BMesh.transform

http://www.blender.org/api/blender_python_api_2_74_release/bpy.types.Armature.html?highlight=transform#bpy.types.Armature.transform

http://www.blender.org/api/blender_python_api_2_74_release/bpy.types.Curve.html?highlight=transform#bpy.types.Curve.transform

... do an API search for 'transform' to see all.
Post by Jenny
Hi Giuseppe,
I'm not sure if you'd asked a question in your last email, so I didn't
respond.
However, I just took a look again, and it seems you have.
I don't think there's a way to invoke the scale helper via the Python API.
If you want something more custom, you might need to check out the C/C++
source. https://developer.blender.org/diffusion/B/
If you want to set custom pivots, check out
http://blender.stackexchange.com/questions/5359/how-to-set-cursor-location-pivot-point-in-script
-Jenny
Post by Giuseppe De Marco
Post by Jenny
http://wiki.blender.org/index.php/Doc:2.6/Manual/3D_interaction/Transform_Control/Reset_Object_Transformations
Thank you, never seen it before ! Very exaustive.
Post by Jenny
bpy.ops.object.transform_apply(location=False, rotation=False, scale=True)
Ok, this is the method that apply transformation as the UI. I saw in
API and tested it in console without knowing conceptually what it
really does.
Post by Jenny
I don't think it's great to intercept keystrokes. I think the reason why
people might be frustrated (why scaling in Object mode doesn't behave as
they expect) comes from a lack of understanding of how the tools work.
You're right, together with the possibility that a user could
customize his shortcuts in every moment.
First of all I learned how to apply the transformation in object mode,
this is very important.
But, talking in python, if a day there will be the need to know this,
how to call, from pycode, the mouse pointer with the pivot point for
configuring the desidered value ? ... As the scale UI function does.
How to call the scale function, from console, in a way that it's as we
called it from UI.
_______________________________________________
Bf-python mailing list
http://lists.blender.org/mailman/listinfo/bf-python
_______________________________________________
Bf-python mailing list
http://lists.blender.org/mailman/listinfo/bf-python
--
- Campbell
Loading...