I have a simple piece of code that sometimes does not work and after a while does. It’s driving me insane as it is impossible to debug. The original code comes from here
I am trying to get the Scale value of Blocks. I am using BlockInstanceXform() to get the form. I am getting a ‘unable to find InstanceObject’ … until I am no longer getting the error and the code works. No change in the script, no change in the inputs, nothing! How is it possible that the exact same piece of code will sometimes fail and sometimes not fail? This is deeply frustrating and I am happy to find out what I am doing wrong to be causing this behavior.
The simple code:
“”“Provides a scripting component.
x: The x script variable
y: The y script variable
a: The a output variable”""
author = “pascal”
version = “2018.03.02”
import rhinoscriptsyntax as rs
import scriptcontext as sc
from scriptcontext import doc
U = False
xform = rs.BlockInstanceXform(x)
scaleX = Rhino.Geometry.Vector3d(xform.M00,xform.M10,xform.M20).Length scaleY = Rhino.Geometry.Vector3d(xform.M01, xform.M11,xform.M21).Length scaleZ = Rhino.Geometry.Vector3d(xform.M02, xform.M12, xform.M22).Length if scaleX == scaleY == scaleZ: U = True print "X scale = " + str(scaleX) + " Y scale = " + str(scaleY) +" Z scale = " + str(scaleZ)