Problem while scripting in GH-python using loop

Hi all,

I am looking for someone to help as I am facing some problem while scripting something using For loop in GH-Python.
The desired output is a list of values.
All the steps are written in the file that is attached herewith. A screenshot is also attached here.
Waiting for the valuable replies.
Thank you (8.4 KB)

Two things from a quick look:

  1. Your white space/indentation is all over the place.
  2. You should set appropriate Access and Type Hints on your inputs.

Sorry but I did not get your first point. Can you explain a it a bit more?


What Copy/Paste?

:smiley:, never mind.

Usually when you copy/paste pieces of code your indentation goes haywire.

1 Like

But I tried to write it by myself and it is not working. May be it is too difficult to understand.

I am not at my PC, but usually if the indentation is wrong you would get an error. From the screenshot it is not visible. Have you tried to flatten the output? Currently you are getting a data tree. If you want a list, like you stated in the original post, then perhaps you must flatten the output.

Flatten the output is not giving the output either :frowning:

Specifically, distance is not a list, hence your E only ever holds one item, and you never start your first loop. Made some highlights here:

I have simplified things in GH-Python file now. May this will help understanding (8.8 KB)

The float command is not working with “List Access” so as the entire code. What to do next?

There is a lot of strange things going on here (like the break calls). But basically you need to understand the type of data you are inputting. If you set your distance input to List Access and your Type Hint to float, it will be a Python list of floats. So you could do something like this (note that your indentation still has a space too many):

I am new to GH and Python that is why I am lacking in the understandings.

I have managed to split the code into different steps, but I still need to combine it in one file. See if you can still help. Please. (12.9 KB)

Hi Zohaibneduet

You can do this:

import rhinoscriptsyntax as rs
import math as ma
E   = []
list1 = []
list2 = []
list3 = []

for i in xrange(len(x)):
    Area = ma.pi* ma.pow(R,2)
    num = Area * float(x[i])
    pt1 = float(num)
        pt2 = float(Area * float(x[i+1]))
        print pt2
        dE = (pt2)-(pt1)
        alpha = dE - x[i]
    Final_E= alpha * num

a = E
b = list1
c = list2
d = list3

You can’t use the “Panel” component input, which will cause errors.

my gh file:
Problem (1).gh (14.4 KB)


@603419608 Thanks a lot! Your Code is working fine. But I need to output only one list i.e “d” in this case, but when I am applying “if” loop in the beginning then it is not displaying the output list in panel.

I have attached my file herewith. Can you please guide a little more?

Thanks once again.

My file: (9.4 KB)

Hi Zohaibneduet
“Value List” component output null.

my gh file: (12.5 KB)

1 Like

Thanks a lot @603419608 it is working, but can’t we do it by using if loop in the script, without using the panel as output with value list?

Just like it was done in some previous work of mine.

screen shot:

Value_list used in previous work is :Value_List

@603419608 Aha! Thanks a lot for your valuable guidance man! Your code really worked!

I found my basic mistake, it was just “Circular” instead of ‘Circular’ when providing to Value_list.

Thanks a lot again :slight_smile: