- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
During my modeling work, I consistently use the built-in measure tool to monitor my assets' dimensions and lengths. Its ability to refresh information in real-time, without the need to repeatedly run the code or press the button, makes it an excellent tool. So, having a real-time updating feature in a shape length measure script can certainly enhance efficiency. As for me, I'm currently working on crafting a simple script that includes shape length information and other object parameters that I usually work with to replace the built-in measure tool and to accelerate my workflow.
However, I've encountered a roadblock. Certain spline codes, including getSplineSelection and numSpline are incompatible with standard shape primitives even with the edit spline modifier added on top. Moreover, curvelength/ getseglengths may yield incorrect values when the object undergoes scaling or has deform modifiers applied.
So my approach is using clone method to create temporary objects from the current selection, resetting their scaling, converting it to editable spline to collapse all modifier stacks and avoid standard shape primitives, then measuring and deleting these objects.
There is, however, a significant issue with the code I've made (detailed in the code below). The original object perpetually refreshes, impeding select any of its modifiers. Selecting sub-object levels also results in substantial errors.
I suspect the root of the problem lies in a conflict between line 21, line23 and the node callback event. This callback refreshes the modify panel and all information within it whenever I select spline objects or sub-object levels of the object.
Questions :
Is there an alternative method that consumes less system performance than object cloning?
If not, what modifications can I apply to the original code to prevent the constant refreshing caused by the conflict between line 21, line23 and the node callback event?
(
fn ShapesLength =
(
local ShapeArr = selection as Array -- to simplify, my current selection only includes Line, Editable_Spline and Edit_Spline object
local ShapeCopyArr = #()
with redraw off
(
ShapeCopyArr = for i in ShapeArr collect (copy i)
for i in ShapeCopyArr do -- try to reset Xform without selecting the dupplicated object
(
i.isHidden = true
i.parent = undefined
local ObjPos = i.position; local ObjRot = i.rotation
i.rotation = (quat 0 0 0 1); i.position = ObjPos
local ObjTm = i.transform; i.transform = transMatrix i.pos
local piv = i.objecttransform * inverse i.transform
i.objectoffsetPos = [0,0,0]; i.objectoffsetRot = (quat 0 0 0 1); i.objectoffsetScale = [1,1,1]; ObjTm.translation = [0,0,0]; ObjTm = piv * ObjTm
local xformMod = XForm(); addmodifier i xformMod; xformMod.gizmo.transform = ObjTm -- ISSUE
i.rotation = ObjRot; i.position = ObjPos
convertToSplineShape i -- ISSUE
)
)
)
fn ShapesLength_Callback ev nd = (ShapesLength())
fn Measure_Callback_On =
(
ShapesLength_Event = undefined
gc()
ShapesLength()
ShapesLength_Event = NodeEventCallback mouseUp:true delay:1000 selectionChanged:ShapesLength_Callback deleted:ShapesLength_Callback \
groupChanged:ShapesLength_Callback geometryChanged:ShapesLength_Callback
)
Measure_Callback_On()
)
Solved! Go to Solution.