585,931 active members*
3,627 visitors online*
Register for free
Login
IndustryArena Forum > Machine Controllers Software and Solutions > G-Code Programing > Any Way to Improve Processing G Code with Excel?
Page 1 of 2 12
Results 1 to 20 of 35
  1. #1
    Join Date
    Mar 2003
    Posts
    332

    Any Way to Improve Processing G Code with Excel?

    I have a need to convert text to code. I can do it with Excel, but I can only do one line at at time.
    I am using a kinematics program to produce six axis joint angles for a robot arm. The information represents a point to point move and is usually around 50 lines of text as follows:

    0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
    -0.000000 7.819982 14.789516 0.000002 6.969540 0.000003
    0.000000 16.114470 30.837702 -0.000001 14.723211 -0.000001
    0.000000 23.386688 45.481628 -0.000000 22.094950 -0.000000
    -0.000000 29.612301 59.122925 0.000000 29.510695 -0.000001
    -0.000000 33.830772 70.922791 0.000001 37.153328 -0.000000
    -0.000000 33.830772 70.999458 0.000001 37.168625 -0.000000

    I can copy and paste one line at a time into excel, then copy and paste the result into another text file for use as g code. I am using Excel to round down to four places, add the axis letter and recalculate axis z,b,c:

    X 0.0000 Y 7.8200 Z 22.6095 A 0.0000 B 6.9695 C 0.1882
    X 0.0000 Y 16.1145 Z 46.9522 A 0.0000 B 14.7232 C 0.3975
    X 0.0000 Y 23.3867 Z 68.8683 A 0.0000 B 22.0950 C 0.5966
    X 0.0000 Y 29.6123 Z 88.7352 A 0.0000 B 29.5107 C 0.7968
    X 0.0000 Y 33.8308 Z 104.7536 A 0.0000 B 37.1533 C 1.0031
    X 0.0000 Y 33.8308 Z 104.8303 A 0.0000 B 37.1686 C 1.0036

    Very slow moving one line at a time. I don't know what terms to google. I would like a more automated method of converting blocks of space delimited text.

    Any clues?
    Thanks

  2. #2
    Join Date
    Nov 2004
    Posts
    446
    Not sure what your trying to do but Microsoft Access is very good at manipulating data.

    Murph

  3. #3
    Join Date
    Jul 2003
    Posts
    1220
    If you can copy the whole file, paste into notepad or wordpad. Then import into excel as a delimiter, space, which will put the coords into separate cells.

    Kiwi

  4. #4
    Join Date
    Mar 2003
    Posts
    4826
    Keith,
    You need the services of someone who can write a visual basic script for you. If the programs are always short like you said, visual basic will likely run fast enough to do the job.

    Are the equations you use always exactly the same format, or is there variation required for that aspect?
    First you get good, then you get fast. Then grouchiness sets in.

    (Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)

  5. #5
    Join Date
    Mar 2003
    Posts
    332

    Online Scripting Utilities

    Thanks for the reply.
    I did find scripting utilities online based on both VB and C++. I tried a demo version of one this afternoon and it looks like it will do the job.

  6. #6
    Join Date
    Jul 2003
    Posts
    1220
    keithorr

    If you paste all text data into MSWord this Macro will convert to NC.
    (If unsure how to run please advise.)

    The "C" NC needs adjusted as I'm not sure how you value is calculated.
    If you let me know I will alter as required.

    Kiwi

    Converted From
    -0.000000 7.819982 14.789516 0.000002 6.969540 0.000003
    0.000000 16.114470 30.837702 -0.000001 14.723211 -0.000001
    0.000000 23.386688 45.481628 -0.000000 22.094950 -0.000000
    -0.000000 29.612301 59.122925 0.000000 29.510695 -0.000001
    -0.000000 33.830772 70.922791 0.000001 37.153328 -0.000000
    -0.000000 33.830772 70.999458 0.000001 37.168625 -0.000000

    To this with Macro
    X0.0000 Y7.8200 Z22.6095 A0.0000 B6.9695 C0.0000
    X0.0000 Y16.1145 Z46.9522 A0.0000 B14.7232 C0.0000
    X0.0000 Y23.3867 Z68.8683 A0.0000 B22.0950 C0.0000
    X0.0000 Y29.6123 Z88.7352 A0.0000 B29.5107 C0.0000
    X0.0000 Y33.8308 Z104.7536 A0.0000 B37.1533 C0.0000
    X0.0000 Y33.8308 Z104.8302 A0.0000 B37.1686 C0.0000

    ================================================== =====
    Sub Data2GCode()
    '
    ' Macro recorded 16/8/2005 by Kiwi

    numLines = 6 'Number of Lines
    EOLine = 80

    ActiveDocument.Characters.First.Select

    For Line = 1 To numLines

    XFlag = 1

    For charCount = 1 To EOLine
    Selection.Characters(1).Select
    MyChar = Selection.Characters(1)

    If Asc(MyChar) = 13 Then
    LineCount = charCount
    charCount = EOLine 'End of Line
    End If

    If CFlag = 1 Then strC = strC & MyChar
    If CFlag = 1 And MyChar = " " Then CFlag = 0

    If BFlag = 1 Then strB = strB & MyChar
    If BFlag = 1 And MyChar = " " Then BFlag = 0: CFlag = 1

    If AFlag = 1 Then strA = strA & MyChar
    If AFlag = 1 And MyChar = " " Then AFlag = 0: BFlag = 1

    If ZFlag = 1 Then strZ = strZ & MyChar
    If ZFlag = 1 And MyChar = " " Then ZFlag = 0: AFlag = 1

    If YFlag = 1 Then strY = strY & MyChar
    If YFlag = 1 And MyChar = " " Then YFlag = 0: ZFlag = 1

    If XFlag = 1 Then strX = strX & MyChar
    If XFlag = 1 And MyChar = " " Then XFlag = 0: YFlag = 1

    If Asc(MyChar) = 13 Then

    X = Int(Val(Trim(strX)) * 10000 + 0.5) / 10000
    Y = Int(Val(Trim(strY)) * 10000 + 0.5) / 10000
    Z = Val(Trim(strY)) + Val(Trim(strZ))
    Z = Int(Z * 10000 + 0.5) / 10000
    A = Int(Val(Trim(strA)) * 10000 + 0.5) / 10000
    B = Int(Val(Trim(strB)) * 10000 + 0.5) / 10000
    C = Int(Val(Trim(strC)) * 10000 + 0.5) / 10000

    strData = "X" & Format(X, "####0.0000") & " Y" & Format(Y, "####0.0000") & " Z" & Format(Z, "####0.0000") & " A" & Format(A, "####0.0000") & " B" & Format(B, "####0.0000") & " C" & Format(C, "####0.0000") & Chr(10) & Chr(13)

    For BS = 1 To LineCount
    Selection.TypeBackspace
    Next BS

    Selection.Font.Color = wdColorBlue
    Selection.TypeText Text:=strData
    Selection.TypeBackspace
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    strData = ""
    X = 1: Y = 0: Z = 0: A = 0: B = 0: C = 0
    strX = "": strY = "": strZ = "": strA = "": strB = "": strC = ""
    XFlag = 1
    charCount = EOLine 'End of Line
    End If 'If Asc(MyChar) = 13 Then

    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Next charCount

    Next Line

    End Sub
    ====================================

  7. #7
    Join Date
    Mar 2003
    Posts
    35538
    Quote Originally Posted by keithorr
    Thanks for the reply.
    I did find scripting utilities online based on both VB and C++. I tried a demo version of one this afternoon and it looks like it will do the job.
    Use VBA, it's built into Excel. You can also record what you do as a macro, and play it again, which might work for you.
    Gerry

    UCCNC 2017 Screenset
    http://www.thecncwoodworker.com/2017.html

    Mach3 2010 Screenset
    http://www.thecncwoodworker.com/2010.html

    JointCAM - CNC Dovetails & Box Joints
    http://www.g-forcecnc.com/jointcam.html

    (Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)

  8. #8
    Join Date
    Mar 2003
    Posts
    332
    Ger21,
    WTF???
    Do I have a lot to learn!

    How you do that? I can start to understand what you have done, but not knowing the specific syntax for math operations, I can't modify what you've done to rejigger the C axis. I'll be search the net just as soon.

    Very much appreciated. I was just going to use a macro recorder to duplicate my keyboard strokes-ha!

    This looks like the way I need to adjust my thinking cap. Of course I don't know any of the syntax so I'll need to start reading.

    The formula is:

    X=x, Y=y, Z=y+z, A=a, B=b+(a*.0144), C=c+(a*.02299)+(b*.02299)

    In Excel, 15.6183 16.11447 30.837702 3.429 14.723211 26.7743

    is converted to:X 15.6183 Y 15.6183 Z 46.9522 A 3.4290 B 14.7575 C 27.1916


    I think an improvement for later might be to learn how to enter this in CamSoft G Code directly, which might be an incremental step to learning how to embed the kinematics completely into CamSoft and use XYZ fixed and euler angles for input.

    Thanks for the reply.

  9. #9
    Join Date
    Apr 2005
    Posts
    421
    linux shell, put it in a file named cnv.sh and run as ./cnv.sh <input_file_name> <output_file_name>
    Code:
    #!/bin/sh
    cat $1 | while read line
    do
        F1=`echo $line | cut -f1 -d" "`
        F2=`echo $line | cut -f2 -d" "`
        F3=`echo $line | cut -f3 -d" "`
        F4=`echo $line | cut -f4 -d" "`
        F5=`echo $line | cut -f5 -d" "`
        F6=`echo $line | cut -f6 -d" "`
        echo "X $F1 Y $F2 Z $F3 A $F4 B $F5 C $F6" >> $2
    done
    That is what Unix was written for originally, text proccessing.

    Edit:
    For you windows boys, you can get Cygwin to do the work for you.

  10. #10
    Join Date
    Mar 2004
    Posts
    1542
    Do you have a level of Camsoft where you define your own Gcodes? If so, this looks like a piece of cake to just write a custom Gcode and be done with it. Come up with a G# and six parameter letters you aren't using and Gcode lines like so:

    G123 M15.6183 N16.11447 O30.837702 P3.429 Q14.723211 R26.7743

    In G123, do your math:
    \999=m
    \998=n
    \997= {m+n}

    and so on.

    Then put your motion move in the Gcode after you've calculated everything.

    Karl

  11. #11
    Join Date
    Mar 2004
    Posts
    1306
    If you can open that text file in excel with the delimiter set to space, then all you will need to do is insert extra columns, type the Axis letters and formulars in the top line, and then drag fill the lines down.
    Regards,
    Mark

  12. #12
    Join Date
    Mar 2003
    Posts
    332

    Too much information, or not enough

    Well,

    I couldn't get the VB example to replicate the results listed in the earlier post.

    I do have a macro that works, not as elegant as the idea of the vb macro but...

    Thanks for all the suggestions.

  13. #13
    Join Date
    Mar 2003
    Posts
    4826
    Keith,
    I think you're still going to have to find a way to make your kinematics program output more than just numbers, you need a letter "address" to identify the different numbers even in Camsoft.
    First you get good, then you get fast. Then grouchiness sets in.

    (Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)

  14. #14
    Join Date
    Mar 2003
    Posts
    332
    Quote Originally Posted by HuFlungDung
    Keith,
    I think you're still going to have to find a way to make your kinematics program output more than just numbers, you need a letter "address" to identify the different numbers even in Camsoft.
    I was just flashing on that fact. I still need to use excel to add the letter formats for now.
    I was told I could use space delimited code as long as the format is always the same, i.e., I can't list just 5 axis values, I would need to include zeros for the axis that wasn't being moved.

    That being said, "I" can't do it as my brain now stands, but CamSoft said they could do the setup for me.

    But that's for next week. I can live with using Excel to filter the raw numbers. I will also try Marks suggestion of draging the cells to update the numbers. Not as much fun and sometimes inaccurate when using a touchpad.

    So many ways to think about it.

  15. #15
    Join Date
    Mar 2004
    Posts
    1542
    If you want to go the Camsoft route, why don't you start a new thread in the Camsoft forum. Tell us exactly what motion you want to make with what input data you have. And find enough unused parameter letters for the project. Give an example so we understand completely.

    I'll make a stab at a custom Gcode for you. Someone else will correct my errors. There's some real smart folks there.

    Karl

  16. #16
    Join Date
    Jul 2003
    Posts
    1220
    keithorr

    I'm not familiar with Camsoft so unable to help with any direct solution.
    Using this Macro is workable if you can get the text in bulk into MSWord.


    The lines to alter the MSWord Macro for the B and C values listed below:
    ----------------
    B = Val(Trim(strB)) + (Val(Trim(strA)) * 0.0144)
    B = Int(B * 10000 + 0.5) / 10000

    C = Val(Trim(strC)) + (Val(Trim(strA)) * 0.02299) + (Val(Trim(strB)) * 0.02299)
    C = Int(C * 10000 + 0.5) / 10000
    ----------------------------------

    Also one extra line to be added "If CFlag = 1 And Asc(MyChar) = 13 Then CFlag = 0" in position as shown below.
    -------------------
    If CFlag = 1 Then strC = strC & MyChar
    If CFlag = 1 And MyChar = " " Then CFlag = 0
    If CFlag = 1 And Asc(MyChar) = 13 Then CFlag = 0
    ----------------------

    I'm having trouble with your MFactors to get the same as your figures.
    To calculate C is the 0.02299 the same for a and b.
    Also are your A, a and B, b as per the formula. (just a thought)

    Running the Macro From
    -0.000000 7.819982 14.789516 0.000002 6.969540 0.000003
    15.6183 16.11447 30.837702 3.429 14.723211 26.7743

    After the Macro.
    X0.0000 Y7.8200 Z22.6095 A0.0000 B6.9695 C0.1602
    X15.6183 Y16.1145 Z46.9522 A3.4290 B14.7726 C27.1916

  17. #17
    Join Date
    Mar 2003
    Posts
    332
    I'll give the VB macro another shot.

    As for CamSoft Lite,

    !ACCEL 1000
    !DECEL 1000
    !DECELSTOP
    !z={y+z}
    !b=b+{a*.0144}
    !c=c+{a*.02299}+{b*.02299}
    -----G12

    works just fine. X,Y, and A axis don't need to be updated so there's no point entering !x=x. Course I still have to deal with the axis identifiers as Murray pointed out.

    Feedrate can be entered longhand at the beginning of each move.

    Tap on the keyboard long enough somethings bound to happen. I wasn't able to get it to work before because I was mixing up upper and lower case. I was also having bracket trouble.

  18. #18
    Join Date
    Mar 2004
    Posts
    1542
    Now you taught me something. I'd always thought you couldn't change parameter values and I used variables,\### . Your way is much cleaner and neater.

    Thanks for the tip.

    Karl

  19. #19
    Join Date
    Mar 2004
    Posts
    1542
    Say, I've got CNC Pro. There's a command that would just read your line of data as is. Then you could parse it into the different parameters with the midstring command. Does Lite have these commands?

    Karl

    FILEREAD
    This will read one line up to the next carriage return from the file name that was opened with FILEOPEN. The data will be stored into the specified variable. There is an optional second parameter to jump directly to the Nth line number in the file. NOTE: If you jump to the Nth line and do not specify a jump to line number as the second parameter, the next time you use the FILEREAD command it will read the next line automatically. See related commands FILEOPEN, FILECLOSE and FILEWRITE.
    EXAMPLE: FILEREAD \55;10


    MIDSTR
    The MIDSTR function extracts a specified number of characters from a specified position within a string and stores the splice of the string into a variable. If the number of characters to read is greater than the remainder of the string, then it will store all the characters from the start position over to the end. If the start position is greater than the length of the string, then MIDSTR will return an empty null string. The first parameter is the string from which the characters are to be taken. The second parameter is the start position within the string. The third parameter is the number of characters to retrieve starting from the start position. All the strings can be a literal set of characters. The last parameter must be a variable in which to store the splice. The example below will store the characters TRA into variable \55.
    EXAMPLE: MIDSTR AUSTRALIA;4,3;\55

  20. #20
    Join Date
    Mar 2003
    Posts
    332
    Lower case x,y,z,a,b,c, are variables for upper case X,Y,Z,A,B,C so I guess there isn't any need to change the variable x (for X0) to \something else.
    I just wasn't sure about referring a value back to itself, but it seems to work.

    CNCLite has the commands. I can also look through the galil native commands to see if there is something.

Page 1 of 2 12

Similar Threads

  1. parametric programming
    By Karl_T in forum CamSoft Products
    Replies: 21
    Last Post: 05-24-2005, 08:58 PM
  2. Link a Mastercam File to Excel
    By stampman in forum Mastercam
    Replies: 3
    Last Post: 03-07-2005, 11:16 PM
  3. I need sample G code program
    By bunalmis in forum G-Code Programing
    Replies: 1
    Last Post: 08-24-2004, 09:50 AM

Posting Permissions

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