A user has exposed my poor scripting skills. I’m just beginning the debugging and can’t see anything that looks to be responsible.
A surface has thickness usertext attributed to it, not attached to geometry so it should be resilient. A “property checker” confirms that the thickness (and other attributes) is assigned. Another script (below) changes the objects colour (rs.ObjectColor) based on the thickness attribute, but in the process nukes all the usertext attributes (thickness, name, etc…) of some of the surfaces.
While debugging, running this script once seems to work, nothing gets nuked and the colours get changed properly. But if I run it again straight away some of the parts are nuked, but not all of the ones with the same thickness. Actually, it looks like the usertext gets nuked on the first run, but is only apparent after the second run.
I have tried to avoid adding any usertext to geometry because I don’t want it to be volatile, but it may’ve slipped in over the intermittent years of development. But objectcolor change should not nuke geometry usertext.
It isn’t a particularly complex script.
Loop through the objects
import rhinoscriptsyntax as rs import System from System.Drawing import Color def colourparts(): strSurfIDs = rs.GetObjects("Please select surfaces to colour.", 24, True, True) if not strSurfIDs: return strAttribute = "Thickness" if not strAttribute: return for strSurfID in strSurfIDs: strValue = rs.GetUserText(strSurfID, strAttribute) #Object Attribute Value index_Material = rs.AddMaterialToObject(strSurfID) #In case viewport is rendered if strValue == "3": color = Color.LightCoral elif strValue == "4": color = Color.Green elif strValue == "5": color = Color.HotPink elif strValue == "6": color = Color.Olive elif strValue == "8": color = Color.Purple elif strValue == "10": color = Color.RoyalBlue elif strValue == "12": color = Color.DarkSeaGreen else: color = Color.Black objColour = rs.ObjectColor(strSurfID, color) matColour = rs.MaterialColor(index_Material, color) if __name__ == '__main__': colourparts()
Coloured by layer
After first run of colour by thickness script (correct colour, but all usertext of affected parts is nuked).
After second run of colour by thickness script (incorrect, grey part has had all usertext nuked).
Why would the attached script nuke any usertext?