Is there any way to rename the name of a module on execution?
Not the name that is used to store the .MOD file, but the actual module name that the rapid program uses!
Is there any way to rename the name of a module on execution?
Not the name that is used to store the .MOD file, but the actual module name that the rapid program uses!
The first line of the module file holds the module line (both when you open the .mod file in your editor of choice or in RobotStudio)
Just change this line after the MODULE command. Example:
MODULE MainModule
PROC main()
!some action
ENDPROC
ENDMODULE
change to:
MODULE OtherModuleName
PROC main()
!some action
ENDPROC
ENDMODULE
The name in the first line and the file name is not the same! RS just uses the same name.
But what I want to do, is to create a copy of a module and load it in to the memory(together with the old module). but it needs to be with rapid code. So manually changing the name will not do!
The filename doesn’t matter in execution time, only the name inside the file behind the ‘MODULE’ keyword.
I guess you could use file operations to open the file (as text), change the first line and then save it, but I don’t think that would be a very nice solution. Also all routines and/or variables stored in the module will be defined already in your system which could easily give you loads of errors. Can’t you unload the old module before loading the new one?
I know that the filename doesn’t matter, my problem is that it is the one that I know how to changes. I don’t know how to change the module name.
How do I open the file, and change the first line? (still in RAPID code)
If I define my routines and variables locally, it is no problem.
I could unload the module, but the essence is that I would like to avoid that!
I guess you could open your saved .mod file in reading mode. And write all the lines to a new (temporary?) .mod file, while changing the first line. Something in the line of (not tested and my boss would kill me for using bad names and lack of documentation):
PROC loadModule()
var iodev modulefile;
var iodev tempfile;
var string line;
Open “HOME:/yourmodule.mod”, modulefile\READ;
Open “HOME:/tempmodule.mod”, tempfile\WRITE;
line := ReadStr(modulefile); !first line is ignored, as we are writing our own MODULE line
Write tempfile, “MODULE YourNewModuleName”; !our own MODULE line is written to the temporary file
WHILE line <> EOF DO !loop while we haven’t copied everything of our old module to the temporary file;
line:=ReadStr(modulefile);
Write tempfile, line;
ENDWHILE;
Close modulefile;
Close tempfile;
Load \Dynamic, diskhome, \File:=“tempmodule.mod”
ENDPROC
This is a very simple implementation which assumes that the “MODULE YourModuleName” is the first line. It breaks quite easily, so you might want to build in some checks to prevent writing and loading corrupt module files.
That is more or less what I needed. not a pretty solution to copy every single line, but with a little modification it worked.