[Bf-python] Extra functionality proposals

Campbell Barton ideasman42 at gmail.com
Sun Nov 20 02:34:59 CET 2011


On Sat, Nov 19, 2011 at 6:56 PM, Dima Glibitsky <dima.glib at gmail.com> wrote:
> I propose to add the following functionalities:
>
> * A variant of object.ray_cast that returns all intersections, not
> just the closest one.
> Examples where this can be beneficial:
> - determining whether a point is inside or outside a mesh
> - determining thickness/gaps in the given direction
> - filter intersection results (e.g. consider only frontfacing
> polygons, ignore polygons with transparent material, etc.)
I think this could be added as a helper function, written in python in
'bpy_extras', see -
http://www.blender.org/documentation/blender_python_api_2_60_4/bpy_extras.object_utils.html

It can just do multiple ray casts and step forward each time, casting
from a new point, this is all we would do if it was written in C.
eg:
  bpy_extras.object_utils.ray_cast_multi(..., limit=-1),  where -1 is
unlimited intersections. returns a list of results from ray_cast()


> * A mechanism to temporarily freeze undo history.
> Currently there is no way for scripts to get up-to-date mesh data
> while it is in editmode. Scripts can toggle editmode, but that has a
> nasty consequence of modifying the undo history... The situation may
> change with the arrival of BMesh, but, even then, freezing history
> could still be useful for some other cases I don't know of.
> On the Python level, I suggest it to be implemented as a context manager:
> [CODE]
> with bpy.utils.freeze_undo_history():
>    # ... Do some sneaky operations. Don't forget to return everything
> to where it was!
> # At this point, undo history is the same it was before freeze_undo_history().
> [/CODE]

For mesh tools - current api is dreadfully lacking but I rather write
a BMesh API once BMesh in in trunk.

As for a way to disable undo - calling operators from a script
shouldn't be calling undo. at least calling operators within an
operator wont undo.

Im interested in why undo is being called in your script to begin
with, perhaps that case can be fixed, if it can a context manager
would indeed be a nice way to solve but I rather not have to make
script authors concern themselves about this if possible.

> * UILayout method to display "fake" ID datablock selectors.
> This would be useful for the situations when a script wants to present
> a custom dynamic list of selectable (and, possibly, renamable)
> elements:
> - choosing an object from the custom-filtered list (e.g. from objects
> which have custom property that satisfies some condition)
> - defining and working with custom libraries of domain-specific
> objects (operator presets, game object templates, bookmarked cursor
> positions, etc.)
>
> Example signature:
> UILayout.prop_collection_selector(data, property, name_property,
> search_data, search_property, search_icon='NONE', add_op=None,
> add_icon=None, remove_op=None, remove_icon=None, allow_rename=True)
>
> data -- object from which to take collection
> property -- identifier of the corresponding CollectionProperty member
> name_property -- identifier of item's StringProperty, which has the
> semantics of unique item's name
> search_data -- object that stores active (selected) collection element
> search_property -- identifier of the corresponding StringProperty
> member; has the semantics of active element's name
> search_icon -- icon for drop-down selector
> add_op -- operator for adding items to collection
> add_icon -- add_op icon
> remove_op -- operator for removing items from collection
> remove_icon -- add_op icon
> allow_rename -- if False, the name won't be editable (like in Enum selector)
>
> Also, any conflicting names should be automatically renamed, like
> everywhere else in Blender.
>
> Another solution is to introduce a special kind of Property for such
> cases (e.g. CustomIDBlockProperty).

Currently blender supports a custom collection to display a listview -
rigify uses it,
the same approach can be used for a selector UI though this is not
what you ask for.

Another thing we should have is a enum property selector that displays
as a search box.

As for what you are requesting - a way to fake an ID selector, I'm not
sure about it, can see you might want it but think this adds too much
functionality into the UI, perhaps this could be done as a new
property type. bpy.props.* instead.


> ------------------------
> dairin0d
> _______________________________________________
> Bf-python mailing list
> Bf-python at blender.org
> http://lists.blender.org/mailman/listinfo/bf-python
>



-- 
- Campbell



More information about the Bf-python mailing list