Python script shows message twice in command line

Hi
I’m having this problem with a simple script in a grasshopper definition
You have to select one object and then all the objects with the same name are selected and a message is shown in the command line bar.
I open the grasshopper definition in the grasshopper player,everything works fine except that it shows the message twice.

If I#m running it within grasshopper, everything works fine.

I checked some similar problems but could not find a solution. I am a Python beginner.

Script:
import Rhino as rc
import scriptcontext as sc
import rhinoscriptsyntax as rs

guids = (x)
sc.doc = rc.RhinoDoc.ActiveDoc
rs.SelectObjects(guids)

rc.RhinoApp.WriteLine (y)

What am I doing wrong?


2_2_Select_Same_Name.gh (15.1 KB)

the *.gh has no internalized geometry, so it is hard to recreate your exact setup.

my first things to investigate would be:

  • y argument of the python component is in item access, check if there are two entries in variable. if so, it gets executed twice.

some more advice as you are a python:

  • concatenate can be also done in python, way more conveniently than in gh. check out f-strings:

Thanx for the quick response Dan

The Y argument gives only one entry so it is executed only once. (Pict 1)

I understand the “concatenating” solution in Python but then I still need to use the “WriteLine” function. When I use only text, it still doubles in the command line. Maybe I’m wrong but that would happen too when concatenating in Python in the script, right?


Btw You should be able to test the gh definition on any geometry, as long as it has a name. The geometry is not the problem, I tried it on several.

It’s definitely the Get Geometry component firing twice (it runs once before the object is selected, and twice more after selecting).

sounds logical Mr.Measure.
I tried several ways to locate the source and in the end it were 3 containers left as suspects(get geometry, model object, query model object).But it only happens when the grasshopper definition is called through grasshopper player, then it shows twice. When used in grasshopper it shows, correctly, only once.

Now the obvious question would be: How to fix it?

As a workaround, you could have your python script store a variable in the sc.sticky dictionary and only run if it hasn’t already run.

2_2_Select_Same_Name.gh (14.8 KB)