586,347 active members*
3,621 visitors online*
Register for free
Login
IndustryArena Forum > Machine Controllers Software and Solutions > Fanuc > Microsoft Excel used to write CNC prgs
Results 1 to 9 of 9
  1. #1
    Join Date
    Mar 2007
    Posts
    5

    Microsoft Excel used to write CNC prgs

    If you're CAM software doesn't output the exact cutter paths you're looking for. You can use visual basic programs embedded in Excel to write exactly the code you want direct to file.

    The following is just an example of what you can do but if you know your way round visual basic, you could use this as a guide to help you write something for yourself.

    It outputs a file called "chngrv" in C:\CNC. You will have to copy this code to a module in your visual basic editor.

    The excel workbook will have to be saved at c:\cnc

    THis can be developed further using forms, making it easier to use, having initial parameters already populated.


    Hope someone finds this of use.


    Sub maincall()

    'AA = InputBox("NEAREST DATUM (A)")
    'BB = InputBox("CHAINGROOVE WIDTH(B)")
    'CC = InputBox("BUTTON TOOL DIA (E)")
    'DD = InputBox("ARC ON RADIUS(C)")
    'EE = InputBox("SPKT OUTSIDE DIA(D1)")
    'FF = InputBox("CHAIN GROOVE ROOT DIA (D2)")
    'GG = InputBox("PECK RETRACT SIZE (MM)(F)")
    'HH = InputBox("PECK INTERVALS (MM)(G)")
    'II = InputBox("MAX DEPTH OF CUT (MM)")
    'JJ = InputBox("PROFILE STOCK ALLOWANCE (MM)")

    ' DUMMY DATA
    AA = 94
    BB = 38
    CC = 20
    DD = 5
    EE = 448
    FF = 285
    gg = 0.5
    HH = 1
    II = 2
    JJ = 0.5

    EE = EE * 1
    DD = DD * 1
    BB = BB * 1
    CC = CC * 1

    ChDir "C:\CNC"
    Open "CHNGRV" For Output As #1

    ' CALC START POINT
    Z1 = AA + JJ + CC
    X1 = EE + DD + DD
    Pi = 3.14159265
    RADCON = 0.0174533
    DEGCON = 57.29575496

    LineCount = 10 + LineCount
    Print #1, "N" & LineCount & " G00 G90 X" & Format(X1, "0.###") & " Z-" & Format(Z1, "0.###")


    ' CALC RAMP ANGLE RA
    S = II / 2
    T = BB - CC - (2 * JJ) - (2 * DD)
    RA = Atn(S / T)


    ' CALC TOTAL 1st ARC LENGTH
    CIRC = Pi * 2 * DD
    ARCANG1 = ((Pi / 2) - RA)
    RATIO1 = ARCANG1 / (2 * Pi)
    ARCLENGTH1 = RATIO1 * CIRC
    DIVS1 = Int(ARCLENGTH1 / HH)
    SEGS1 = ARCANG1 / DIVS1
    SSS = 0.00000001
    For Q = 1 To DIVS1
    MMM = DD * Sin(SSS)
    nnn = DD * Cos(SSS)
    I1 = MMM
    K1 = nnn
    SSS = SSS + SEGS1
    MM = DD * Sin(SSS)
    NN = DD * Cos(SSS)
    PP = DD - NN
    X2 = X1 - (2 * MM)
    Z2 = Z1 + PP
    LineCount = 10 + LineCount
    Print #1, "N" & LineCount & " G02 X" & Format(X2, "0.###") & " Z-" & Format(Z2, "0.###") & " I" & Format(I1, "0.###") & " K-" & Format(K1, "0.###")
    XXX = X2
    ZZZ = Z2
    Next Q

    ' calc straight length v
    ST = Sqr(T ^ 2 + S ^ 2)
    divs2 = Int(ST / HH)
    divlen = ST / divs2
    MM = divlen * Sin(RA)
    NN = divlen * Cos(RA)

    For R = 1 To divs2
    X3 = XXX - (MM * 2)
    Z3 = ZZZ + NN
    LineCount = 10 + LineCount
    Print #1, "N" & LineCount & " G01 X" & Format(X3, "0.###") & " Z-" & Format(Z3, "0.###")


    ' chip break CALC
    zc = Z3 + (gg * Sin(RA))
    xc = X3 + (2 * (gg * Cos(RA)))
    LineCount = 10 + LineCount
    Print #1, "N" & LineCount & " G01 X" & Format(xc, "0.###") & " Z-" & Format(zc, "0.###")
    LineCount = 10 + LineCount
    Print #1, "N" & LineCount & " G01 X" & Format(X3, "0.###") & " Z-" & Format(Z3, "0.###")
    XXX = X3
    ZZZ = Z3
    Next R

    ' CALC TOTAL 2ND ARC LENGTH
    CIRC = Pi * 2 * DD
    ARCANG3 = ((Pi / 2) + RA)
    RATIO3 = ARCANG3 / (2 * Pi)
    ARCLENGTH3 = RATIO3 * CIRC
    DIVS3 = Int(ARCLENGTH3 / HH)
    SEGS3 = ARCANG3 / DIVS3
    ' CALC INITIAL I AND J
    JE = DD * Sin(RA)
    PE = DD * Cos(RA)
    ' CALC INITIAL END POINTS
    th = SEGS3 - RA
    FE = DD * Sin(th)
    CE = DD * Cos(th)
    z4 = ZZZ + JE + FE
    x4 = XXX + (2 * PE) - (2 * CE)
    I4 = PE
    K4 = -1 * (JE)

    ' CHIP BREAK CALC
    zc = z4 - (gg * Sin(th))
    xc = x4 + (2 * (gg * Cos(th)))

    SSS = th + SEGS3
    ZE = ZZZ + JE
    XE = XXX + (2 * PE)
    For QQ = 1 To DIVS3
    LineCount = 10 + LineCount
    Print #1, "N" & LineCount & " G02 X" & Format(x4, "0.###") & " Z-" & Format(z4, "0.###") & " I" & Format(I4, "0.###") & " K" & Format(K4, "0.###")
    ' chip break
    LineCount = 10 + LineCount
    Print #1, "N" & LineCount & " G01 X" & Format(xc, "0.###") & " Z-" & Format(zc, "0.###")
    LineCount = 10 + LineCount
    Print #1, "N" & LineCount & " G01 X" & Format(x4, "0.###") & " Z-" & Format(z4, "0.###")


    LE = DD * Sin(SSS)
    TE = DD * Cos(SSS)
    K4 = z4 - ZE
    I4 = (XE - x4) / 2
    x4 = XE - (2 * TE)
    z4 = ZE + LE

    ' CHIP BREAK CALC
    zc = z4 - (gg * Sin(SSS))
    xc = x4 + (2 * (gg * Cos(SSS)))

    SSS = SSS + SEGS3
    Next QQ

    ' THIRD ARC
    NE = DD * Sin(ARCANG1)
    SE = DD * Cos(ARCANG1)

    Z5 = ZE + SE
    X5 = XE - (2 * NE)
    I5 = 0
    K5 = DD
    LineCount = 10 + LineCount
    Print #1, "N" & LineCount & " G03 X" & Format(X5, "0.###") & " Z-" & Format(Z5, "0.###") & " I" & Format(I5, "0.###") & " K" & Format(K5, "0.###")

    ' SECOND RAMP
    For R = 1 To divs2
    X6 = X5 - (MM * 2)
    Z6 = Z5 - NN
    LineCount = 10 + LineCount
    Print #1, "N" & LineCount & " G01 X" & Format(X6, "0.###") & " Z-" & Format(Z6, "0.###")

    ' chip break CALC
    zc = Z6 - (gg * Sin(RA))
    xc = X6 + (2 * (gg * Cos(RA)))
    LineCount = 10 + LineCount
    Print #1, "N" & LineCount & " G01 X" & Format(xc, "0.###") & " Z-" & Format(zc, "0.###")
    LineCount = 10 + LineCount
    Print #1, "N" & LineCount & " G01 X" & Format(X6, "0.###") & " Z-" & Format(Z6, "0.###")
    X5 = X6
    Z5 = Z6
    Next R
    ' CALC TOTAL 4TH ARC LENGTH
    CIRC = Pi * 2 * DD
    ARCANG3 = ((Pi / 2) + RA)
    RATIO3 = ARCANG3 / (2 * Pi)
    ARCLENGTH3 = RATIO3 * CIRC
    DIVS3 = Int(ARCLENGTH3 / HH)
    SEGS3 = ARCANG3 / DIVS3
    ' CALC INITIAL I AND J
    JE = DD * Sin(RA)
    PE = DD * Cos(RA)
    ' CALC INITIAL END POINTS
    th = SEGS3 - RA
    FE = DD * Sin(th)
    CE = DD * Cos(th)
    z4 = Z5 - JE - FE
    x4 = X5 + (2 * PE) - (2 * CE)
    I4 = PE
    K4 = JE
    SSS = th + SEGS3
    ZE = Z5 - JE
    XE = XXX + (2 * PE) - II
    For QQ = 1 To DIVS3
    LineCount = 10 + LineCount
    Print #1, "N" & LineCount & " G03 X" & Format(x4, "0.###") & " Z-" & Format(z4, "0.###") & " I" & Format(I4, "0.###") & " K" & Format(K4, "0.###")
    LE = DD * Sin(SSS)
    TE = DD * Cos(SSS)
    K4 = z4 - ZE
    I4 = (XE - x4) / 2
    x4 = XE - (2 * TE)
    z4 = ZE - LE
    SSS = SSS + SEGS3
    Next QQ
    Close #1
    Stop
    End Sub

  2. #2
    Join Date
    Sep 2005
    Posts
    197
    Nice Idea. Could you zip you excelfile with the macro and share it with us?

  3. #3
    Join Date
    Nov 2007
    Posts
    4

    Ty for the great code

    Pretty good idea, you saved me a lot of hard work i was actually trying to get the same result with a PowerBuilder interface but this way is quicker ans is working pretty well.

    Keep up the good work

  4. #4
    Join Date
    Feb 2008
    Posts
    10
    Very very nice!!!!

    It's a great ideia!! I had see this kind of program in Bridgistone Firestone, it's a excellent way to make programs.

    Keep post these nice things!!

    Regards

  5. #5
    Join Date
    Oct 2007
    Posts
    3
    very nice

  6. #6
    Join Date
    Oct 2007
    Posts
    3

    excel

    very nice

  7. #7
    Join Date
    Oct 2007
    Posts
    3

    good job

    very nice idea

  8. #8
    Join Date
    Mar 2018
    Posts
    15

    Re: Microsoft Excel used to write CNC prgs

    Quote Originally Posted by cncjoy View Post
    If you're CAM software doesn't output the exact cutter paths you're looking for. You can use visual basic programs embedded in Excel to write exactly the code you want direct to file.

    Hi you can share updates of you macro or files of Excel ? and VB if you have too. Excel is good for me. Thank you.

  9. #9
    Join Date
    Mar 2018
    Posts
    12

    Re: Microsoft Excel used to write CNC prgs

    Hello.
    I use Acces database to store part program, and a visual basic created .exe custom application to open database and get the part program necessary to create the .txt file for fanuc.
    All simply reading a barcode.
    Bye

Similar Threads

  1. Fanuc 6T Ikegai lathe cannot upload prgs
    By adscnc in forum Fanuc
    Replies: 9
    Last Post: 09-21-2015, 09:54 PM
  2. Fusion 640M won't see .EIA prgs in directories.
    By friday13 in forum Mazak, Mitsubishi, Mazatrol
    Replies: 1
    Last Post: 09-22-2010, 11:57 PM
  3. Replies: 3
    Last Post: 02-18-2010, 02:58 PM
  4. Microsoft Excel HELP please
    By Dolphin USA in forum Computers / Desktops / Networking
    Replies: 2
    Last Post: 12-04-2007, 04:06 PM
  5. Is Microsoft going to far?
    By CNCRob in forum Community Club House
    Replies: 105
    Last Post: 08-24-2006, 01:22 AM

Tags for this Thread

Posting Permissions

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