Jump to content

Trouble pushing worksheet template: what am I doing wrong?


patjdixon

Recommended Posts

I am trying to follow 'Workbook Templates' example in SPy documentation to push a worksheet template into a workbook.  I believe the correct command is:

spy.push(workbook={new workbook ID that I am pushing to}, worksheet={template worksheet ID that I want to insert into the new workbook})

I find the push gives me a link to the correct workbook that I want to push to, but no worksheet is inserted.  I know that the template worksheet is the correct ID.  If I replace the worksheet ID with a string for a worksheet name, it will insert a blank worksheet with that name.  

See attached files.  What am I doing wrong?

 

seeq_push_code_2023-06-21 at 9.25.11 PM.jpg

seeq_push_instance_2023-06-21 at 9.23.53 PM.jpg

seeq_push_template_2023-06-21 at 9.22.57 PM.jpg

CreateInstancesFromTemplates.ipynb

Link to comment
Share on other sites

  • Seeq Team

Pat if you're only pushing a workbook (and not accompanying that workbook push with calculations as well), you'll use `spy.workbooks.push()` instead of `spy.push()`.

Take a look at the "Using Pre-existing Signals/Conditions/Scalars etc" section of the Workbook Templates.ipynb documentation file:

image.png

Link to comment
Share on other sites

  • Seeq Team

I think this should work:

# Pull the workbook
workbook = spy.workbooks.pull(workbook_id)

# Add the template worksheet
if template_worksheet.name in workbook.worksheets:
    workbook.worksheets[template_worksheet.name] = template_worksheet
else:
    workbook.worksheets.append(template_worksheet)

# Push back up
spy.workbooks.push(workbook)

 

Link to comment
Share on other sites

  • Seeq Team

Sorry, try this:

# Pull the workbook
workbooks = spy.workbooks.pull(workbook_id)
workbook = workbooks[0]

# Add the template worksheet
if template_worksheet.name in workbook.worksheets:
    workbook.worksheets[template_worksheet.name] = template_worksheet
else:
    workbook.worksheets.append(template_worksheet)

# Push back up
spy.workbooks.push(workbook)

 

  • Like 1
Link to comment
Share on other sites

I found a problem.  Append does not append the worksheets in the workbook.  The template worksheet ID gets pushed and just replaces the worksheet that is there.  When you change the worksheet name, the ID is retained so you do not add another worksheet.  It just renames the worksheet already there.  I need a way to append a workbook with instances of the template worksheet.  Ideas?

Link to comment
Share on other sites

To be clear, if I run this 5 times with and rename template_worksheet.name each time, I will end up with 1 worksheet that has the name of the last template_worksheet.name.  What I want is 5 worksheets with the names I assign for each worksheet.

Link to comment
Share on other sites

  • Seeq Team

It's a bit hidden in the documentation, but in this scenario where you're wanting to add several worksheets that use the same template, you'll need to use the copy() function (see below). You must supply a label argument. You'll do this before you assign a name and before you append to the worksheets list.

image.png

Link to comment
Share on other sites

I have it working, but I am getting an error.  It does not prevent execution, but I want to clean it up.  The code I have that is working is:

image.thumb.jpeg.93b2750f4deebddbfdabb33a66205356.jpeg

This does insert new worksheets, but I have errors that seem to indicate push is trying to push the template workbook, which I do not want to do.  I only want to push new worksheets to the existing workbook I have:

image.jpeg.69b97ffc772a390a51234c3bb05541bb.jpeg

WorksheetAppend_testcode.ipynb

Link to comment
Share on other sites

  • Seeq Team

Pat, in the ipynb file you attached, it's showing that the error is 

AttributeError: 'Analysis' object has no attribute 'parameters'

Can you attach a notebook with the dependency error showing (that you took a screenshot of above), and with the stack trace expanded?

Also, for your template worksheet, do you have a Journal with links to worksteps in it? I think that may be causing a problem. (It shouldn't cause a problem... but I need to see what the Journal looks like.)

 

 

Edited by Mark Derbecker
Link to comment
Share on other sites

I think you are right.  Everything seems to work.  I do want the links in the template, but I need to figure out how to get the instance to have those figures (Trend, XY Plot, Table) configured so I don't have to manually recreate them.  I think the Mustache templating system will help.

Actually, looking at the "Workbook Templates" help, it looks like Mustache would only allow variables that are text or signals, not worksteps that would open preset Trend, XY Plot, Table, etc.  Therefore, I think I just have to live with the error messages; I don't see another way.

Link to comment
Share on other sites

  • Seeq Team

Well, actually, that all SHOULD work the way you intend it -- where you have a Journal that opens those preset visualizations.

But it's not working, and I think it's a bug. Can you execute the following lines at the bottom of your notebook and send me the resulting zip files?

spy.workbooks.save(spy.workbooks.load('./PJD_WorksheetTemplate'), 'ForMark-Templates.zip')
spy.workbooks.save(WorkbookInstance_List, 'ForMark-PulledWorkbook.zip')

(I agree with your comment -- the Mustache stuff won't help here.)

Edited by Mark Derbecker
Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...