I want the first decimal number

Hi! Can anyone see where I should change if I want the first decimal number to appear if it is greater than 0? It is a script that displays the text in a Wall tag.
image

string.Split(“.”) => FirstItem

1 Like

Thanks for the answer @Deniz_Maral! Hmm, I don’t really know where to put those parts? I’ve just started experimenting with the program so I’m trying it out. But as you can see in the picture, I seem to be wrong with the placement as it doesn’t do what I want.

Maybe like this?

Hope that helps,

Mark

Edit :

I find nodes a bit clunky for text manipulation, so I tend to jump to python…

3 Likes

Thanks for the answer @Mark.Ackerley!
I haven’t worked with Phyton at all except that I pasted scripts that others have done. But I guess I can write the Phyton script in Dynamo like I did in the picture? Also don’t know where in Dynamo I should put Phyton?

Hey,

Python is relatively ‘human readable’…

For num in IN[0]… so if you plug your list of numbers into IN[0], python will start looping through that list…

It will round(num to 1 dp), and convert to a STRing.

then If rounded_num ends with .0, it will make num an Integer (ie. no decimals) and then make it a STRing, and add to the output list.

Else, it will add rounded_num to the output list.

Hope that helps,

Mark

1 Like

Sorry I’m a bit slow to keep up with the program. A little unsure which string is “List of numbers”. Does it look right in the picture?

The output from your ‘list no 1’ is a (list of) Strings…


Dynamo is very concerned about Data Types, and if it gets a String where it was expecting a Number, it will get confused.

I would hover over the yellow triangle and read the warning, it probably says ‘unexpected type’ or similar…

If you head back up your graph to before you converted text to strings, you could use the code there?

It would probably be easier if you included more of your graph for us to see :slight_smile: and included the warnings…

Hope that helps,

Mark

1 Like

First of all, I am very grateful for all the help :slightly_smiling_face:
image

So, yes, I think the python node wants to go here…

So it is taking numbers in and giving a list of strings out… You shouldn’t need a bunch of nodes to the right of the python then. Just work your way across, left to right, seeing what the nodes are doing…

1 Like

I tried to put the script in there but as you can see in the picture I got “null”, then looked through the nodes on the right but think that they looks like it is needed. Still tried to remove them because to test but didn’t turn out well.

Can I put a directive in the Python script that is already in the file? as you can see in the picture it finds all 3 decimal places but it has changed 10.500 (as in Revit) to 10.000

Sends the script in case anyone sees what needs to be changed/added

import clr
import sys
pyt_path = r’C:\Program Files (x86)\IronPython 2.7\Lib’
sys.path.append(pyt_path)
from decimal import Decimal

def tolist(input):
if isinstance(input,list):
return input
else:
return [input]

nums = tolist(IN[0])

if IN[1] != 0 :
OUT = [str(round(Decimal(n),IN[1])) for n in nums]
else:
OUT = [str(int(round(Decimal(n),IN[1]))) for n in nums]

you have a typo… the python tells you… rounded not rounden, you don’t want to just ditch something because of a warning, just work your way through methodically, understand what each part is doing and you’ll get there :slight_smile:

1 Like

Thank you so much @Mark.Ackerley ! So grateful that you and the rest of you have taken the time to help me. I almost thought about giving up before the last question since I got it so well described but didn’t get it right. I have dyslexia and am bad at English so even though I went through the script so many times, I didn’t see the little carelessness.

Again, thank you very much! Wish you the best

1 Like