Totally useless scripts in Dynamo

After the discussion last night about loops (which I must admit may have involved wine)… I thought it’d be fun to create a script that did one thing… then did the next thing… and so on…

I can’t seem to get it to flow right on periodic… So I’ve put it in player and hit run, run, run…

So it runs through the entire list… Then when the list is finished …
you get this:

It’ll work with any length of list…

If anyone fancies trying to make it work on periodic I’d like to see how you actually did it.

periodic.dyn (7.4 KB)

WARNING This alters the project parameter, “Author” … so don’t go running it in a live Revit project. :smile:

You’ll need IronPython for it to work… Unless the Py3 stuff has been fixed?

1 Like

I think there is a misunderstanding here
Periodic in Dynamo terms is what you get if you use a DateTimeNow node

Yes… but I couldn’t get it to work even using that…

Try and see. :slight_smile:

Why use mouse clicks anyway? DateTimeNow can get things moving

Yes… See if you can make that script I posted work.

The biggest misconception about the Periodic Run type is that it just runs continuously and automatically, when it doesn’t. It executes at the specific interval but still follows all the same runtime rules for code execution. It won’t just ignore all issues and then execute when it can.

If you want your code to run in Periodic, then you have to take into account when your code is running and when it isn’t. For example, if you set the graph to execute every second, then you would have to ensure that your code was able to execute and complete in less than a second. If you have any user interactions in your code, then your code is going to pause for some amount of time. You have to be sure that the pause will not interrupt the periodic execution of the code. I don’t think any of that is an issue with your specific code, but it’s always worth considering.

Just plugging the DateTime.Now node into an unused port is enough to make the python dialog run after each interaction, but that may not be the experience you’re looking for. You’d at least want an end condition so that the dialog doesn’t repeat indefinitely.

2 Likes

I tried that but it seemed to work for 2-3 runs then stop.
I tried the periodic into another python node that changed from A-F every 10 seconds but that also didn’t make the other node update enough times (even though it only needs to run through 7 iterations on the one pasted).

I’ve only ever used periodic for fun moving things before… I was actually surprised this didn’t work easily.

How exactly do you expect it to work?

This works for me with no other changes:

3 Likes

Oh… How strange. It went, 1, 2, 3 and stopped for me.

As I said, I also tried plugging the date time into another Python node too.

Is it possible to get it to work in Py3 yet?

The issue with WinForms? I don’t believe so. I don’t know of any issues with CP3 and Periodic though.

Yes, I mean the winforms.

I believe PythonNet3 does fix those issues (along with many others). You can download it and give it a try.

2 Likes

Hi @Alien

this syntax work only on IronPython (define proprieties directly in constructor like C#)

label = Label(Text=Title_text)

here the fixed code for Cpython3 or PythonNet3

import clr
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

import System
from System.Windows.Forms import *
from System.Drawing import *
from System.Net import *
from System.IO import MemoryStream
import os
from System.Diagnostics import Process
import math
from System.Runtime.InteropServices import Marshal
import random 

Top_strip_text = "Alien woz ere"

# **Get current document**
doc = DocumentManager.Instance.CurrentDBDocument
proj_info = doc.ProjectInformation
param_name = "Auteur"

# **Start a transaction to modify the document**
TransactionManager.Instance.EnsureInTransaction(doc)
param = proj_info.LookupParameter(param_name)


try:
    current_value = int(param.AsString())  
    new_value = current_value + 1  
except (ValueError, TypeError):
    new_value = 0  

# **Set the new value for next run**
param.Set(str(new_value)) 
TransactionManager.Instance.TransactionTaskDone()


stuffIN = list(IN[0])  

if new_value < len(stuffIN):
    Title_text = stuffIN[new_value]  # Get the message at index
else:
    Title_text = "FINISHED"  # End message if out of range


### **Create UI Window**
class CreateWindow(Form):
    def __init__(self):
        super().__init__()
        self.Name = "Create Window"
        self.Text = Top_strip_text
        self.Size = Size(380, 230)  # Overall size
        self.CenterToScreen()
        
        label = Label()
        label.Text=Title_text
        label.Parent = self
        label.Location = Point(200, 20)
        label.AutoSize = False
        label.Height = 100
        label.Width = 150
        label.Font = System.Drawing.Font("Arial", 16, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
        label.ForeColor = Color.CornflowerBlue

        picBox = PictureBox()
        picBox.SizeMode = PictureBoxSizeMode.AutoSize
        picBox.Location = System.Drawing.Point(20, 20)        
        
        # Download the image from a URL
        imagePath = r"https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/alien/144/40701_2.png"
        client = WebClient()
        data = client.DownloadData(imagePath)        
        memoryStream = MemoryStream(data)        
        image = Image.FromStream(memoryStream)
        picBox.Image = image        
        self.Controls.Add(picBox) 

        self.button = Button()
        self.button.Parent = self
        self.button.Text = "Yay!"
        self.button.Location = Point(230, 130)
        self.button.Width = 100
        self.button.Height = 30
        self.button.Click += self.ButtonClicked
        self.button.BackColor = Color.CornflowerBlue
        self.button.ForeColor = Color.White     
        self.button.Font = Font(label.Font.Name, 10)
        
        # **Make the form always on top**
        self.TopMost = True

    def ButtonClicked(self, sender, args):
        self.Close()


form = CreateWindow()
form.ShowDialog()

OUT = new_value
1 Like