emtrax-ltd / Cura2MoonrakerPlugin

Ultimaker Cura 2 Mooraker Upload Plugin
GNU General Public License v3.0
289 stars 25 forks source link

[FR] replacing dots and whitespace in filenames with an underscore or dash #2

Closed itCarl closed 3 years ago

itCarl commented 3 years ago

it would be really nice if the Plug-in could replace dots and whitespaces/spaces with an underscore or a dash instead of cutting/stripping the Filename.

Examples: i have a .stl file with the filename "_test_headv1.4 (small).stl" current filename handling is like "_test_headv1.[gcode | ufp]" (file extension doesn't really matter in thsi example)

would i would like is something like this "_test_head_v1_4small.gcode" or "_test_head_v14-small.gcode"

EDIT i would really like to inplement it by myself but unfortunately i dont know python that well.

emtrax-ltd commented 3 years ago

there is currently no cutting or stripping algorithm for filenames implemented - it takes the suggestion from cura (core) for the filenames to use -> same as for dialog of "save as file". is there any other plugin active in your installation of cura which can enforce this behavior?

no matter... i can imagine a feature for regexp-replace in the filename - so you can 'program' and configure the conversion for your self.

itCarl commented 3 years ago

is there any other plugin active in your installation of cura which can enforce this behavior?

currently i dont have any plug-ins except "yours" (Cura2MoonrakerPlugin)

But Fenne from Ultimaker/Cura#9431 linked me a Plug-in that exactly does what this issue here is about. in general, i don't like plug ins, i prefer fixed features because then less can go wrong more often

emtrax-ltd commented 3 years ago

in the upload-dialog there is only one limitation for filenames -> maximumLength: 100;

if you need more, just post it.

itCarl commented 3 years ago

i just played around with the Plug-in and stuff and just found something interesting...

it takes the suggestion from cura (core) for the filenames to use -> same as for dialog of "save as file".

when i save the .gcode "as a File" it outputs exactly the right filename as you can the on the first picture. but when i use "upload to %Printername%" it "cuts" everything after the first dot and or whitespace in the Filename String.


Save to File sdfsdfsdf


Upload to Moonraker adasdasdasd


asdasdasdasdds


ps: yes, i know a colon is a invalid character for windows. But it's still slighty annoying that the "Cura2Moonraker" Plug-in cuts the Filename String after a dot and or whitespace instead of replacing it.


again i dont know Python that well but i feel like a fix for my issue is located somewhere in these next couple of lines

https://github.com/emtrax-ltd/Cura2MoonrakerPlugin/blob/97043a926376cabc6882f93832f9e6bc52678b25/MoonrakerPlugin/MoonrakerOutputDevice.py#L92-L123

emtrax-ltd commented 3 years ago

I will check that

itCarl commented 3 years ago

I'm trying to figure out were exactly the 'error' here is what i found so far.


if I am not mistaken it's doing the "os.path.splitext(file)" correctly.. (line 94) ...thats weird but its displaying it wrong in the dialog box...

file_ext

https://github.com/emtrax-ltd/Cura2MoonrakerPlugin/blob/97043a926376cabc6882f93832f9e6bc52678b25/MoonrakerPlugin/MoonrakerOutputDevice.py#L92-L107


Just some quick and dirty Debuging LogOutput python


"Bug explained: " it seems that the given fileName method (=requestWrite(self, node, fileName = None, *args, kwargs) line 71 )parameter gets a String with no extension and path just the Filename (line 92) - obviously - so the os.path.splitext() Method cuts the fileName** String at a dot because it "thinks" that every think after the dot is the file extension.

possible Fix: emtrax-ltd/Cura2MoonrakerPlugin/pull/3

emtrax-ltd commented 3 years ago

thank you for your detailed investigation. i have taken it into account and developed it a little bit more complex but much more flexible. take a look at the new version in the repository.

       if fileName:
            fileName = os.path.basename(fileName);
        else:
            fileName = "%s." % Application.getInstance().getPrintInformation().jobName

        # Translate filename
        if self._trans_input and self._trans_output:
            transFileName = fileName.translate(fileName.maketrans(self._trans_input, self._trans_output, self._trans_remove if self._trans_remove else ""))
            fileName = transFileName

        self._fileName = fileName  + "." + self._output_format

your requirements should be satisfied by the following settings... now available within the configuration wizzard image

itCarl commented 3 years ago

That's cool. Thanks a lot.