RoboDK Forum
MakeProgram - how to change the name & extension of the output file?- Printable Version

+- RoboDK Forum (//m.sinclairbody.com/forum)
+-- Forum: RoboDK (EN) (//m.sinclairbody.com/forum/Forum-RoboDK-EN)
+--- Forum: RoboDK API (//m.sinclairbody.com/forum/Forum-RoboDK-API)
+--- Thread: MakeProgram - how to change the name & extension of the output file? (/Thread-MakeProgram-how-to-change-the-name-extension-of-the-output-file)



MakeProgram - how to change the name & extension of the output file?-Maarten-07-08-2021

I'm generating robot program files via the RoboDK API using "MakeProgram". How do I change the name and the extension of the output file?

The code I use below outputs the program 'myProgram' as the file 'myProgram.py'. I would like to change the filename to e.g. 'myProgram_1.py' or 'myProgram_2.txt', without changing the name of the program itself:

Code:
from robolink import * # RoboDK API
from robodk import * # Robot toolbox
RDK = Robolink()

myProgramItem = RDK.Item('myProgram',ITEM_TYPE_PROGRAM) # Get the program item named 'myProgram'
myProgramItem.MakeProgram('',RUNMODE_MAKE_ROBOTPROG) # Export 'myProgram' to file.



RE: MakeProgram - how to change the name & extension of the output file?-Jeremy-07-08-2021

I think you could do something like that before generating the program to change the name:

Code:
myProgramItem.setName('NewName')

But for the extension, it's coded in the post-processor.
So either you modify the post or you add a python command to your macro to get the file generated and change the extension. 100% sure it can be done.


RE: MakeProgram - how to change the name & extension of the output file?-Maarten-07-09-2021

谢谢,这很管用!重命名程序,export file, then rename program back to its original name.

Maarten