Jump to content

Script Message: Auto Update


Recommended Posts

Please excuse the rapid-fire new threads, I'm on a roll of ideas tonight.

 

I've been asked by someone in the office to do something that sounds simple, but I think involves quite a bit. I would like a script message on screen that updates itself whenever there is pertinent data.

 

I have a simple script that generates this Message on command. It's job is to display the highest Cable value used in the file.

maxglobal = 0
maxlocal = 5000

def scancircuit(h):
	global cab, maxglobal, maxlocal
	try:
		cab = int(vs.GetRField(h, 'Circuit', 'Cable'))
		type = vs.GetRField(h, 'Circuit_Options', 'Local Circuit')
		if type == 'True' and cab > 5000:
			maxlocal = max(maxlocal, cab)
		elif type == 'False' and cab < 5000:
			maxglobal = max(maxglobal, cab)
	except:
		pass

def process():
	vs.ForEachObject(scancircuit, "PON = 'Circuit'")

process()

nextlocal = int(maxlocal) +1
nextglobal = int(maxglobal) +1

vs.Message(f"Next Cable ID: {nextglobal}.{os.linesep}{os.linesep}Next Cable ID (Local Circuit): {nextlocal}{os.linesep}{os.linesep}Re-run 'Show Next Circuit' to see current values")

 

It works great manually, but if the user was to renumber some cables, the data in the message box is now out of date, and needs to be refreshed manually.

 

I would like it such that if any Circuit object in the drawing has a Cable field changed, this script executes to refresh the message box. Can my script somehow be aware of other things going on in the file?

 

Is this something I should run away fast from?

 

Thanks,

 

Simon

Edited by spettitt
Link to comment
4 minutes ago, JBenghiat said:

No — Python can’t run in the background and could only be triggered from the circuit object code. You need the SDK if you want to implement a listener. 

Thank you Josh, I suspected as much. Maybe it's a project to dive in to the SDK with over the break then.

 

Cheers

Link to comment

yeah, sadly python can't run in the background... I would kill for some JS eventlistener style functionality that can run a script when stuff happens. maybe ill submit that as a feature request one day... 

 

let me know if you end up diving into the SDK and how scary it is, I keep meaning to play around with it but I know NOTHING about C++. lol

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...