This patch provides a new attribute "length" for curve splines, to be accessed via
object.data.splines[...].length
in Python and drivers contexts.
Differential D1810
Length attribute for curve splines Authored by Campbell Barton (campbellbarton) on Feb 17 2016, 7:31 PM. Tags None Subscribers None Tokens
Details This patch provides a new attribute "length" for curve splines, to be accessed via object.data.splines[...].length in Python and drivers contexts.
Diff Detail
Event TimelineComment Actions If we add this, it should be a function calc_length(), since its an expensive calculation and not some data we simply read from. This function could take an optional resolution argument to allow for quick approximations for cases when accurate results arent needed. Comment Actions Yes, I actually thought about that (and about the nice additional resolution parameter that could be added in case of a method), but from what I could test, it seems that we then lack the ability to easily use this attribute in a driver. Of course there is still the possibility to use an absolute bpy.data.* path within the scripted expression. Comment Actions So I made the change, it runs well too, except when used in a scripted expression (driver), as it then doesn't get updated when the spline's length does (usage in a driver was actually main part of the original feature request). Comment Actions In this case I think we should add support for driver variables which put the ID in the name-space. So you could reference and object or curve from a driver variable, but let the Python expression access its functions/members. Comment Actions Submitted a patch to support Object data for driver variables: D1812 so a curve can be referenced directly and the Driver expression can be curve.calc_length() Comment Actions Looks good with D1812. (Still a click on "Update Dependencies" is needed, but that's normal, right?) |