Nullify String.ToNumber Warning If String Input Is Empty

Afternoon,
Quick one hopefully is there a simple way to nullify the String.ToNumber warning on an empty string input?

Cheers KS

Hi @Kai not really sure, but you can suppress the yellow warning as here, but still give null…or you can dismiss the warning…but again depends what is for i would say

1 Like

Cheers @sovitek ,
Trying to stop warning in Dynamo player if possible.
Basically need to run graph to get a list then user picks corresponding number (ie index) before proceeding.
Will have another attempt tomorrow


Cheers KS

1 Like

If it works in your workflow you could use list.clean from genius loci package

As the users are providing the input in a string format, String.FromObject isn’t needed. In fact you could just use a number slider and be done with it.

Then the List.GetItemAtIndex node without the index input will work cleanly. However it may not resolve what @Kai is after as the user won’t know what index they want until after the graph runs.

To ‘select’ an option from an unknown list you need to partially run the graph to get the list, and then trigger a UI for the user to select an option from the list, and then select all the options downstream from that. This cannot be accomplished via Dynamo Player alone as the run cannot be interrupted for new inputs. However the Datashapes UI++ nodes will allow the exact sequence by triggering a second UI after player starts to run. Look into the options there but know this is also tying IronPython2 into the mix for the WinForm to be produced.

3 Likes

Hi,
I tried with CPython
I’m not super talented either

I think Data Shapes is 100 times better than a solution like presented here


reponse 7 mars 2024

Python script
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

import System
clr.AddReference('System.Drawing')
clr.AddReference('System.Windows.Forms')

import System.Drawing
import System.Windows.Forms

from System.Drawing import *
from System.Windows.Forms import *

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import TaskDialog

txt= IN[0]
TaskDialog.Show("essai",txt[0])

class MainForm(Form):
	def __init__(self):
		self.InitializeComponent()
	
	def InitializeComponent(self):
		self._label1 = System.Windows.Forms.Label()
		self._numericUpDown1 = System.Windows.Forms.NumericUpDown()
		self._textBox1 = System.Windows.Forms.TextBox()
		self._button1 = System.Windows.Forms.Button()
		self._numericUpDown1.BeginInit()
		self.SuspendLayout()
		# 
		# label1
		# 
		self._label1.Font = System.Drawing.Font("Microsoft Sans Serif", 12, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
		self._label1.Location = System.Drawing.Point(16, 28)
		self._label1.Name = "label1"
		self._label1.Size = System.Drawing.Size(171, 23)
		self._label1.TabIndex = 0
		self._label1.Text = "Index"
		self._label1.Click += self.Label1Click
		# 
		# numericUpDown1
		# 
		self._numericUpDown1.Font = System.Drawing.Font("Microsoft Sans Serif", 12, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0)
		self._numericUpDown1.Location = System.Drawing.Point(193, 25)
		self._numericUpDown1.Name = "numericUpDown1"
		self._numericUpDown1.Size = System.Drawing.Size(54, 26)
		self._numericUpDown1.TabIndex = 0
		# 
		# textBox1
		# 
		self._textBox1.Font = System.Drawing.Font("Microsoft Sans Serif", 15.75, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0)
		self._textBox1.Location = System.Drawing.Point(387, 162)
		self._textBox1.Name = "textBox1"
		self._textBox1.Size = System.Drawing.Size(231, 31)
		self._textBox1.TabIndex = 7
		# 
		# button1
		# 
		self._button1.Font = System.Drawing.Font("Microsoft Sans Serif", 12, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
		self._button1.Location = System.Drawing.Point(440, 79)
		self._button1.Name = "button1"
		self._button1.Size = System.Drawing.Size(132, 40)
		self._button1.TabIndex = 8
		self._button1.Text = "Send"
		self._button1.UseVisualStyleBackColor = True
		self._button1.Click += self.calcul
		#
		# MainForm
		# 
		self.ClientSize = System.Drawing.Size(621, 620)
		self.Controls.Add(self._button1)
		self.Controls.Add(self._textBox1)
		self.Controls.Add(self._numericUpDown1)
		self.Controls.Add(self._label1)
		self.Name = "MainForm"
		self.Text = "attribute the index"
		self._numericUpDown1.EndInit()
		self.ResumeLayout(False)
		self.PerformLayout()


	def calcul(self, sender, e):
		b=str(self._numericUpDown1.Value)
		self._textBox1.Text = str(round(eval(b)))

	def Label1Click(self, sender, e):
		pass

a=MainForm()

a.ShowDialog()

OUT =a._textBox1.Text

cordially
christian.stan

1 Like

Thanks all will have a look at data shapes… to be honest there will probably be only myself and one other guy running it on any regularity. So could potentially live with the warning and let users know they need to run it (hit play) twice on the odd occasion anyone else uses it. Once to trigger the list input and second time to run their selection once they have added it.:thinking:

2 Likes