Change the material

I want change the material of suction cup on the gripper when it’s gripping the product.
The code is shown below, it was working fine on my laptop,but It did’t work on my desktop

from vcScript import *
from vcMaterial import *

app = getApplication()
comp = getComponent()
sim = app.getSimulation()

link = comp.findNode(“Link_0”)
link.MaterialInheritance = VC_MATERIAL_FORCE_INHERIT

red = app.findMaterial(“red”)
green = app.findMaterial(“green”)

def OnRun():

link1 = comp.findNode("Link_1") 
while True:
  while not (link1.J1 == 46.0):
    link.NodeMaterial = green
    app.render() 
    delay(0.1)       
  else:
    link.NodeMaterial = red
    app.render()
    delay(0.1)

Comparing floating point values exactly is a bad idea as they rarely are exactly some value. You need some tolerance like while abs(link1.J1 - 46) > 0.01:

Hy,

for comparing floats I use this:

def isclose(a, b, rel_tol=1e-09, abs_tol=0.0):
    return abs(a-b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)

Source:

Regards
Feature

Hi
I see, thanks for your reply.