Script Module

I am trying to run a script module when I press a button. If i press the button I get the following error.

Traceback (innermost last):
File “event:mouseClicked”, line 8, in ?
ImportError: Error loading module scheduleCreate: null

Any ideas on what i have done wrong?

Thanks
JP

################################################

Script Module Named scheduleCreate
################################################

def create(LineNumber):
import system, app

#the rest of the script
lineID = LineNumber

This script will run on sunday at midnight (00:00) and create all the scheduled runs for the (mon-sun) week.

#get timestamp
timestamp = system.db.runScalarQuery(“SELECT DATE_FORMAT(NOW(), ‘%Y-%m-%d %H:%i:%s %w’)”)
date = timestamp[:10]
time = timestamp[-10:-5]
day = int(timestamp[-1:]) #0=sunday, 6 = saturday

#######################################

Mouse Clicked Event on Button
###################################

This script was generated automatically by the property set

script builder. You may modify this script, but if you do,

you will not be able to use the property set builder to update

this script without overwriting your changes.

– ERROR – You must choose a destination property path.

LineNumber = event.source.Line
app.scheduleCreate.create(LineNumber) -Line Number 8 in the script editior

####################################

Does your script module scheduleCreate compile ok? Do you only have one function called create? Can you copy and paste your code using the code block so we can see tabs?

Travis,

Yes it compiles with no errors.

[code]# This script was generated automatically by the property set

script builder. You may modify this script, but if you do,

you will not be able to use the property set builder to update

this script without overwriting your changes.

– ERROR – You must choose a destination property path.

LineNumber = event.source.Line
app.scheduleCreate.create(LineNumber)[/code]

[code]def create(LineNumber):
import system, app

#the rest of the script
lineID = LineNumber

This script will run on sunday at midnight (00:00) and create all the scheduled runs for the (mon-sun) week.

#get timestamp
timestamp = system.db.runScalarQuery(“SELECT DATE_FORMAT(NOW(), ‘%Y-%m-%d %H:%i:%s %w’)”)
date = timestamp[:10]
time = timestamp[-10:-5]
day = int(timestamp[-1:]) #0=sunday, 6 = saturday

#check if there is something on the schedule after now
futureEvents = system.db.runScalarQuery(“SELECT COUNT(*) FROM schedule WHERE FinishDateTime > NOW() AND LineID == LineNumber”)
print futureEvents

#check if it’s time to run
if (day == 0 and time == “00:00”) or futureEvents == 0:

if lineID == 1:
	presetQuantity = 10
else:
	presetQuantity = 1

#insert 7 times, one for each day of the week
for i in range(7):
	#get the # of days to add to today
	result = system.db.runQuery("SELECT DATE_FORMAT('%s 00:00:00' + INTERVAL %s DAY, '%%Y-%%m-%%d'), DATE_FORMAT('%s 00:00:00' + INTERVAL %s DAY, '%%Y-%%m-%%d')" %(date, i, date, i+1))
	nextDay = result[0][0]
	dayAfter = result[0][1]
	#get shift start times
	shift1Start = system.db.dateFormat(system.tag.getTagValue("Shift 1 Start Time"), "HH:mm:ss")
	shift2Start = system.db.dateFormat(system.tag.getTagValue("Shift 2 Start Time"), "HH:mm:ss")
	shift3Start = system.db.dateFormat(system.tag.getTagValue("Shift 3 Start Time"), "HH:mm:ss")
	#one insert for each shift, the last one rolls over to the day after
	for i in range(3):
		if i == 0:
			startOfDay = "%s %s" %(nextDay, shift1Start)
			endOfDay = "%s %s" %(nextDay, shift2Start)
		elif i == 1:
			startOfDay = "%s %s" %(nextDay, shift2Start)
			endOfDay = "%s %s" %(nextDay, shift3Start)
		elif i == 2:
			startOfDay = "%s %s" %(nextDay, shift3Start)
			endOfDay = "%s %s" %(dayAfter, shift1Start)
		#insert
		system.db.runPrepUpdate("INSERT INTO schedule (LineID, WorkOrderID, ScheduleType, StartDateTime, FinishDateTime, Quantity, EnteredBy, RunStartDateTime, Timestamp, shift) VALUES (?, 1, 0, ?, ?, ?, 'System', ?, NOW(), ?)", [lineID, startOfDay, endOfDay, presetQuantity, startOfDay, i+1])
print "Schedules for 7 new Days created."[/code]

Make sure that all of the code is tabbed into the create function in your script module. It looks to me that the timestamp = … line is not part of the function which means system is not imported.

Thanks

That was it