Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Have an idea and zero programming knowledge...

DirtSimpleCNC

New Coder
Howdy all, have a question.

At my job we deal with CNC programs regularly. Per our procedures the files are given a certain name on the computer, say "Part #, Revision #, Operation #" like "1234Rev1Op10". The issue is the first line of the program would have the program number and op number followed by the file name such as:
O23410 (1234Rev1Op10);
Rest of;
The code;

The problem arises when we try to then save the program BACK from the machine as it changes the file name to the program name of O23410.nc
Instead of the actual file name. This results in me having to open every file, find the name and rename them EVERYTIME WE SAVE A PROGRAM FROM THE MACHINE!

I have zero programming knowledge and have struggled to find an answer but id like to find what language would let me build something to automatically open a file, find the information in-between the first set of parentheses found, and rename the file with that info.

I'm not asking for the answer per se, as I see a great oppurtunity to learn something new! I just have zero clue where to start....
 
Not sure if I understand correctly, but is O23410 the name of "the program", whatever that is ? And does the program read a file correctly, but then save it back with the name of the program instead of the original file name ? If so, is the program perhaps written in C and did the programmer not know that the first argument in the program is always the name of the program itself ? Just guessing, as the description is not very clear....
 
Not sure if I understand correctly, but is O23410 the name of "the program", whatever that is ? And does the program read a file correctly, but then save it back with the name of the program instead of the original file name ? If so, is the program perhaps written in C and did the programmer not know that the first argument in the program is always the name of the program itself ? Just guessing, as the description is not very clear....
Its not code in the sense of computer programming. Its called G-Code. We can write it in notepad and transfer it to the machine. The machine reads it and changes it to a .nc file. The machine reads the program number "O12310" in this case and when transferring the file out of the machine names the file O12410. Ill try to give an example...
Write the program on the computer:
File Name: Code.txt

Program:
%
O12310 (12345Rev1Op10)
Etc.
End of code
%
Load it into the machine and the control reads everything between the %'s and sees the program number is O12310.

When you transfer the file back out of the machine instead of being the original Code.txt name and file format it will now be O12310.nc.

Then I have to open the file, copy the first comment, the info between () and paste it as the file name so it matches our procedures.
 
But why does the machine (whatever that is) use the program number instead of the file name ? Does it even read the filename from the first line ? And where does it get the .nc suffix from ?
But now I re-read your question I see you just want to add a post-processing step that does what you now need to to manually. Any programming language will let you do that. What is your environment and what tools have you got available ?
 
But why does the machine (whatever that is) use the program number instead of the file name ? Does it even read the filename from the first line ? And where does it get the .nc suffix from ?
But now I re-read your question I see you just want to add a post-processing step that does what you now need to to manually. Any programming language will let you do that. What is your environment and what tools have you got available ?
Environment? Windows 10?
Tools? Nada.
I am not what I would call computer savvy. Ive seen code before and have talked with friends back in college about it and understand the core ideas but have no clue past an understanding it exists.
 
On Windows, you can use the simplest and readily available tool, the command interpreter. Paste the following code into a batch file called fixname.bat :

Code:
@echo off
rem Pick up wrong file name from command line argument
set wrongname=%1%
rem Read the token between () from the second line of the file
for /f "skip=1 tokens=2 delims=()" %%s in (%wrongname%) do (
    rem Construct the correct name
    set rightname=%%s.txt
    rem Break the loop
    goto :stop
)
:stop
rem Rename the file !
rename %wrongname% %rightname%

(Do not call it rename.bat as it might clash with the Windows rename comnmand)

Then in a command window run this batch file with the wrong filename as commandline argument :

fixname o12310.nc

This will do exactly what you've been doing by hand until now. Ideally you can run this batch file somewhere in your chain of commands instead of by hand.
Of course, if the wrong filename is always the same, you can hardcode it in line 3 of the batch file, instead of having to pass it as a parameter.
 

Buy us a coffee!

Back
Top Bottom