Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5743

Frustrating experience with Python code which sometimes work and sometimes doesn't, same input

$
0
0

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.
Inputs:
x: The x script variable
y: The y script variable
Output:
a: The a output variable”""

author = “pascal”
version = “2018.03.02”

import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc
from scriptcontext import doc

U = False

if y:
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)

3 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 5743

Trending Articles