Help for Enable disable in python grasshopper components

hi everyone
Enable disable in python grasshopper components
in this code doesn’t to disable the component and nothings happening !!
please help me to control this by python or c# scripts ( i doesn’t want use mettahopper plugin )


import Grasshopper as gh
for obj in ghenv.Component.OnPingDocument().Objects:
    if obj.NickName == NickName:
        obj.Locked = Enable

Enable disable in python grasshopper components.gh (13.3 KB)


@dale
@Mahdiyar
@Jarek

maybe this:

obj.ExpireSolution(True)

1 Like

def callback(doc):
  for obj in doc.ActiveObjects():
    if obj.NickName in nickNames.AllData():
      obj.Locked = not active
      obj.ExpireSolution(False)
doc = ghenv.Component.OnPingDocument()
doc.ScheduleSolution(5, callback)
private void RunScript(DataTree<string> nickNames, bool active, ref object A)
{
  _nickNames = nickNames;
  _active = active;
  GrasshopperDocument.ScheduleSolution(5, Callback);
}
// <Custom additional code> 
private DataTree<string> _nickNames;
private bool _active;
private void Callback(GH_Document doc)
{
  foreach(var obj in GrasshopperDocument.ActiveObjects())
    if(_nickNames.AllData().Contains(obj.NickName))
    {
      obj.Locked = !_active;
      obj.ExpireSolution(false);
    }
}

Ehsan.gh (12.8 KB)

3 Likes

Thanks @Mahdiyar
@Gijs

If someone need it:

objects = ghenv.Component.OnPingDocument().Objects

for obj in objects: 
    if obj.Name == 'Number':
        if Lock:
            obj.Locked = True
        if Unlock:
            obj.Locked = False
        


objects = ghenv.Component.OnPingDocument().Objects

for obj in objects: 
    if obj.Name == 'Number':
        obj.Locked = Lock

1 Like