Jump to content
Sign in to follow this  
jeroen-somers

Plugin question

Recommended Posts

Posted · Plugin question

Hi there all,

I don't know if its been asked before (I've looked but couldn't find it).

I am writing a Cura Plugin to display the current .gcode file that is selected from the SD card.

Only I can't get the plugin working so maybe you could help me out here.

What I want is that the message >> M117 Printing... <<

is replaced with >> M117 ("filename".gcode) <<

This is my plugin so far:

--------------------------------------

#Name: Display Name

#Info: Shows the name of the file on the display.

#Type: postprocess

import re, os.path

def getFilename():

return os.path.basename(filename)

with open(filename, "r") as f:

lines = f.readlines()

with open(filename, "w") as f:

for line in lines:

if line.startswith('M117'):

filename = getFilename()

f.write("M117 " + filename + '\n')

else :

f.write(line)

-------------------------------------

what it does, it replaces the printing message > M117 Printing...

with this >> M117 CuraPluginTempz3u6ub

This isn't my ("filename".gcode)

This is some random temp file that is made when you save your cura model to .gcode

If you need more information just say so.

I hope someone can help me with this

With kind regards,

Jeroen Somers

 

Share this post


Link to post
Share on other sites
Posted · Plugin question

The plugin runs before you save the file. Therefore it cannot know the final filename. The only thing it can know is the name of the temporary file created by Cura and handed over to the plugin.

 

Share this post


Link to post
Share on other sites
Posted · Plugin question

The plugin runs before you save the file. Therefore it cannot know the final filename. The only thing it can know is the name of the temporary file created by Cura and handed over to the plugin.

 

But the filename is created by the model you load, this model has a name and when you save it it becomes (modelname.gcode). And the model is loaded before the Plugin.

Isn't there a way to get this name?

 

Share this post


Link to post
Share on other sites
Posted · Plugin question

Not at the moment as far as I know. Cura would have to pass the model name over to the plugin. Daid might prove me wrong.

 

Share this post


Link to post
Share on other sites
Posted · Plugin question

You could do it post save instead of with a plugin. This way you can open the saved file and change it.

Look for _saveGCode function in Cura/gui/sceneView.py

 

Share this post


Link to post
Share on other sites
Posted · Plugin question

A simple solution could be if cura would create a random directory and give the file its normal basename. But yeah, this might need some cura changes. At some point the start.gcode had placeholders for the filename, but they were never replaced with the actual filename.

 

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×
×
  • Create New...

Important Information

Welcome to the Ultimaker Community of 3D printing experts. Visit the following links to read more about our Terms of Use or our Privacy Policy. Thank you!