586,832 active members*
3,015 visitors online*
Register for free
Login
Page 1 of 2 12
Results 1 to 20 of 25
  1. #1
    Join Date
    Apr 2007
    Posts
    21

    Changing each number seperately...

    Hey everyone...I have a post processor from ages ago for our CNC, and sometimes it likes to give me code like:

    X12.5367 Y-6.1065 Z0.2045 C355.
    X12.5381 Y-6.0863 C355.833
    X12.5394 Y-6.066 C356.666
    X12.5396 Y-6.0457 C357.5
    Y-6.0253 Z0.2057 C358.334
    Y-6.005 C359.167

    The problem with it is that the CNC's C axis doesn't go nearly that far. It has so very many numbers and it's SUCH a huge waste of time to go through each one with a calculator (like I've been doing :S) and I was wondering if anyone knows of a program that can pick out the letter and the number following and subtract lets say 180 from it? So if I were to run this program it would make the previous code look like:

    X12.5367 Y-6.1065 Z0.2045 C175.
    X12.5381 Y-6.0863 C175.833
    X12.5394 Y-6.066 C176.666
    X12.5396 Y-6.0457 C177.5
    Y-6.0253 Z0.2057 C178.334
    Y-6.005 C179.167

    I know there has got to be something like that out there. I mean Notepad has a replace option right? Lol any help would be greatly appreciated

  2. #2
    Join Date
    Mar 2003
    Posts
    2932
    What CAM system are you running? Does it have an editor?
    I know that Predator Editor will do math operations (included with SmartCAM and others, or buy from Predator Software), Discriminator will do math operations (shareware ~ $35). There's others I'm sure.

  3. #3
    Join Date
    Apr 2007
    Posts
    21
    I'm running SURFCAM Velocity 3.0...but only for one CNC. It does have an editor although I'm not sure how to use it quite yet. I'm getting sent away for training soon but if you could help me out with it sooner that would be awesome. I was mainly looking for a program to change a text file just so it'd work for both our old and newer CNC. I will check out that software you recommended and get back to you

    Thanks

  4. #4
    Join Date
    Jul 2003
    Posts
    1220
    AcryNom
    Here is a Word Macro. Paste your code into MS Word and run this macro.
    You will need to enter the number of lines in the 4th Line.
    I'm sure someone can improve on this, I'm just a self taught hacker.

    Sub Macro1()
    'Converts C Rotation to less than 180 deg.
    ActiveDocument.Characters.First.Select
    For Line = 1 To 6 'ENTER NUMBER of LINES <<<<<<<<<<<<<<<<<<
    Flag1 = 0
    For charCount = 0 To 60
    Selection.Characters(1).Select
    MyChar = Selection.Characters(1)
    If Flag1 = 0 Then Mystr = Mystr & MyChar
    If Flag1 = 1 Then CVstr = CVstr & MyChar
    Counter = charCount
    AA = Asc(MyChar)
    If Flag1 = 1 And MyChar = " " Then Flag1 = 0: charCount = 60
    If MyChar = "C" Then Flag1 = 1

    Selection.Characters(1) = MyChar
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Next charCount
    CVstrLen = Len(CVstr)
    MystrLen = Len(Mystr)
    If Val(CVstr) > 180 Then CV = (Val(CVstr) - 180)
    CVstr = CV
    If Int(CV) = CV Then CVstr = CV & Chr(46): MystrLen = MystrLen - 1

    Selection.MoveLeft Unit:=wdCharacter, Count:=2

    For BS = 1 To CVstrLen - 2
    Selection.TypeBackspace
    Next BS

    Selection.Characters(1) = CVstr
    Selection.MoveLeft Unit:=wdCharacter, Count:=MystrLen
    Selection.MoveDown Unit:=wdLine, Count:=1

    charCount = 0: Counter = 0 'Reset counter
    Mystr = "": CVstr = ""
    Next Line
    End Sub

  5. #5
    Join Date
    Apr 2007
    Posts
    21
    Hey Kiwi

    Thanks for the code...I can see where you're going with it...I just have no idea how to run a macro in Word. I tried recording it by copy and pasting your code while Word was recording, stopped it, and tried running it but it just copied the code and that's it.

    What do you mean on the 4th line..where it says
    For Line = 1 To 6 'ENTER NUMBER of LINES
    What is the 1 to 6 for? Could I input "For Line = 5 To 300"?

    It would probably be easier for you to give me an example and then I compare the 2 sets of code...lets say I wanted to subtract 180 from each C movement from the following part of a program..how would you set it up and run the macro?

    X-4.8333 Y-25.7433 C153.
    X-4.7122 Y-25.6086 C153.899
    X-4.5911 Y-25.4739 C154.8
    X-4.47 Y-25.3392 C155.7
    X-4.3489 Y-25.2045 C156.601
    X-4.2278 Y-25.0698 C157.5
    X-4.1118 Y-24.9292 C158.4
    X-3.9958 Y-24.7886 C159.3
    X-3.8798 Y-24.648 Z-2.9145 C160.2
    X-3.7638 Y-24.5075 C161.101
    X-3.6477 Y-24.3669 C162.
    X-3.5371 Y-24.2205 C162.899
    X-3.4265 Y-24.0741 C163.8
    X-3.3158 Y-23.9276 C164.7
    X-3.2052 Y-23.7812 C165.601
    X-3.0945 Y-23.6348 C166.5
    X-2.9895 Y-23.4827 C167.4
    X-2.8845 Y-23.3305 C168.3
    X-2.7795 Y-23.1783 C169.2
    X-2.6745 Y-23.0261 C170.101
    X-2.5695 Y-22.874 C171.
    X-2.4704 Y-22.7161 C171.9
    X-2.3714 Y-22.5582 C172.8
    X-2.2723 Y-22.4004 Z-2.9135 C173.7
    X-2.1732 Y-22.2425 C174.601
    X-2.0741 Y-22.0846 C175.5
    X-1.9813 Y-21.9212 C176.4
    X-1.8885 Y-21.7577 C177.3
    X-1.7957 Y-21.5943 C178.2
    X-1.7028 Y-21.4308 C179.1
    X-1.61 Y-21.2674 C180.

    If this works you would save me hours of stress lol

    Thanks again

  6. #6
    Join Date
    Jul 2003
    Posts
    1220
    Hey AcryNom
    To get the Macro into Word
    Open Word:Tools/Macro/Record new Macro/OK
    Hit a couple of keys. Stop recording.

    Tools/Macro/Macros/Edit
    Now paste the Code over all this text from Sub to End Sub.
    Close the VB Screen.

    To Run: Macro/Macros/Select macro & Run.

    >What is the 1 to 6 for? Could I input "For Line = 5 To 300"?<
    Yes... this is the lines to be altered.

    I have modified the Macro
    Check your code at start and END to be sure all correct.
    If the line number is greater than your code, I notice some garbage appears on the page well below the last line.
    You will need to DELETE this. Not sure why this happens.

    NEW VERSION.
    '====================================
    Sub Macro1()
    'Deducts 180 deg from C Rotation.
    ActiveDocument.Characters.First.Select
    For Line = 1 To 35
    Flag1 = 0
    For charCount = 0 To 60
    Selection.Characters(1).Select
    MyChar = Selection.Characters(1)
    If Flag1 = 0 Then Mystr = Mystr & MyChar
    If Flag1 = 1 Then CVstr = CVstr & MyChar
    Counter = charCount
    AA = Asc(MyChar)
    If Flag1 = 1 And MyChar = " " Then Flag1 = 0: charCount = 60
    If MyChar = "C" Then Flag1 = 1

    Selection.Characters(1) = MyChar
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Next charCount
    CVstrLen = Len(CVstr)
    MystrLen = Len(Mystr)
    CV = (Val(CVstr) - 180) ' 180 is deg to deduct.
    CV = Int(CV * 1000 + 0.5) / 1000
    CVstr = CV
    If Int(CV) = CV Then CVstr = CV & Chr(46): MystrLen = MystrLen - 1

    Selection.MoveLeft Unit:=wdCharacter, Count:=2

    For BS = 1 To CVstrLen - 2
    Selection.TypeBackspace
    Next BS

    Selection.Characters(1) = CVstr
    Selection.MoveLeft Unit:=wdCharacter, Count:=MystrLen
    Selection.MoveDown Unit:=wdLine, Count:=1

    charCount = 0: Counter = 0 'Reset counter
    Mystr = "": CVstr = ""
    Next Line
    End Sub
    '====================================
    RESULTS:
    X-4.8333 Y-25.7433 C-27.
    X-4.7122 Y-25.6086 C-26.101
    X-4.5911 Y-25.4739 C-25.2
    X-4.47 Y-25.3392 C-24.3
    X-4.3489 Y-25.2045 C-23.399
    X-4.2278 Y-25.0698 C-22.5
    X-4.1118 Y-24.9292 C-21.6
    X-3.9958 Y-24.7886 C-20.7
    X-3.8798 Y-24.648 Z-2.9145 C-19.8
    X-3.7638 Y-24.5075 C-18.899
    X-3.6477 Y-24.3669 C-18.
    X-3.5371 Y-24.2205 C-17.101
    X-3.4265 Y-24.0741 C-16.2
    X-3.3158 Y-23.9276 C-15.3
    X-3.2052 Y-23.7812 C-14.399
    X-3.0945 Y-23.6348 C-13.5
    X-2.9895 Y-23.4827 C-12.6
    X-2.8845 Y-23.3305 C-11.7
    X-2.7795 Y-23.1783 C-10.8
    X-2.6745 Y-23.0261 C-9.899
    X-2.5695 Y-22.874 C-9.
    X-2.4704 Y-22.7161 C-8.1
    X-2.3714 Y-22.5582 C-7.2
    X-2.2723 Y-22.4004 Z-2.9135 C-6.3
    X-2.1732 Y-22.2425 C-5.399
    X-2.0741 Y-22.0846 C-4.5
    X-1.9813 Y-21.9212 C-3.6
    X-1.8885 Y-21.7577 C-2.7
    X-1.7957 Y-21.5943 C-1.8
    X-1.7028 Y-21.4308 C-0.9
    X-1.61 Y-21.2674 C0.

  7. #7
    Join Date
    Jul 2003
    Posts
    1220
    AcryNom
    After doing some checking, I've found the line count always starts from the 1st line, regardless of what is entered. eg: For Line = 5 To 300
    Not line 5 as I advised. I guess 5 to 300 will only give a count of 295.
    Sorry to put you wrong.

  8. #8
    Join Date
    Dec 2007
    Posts
    5
    Hi AcryNom,

    You can use a small awk script for this task.
    * Download mawk32.zip from
    http://www.klabaster.com/freeware.htm#dl

    * extract mawk.exe into a directory

    * create a script file "prog.awk":

    $NF~/^C/{
    n=substr($NF,2);
    n-=180;
    $NF="C" n;
    }

    { print; }


    * execute "cmd", cd to the directory and run with

    mawk -f prog.awk gcode > new-gcode

    where gcode is the file to be converted, and new-gcode is the resulting file.

  9. #9
    Join Date
    Apr 2007
    Posts
    21
    Hey Kiwi
    No worries at all When I use it I'll probably be taking lines out of the program and pasting them into word so I probably will always start with line 1
    I have a few more questions if you don't mind..I know how to make macros run in Word now which is SO nice. I tried to change the macro myself so that it would edit Z values, instead of C.
    If MyChar = "C" Then Flag1 = 1 <---Old
    If MyChar = "Z" Then Flag1 = 1 <----New
    And I changed the line with the amount to subtract or add from
    CV = (Val(CVstr) - 180) ' 180 is deg to deduct
    to
    CV = (Val(CVstr) + 0.5) ' 0.5 is amount to add

    That's all I changed in the program and when I ran it it did something weird. Can you use decimals? I looked through the program but I can't make heads or tails of alot of it. I took a visual basic course way back in highschool so I can kind of get an idea of what the program is doing but not even close to all of it. Are those the only lines I would have to change? I tried changing that last line to the following too..

    CV = (Val(CVstr) + 1) ' 1 is amount to add

    ..and it works every other time. If Z was 1, running the macro would make it 2. Running it again would make it 4 though. Every other time it adds 1 instead of 2

    Any ideas?

  10. #10
    Join Date
    Jul 2003
    Posts
    1220
    Hi AcryNom
    I have altered program so details are altered at beginning of program.
    Can handle plus/mius values.
    Will only alter last axis in block. Will need modifying to be able to change axis within the block.

    MODIFIED VERSION
    Sub Macro1()
    'Adjusts last AXIS value in each Block

    Axis = "C" 'ONLY last Axis in BLOCK
    NumLines = 14
    Adjust = -0.1

    ActiveDocument.Characters.First.Select
    For Line = 1 To NumLines
    Flag1 = 0: Flag2 = 0
    For charCount = 0 To 60
    Selection.Characters(1).Select

    MyChar = Selection.Characters(1)
    If Flag1 = 0 Then Mystr = Mystr & MyChar
    If Flag1 = 1 Then CVstr = CVstr & MyChar
    AA = Asc(MyChar)
    If Flag1 = 1 And MyChar = Chr(13) Or Flag1 = 1 And MyChar = Chr(11) Then Flag1 = 0: charCount = 60

    If MyChar = Axis Then Flag1 = 1: Flag2 = 1

    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Next charCount
    CVstrLen = Len(CVstr)
    MystrLen = Len(Mystr)
    CV = (Val(CVstr) + Adjust)
    CV = Int(CV * 1000 + 0.5) / 1000
    CVstr = CV
    If Int(CV) = CV Then CVstr = CV & Chr(46): MystrLen = MystrLen - 1

    If Flag2 = 1 Then
    Selection.MoveLeft Unit:=wdCharacter, Count:=2
    For BS = 1 To CVstrLen - 2
    Selection.TypeBackspace
    Next BS
    Selection.Characters(1) = CVstr
    Selection.MoveLeft Unit:=wdCharacter, Count:=MystrLen
    End If

    Selection.MoveDown Unit:=wdLine, Count:=1
    charCount = 0
    Mystr = "": CVstr = ""
    Next Line
    End Sub

  11. #11
    Join Date
    Jul 2003
    Posts
    1220
    Hi AcryNom
    Now to answer your questions.
    Your mods to the program are correct.
    Most of the problems are the backtracking and deleting the correct number of charactors and when the line number isn't correct the curser backtracts into the corrected lines.
    I think I have plugged all the leaks.
    Some tips to help you debug:
    You can highlight any line in the macro (on the VB screen) by clicking in the left column and the program will run to this point and pause. You can then move your curser over the variables and their values will show. You can run the macro from the VB screen by clicking the triangled pointer (just below the word 'Debug').
    Keep clicking the pointer and you will step through the code.

  12. #12
    Join Date
    Jul 2003
    Posts
    1220
    Hi Eauth
    I've never heard of a AWK script. This look most interesting and simpler for manipulating text files like GCode.
    I've download the AWK.exe file and now hope to get to understand how to use it.

  13. #13
    Join Date
    Jul 2003
    Posts
    1220
    Hi Eauth
    I'm having trouble getting started.
    I downloaded mawk32.zip and unzipped to separate folder.
    When I try and open mawk.exe file I get a flash of a DOS screen only.
    Is this DOS screen where I place my awk program?
    Your help will be appreciated.
    Cheers.

  14. #14
    Join Date
    Dec 2007
    Posts
    5
    You have to click Start/Execute. Type "CMD" and you will get a command window. Change to your directory with "cd ...." and execute the commands there. It's easiest if mawk.exe, the script file (e.g. prog.awk) and your g-code files are all in the same directory.

  15. #15
    Join Date
    Jul 2003
    Posts
    1220
    Where is the Start/Execute, is this within Dos or NotePad or the Dos screen that flashes when I open mawk.exe?
    Sorry for being so thick, but I haven't seen the light yet.

  16. #16
    Join Date
    Dec 2007
    Posts
    5
    The Start button is on the left bottom on you desktop (in Windows XP). The entry may be called "Run", not "Execute", sorry. To open Command Prompt, click Start, click Run, type cmd, and then click OK.

  17. #17
    Join Date
    Jul 2003
    Posts
    1220
    I think I have solved my problem. On my PC I can goto Start/Run. Then enter CMD and I get into DOS. Is this where I should be?

  18. #18
    Join Date
    Jul 2003
    Posts
    1220
    Looks like our messages crossed, Thankyou for your help. Cheers

  19. #19
    Join Date
    Jul 2003
    Posts
    1220
    Hi Eauth
    I haven't made a lot of progress. I've tried mawk and gawk versions with the same outcome.
    I'm trying a very simple instruction but must have the format wrong.
    Re the attached pic. Report states invalid character but I am unable to establish what is necessary. Your help will be appreciated.
    Attached Thumbnails Attached Thumbnails gawk test.jpg  

  20. #20
    Join Date
    Dec 2007
    Posts
    5
    it seems that using quotes is a problem with the windows version. You should put your script into a seperate file and execute that with

    Code:
    mawk -f scriptfile
    like described in my first post.

Page 1 of 2 12

Similar Threads

  1. Looking for the the material number details
    By lly1001 in forum Bending, Forging, Extrusion...
    Replies: 1
    Last Post: 06-28-2008, 09:26 AM
  2. Number Counter
    By CI_182 in forum G-Code Programing
    Replies: 3
    Last Post: 09-01-2007, 09:41 PM
  3. Dx-32 auto N number for you
    By jtree83 in forum Bridgeport / Hardinge Mills
    Replies: 4
    Last Post: 09-26-2005, 07:28 PM
  4. (Brackets) after Program Number (O)
    By alanblackwell in forum G-Code Programing
    Replies: 9
    Last Post: 08-09-2005, 11:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •