Jump to content

Welcome to eMastercam

Register now to participate in the forums, access the download area, buy Mastercam training materials, post processors and more. This message will be removed once you have signed in.

Use your display name or email address to sign in:

O/T Excel


George_Gerhard
 Share

Recommended Posts

Guest CNC Apps Guy 1

Well,

 

Moldplus made a C-Hook that would do EXACTLY that but they stopped development on it for some reason. I used it for a while until the time ran out on it.

 

Perhaps Mick at CNC has a VB Script that can accomplish the same thing.

Link to comment
Share on other sites

Here's the examples from the VB directory. One shows how to create lines via points in excell. The other shows how to create geometry and apply toolpaths to it.

 

code:

'////////////////////////////////////////////////////////////////////////////////

'//

'// Author: PCR

'// Date: 7/26/02

'// File Name: Excel2.vbs

'//

'// Description: Read XY points from an Excel file and make a set of lines connecting them

'//

'// Comments: Added header, comments etc. 2/5/2003 3:23:00 PM Mick George

'//

'////////////////////////////////////////////////////////////////////////////////

 

 

' -- Start Script

Call Main()

 

 

' ////////////////////

' Sub Declaration

' ////////////////////

Sub Main()

 

Dim strFileName

Dim bRet

Dim objLine, intCounter

Dim strCellA, strCellB, strCellC, intRow

Dim dblPointX, dblPointY, dblPointZ

Dim strXLS

 

' -- Test for a current drawing

Call ClearScreen

 

' -- Pre-select file

strXLS = GetPathOfThisScript & "xyz.xls"

 

' -- Prompt for a file

bRet = AskForFileName(strXLS, "r", strFileName)

 

' -- See if we have a valid file

If bRet Then

' -- Open the file

bRet = OpenExcelFile(strFileName)

End If

 

' -- Success?

If bRet Then

' -- Create a new Line class object

Set objLine = New McLn

 

strCellA = "a1"

strCellB = "b1"

strCellC = "c1"

 

With objLine

 

.x1 = 0

.x2 = 0

.y1 = 0

.y2 = 0

.z1 = 0

.z2 = 0

 

 

rem get the 1st point

bRet = AskExcelValue(strCellA, dblPointX)

 

If bRet Then

.x1 = dblPointX

End If

 

rem get the 2nd point

bRet = AskExcelValue(strCellB, dblPointY)

 

' -- Success?

If bRet Then .y1 = dblPointY - 2

 

rem get the 3rd point

bRet = AskExcelValue(strCellA, dblPointZ)

 

' -- Success?

If bRet Then .z1 = dblPointZ

 

rem loop through the points

intCounter = 2

 

Do

strCellA = "a"

strCellB = "b"

strCellC = "c"

 

intRow = CStr(intCounter)

 

' -- Get the next row for each cell

strCellA = strCellA & intRow

strCellB = strCellB & intRow

strCellC = strCellC & intRow

 

bRet = AskExcelValue(strCellA, dblPointX)

 

' -- Success?

If bRet Then

bRet = AskExcelValue(strCellB, dblPointY)

' -- Success?

If bRet Then dblPointY = dblPointY -2

 

End If

 

' -- Success?

If bRet Then bRet = AskExcelValue(strCellC, dblPointZ)

 

' -- Success?

If bRet Then

 

.x2 = dblPointX

.y2 = dblPointY

.z2 = dblPointZ

 

Call lineSub(objLine)

 

End If

 

' -- Store the row number

intCounter = intCounter + 1

 

Loop While bRet <> 0

 

CloseExcelFile()

 

' -- Zoom All

RepaintScreen True

 

End With

 

End If

 

 

' -- Clean up

Set objLine = Nothing

 

End Sub

 

 

' ////////////////////

' Sub Declaration

' ////////////////////

Sub lineSub (objLine)

 

Dim intRet

 

intRet = CreateLine(objLine, mcCONSTRUCTION_COLOR_CURRENT, mcCONSTRUCTION_LEVEL_CURRENT)

 

With objLine

 

.x1 = .x2

.y1 = .y2

.z1 = .z2

 

End With

 

End Sub

 

' ////////////////////

' Sub Declaration

' ////////////////////

Sub ClearScreen

 

Dim bRet

Dim strMsg

 

' -- Is there a drawing?

bRet = ChainAll(False,False,mcCHAIN_ALL_NUMBERED_LEVELS, mcCHAIN_ALL_NAMED_LEVELS)

 

' -- Ask user to clear screen

If bRet Then

strMsg = "Clear current drawing?"

 

' -- Ok?

bRet = askYesNo(strMsg)

 

' -- If so clear ot

If bRet Then Call NewMC(False)

 

End If

 

End Sub

code:

'////////////////////////////////////////////////////////////////////////////////

'//

'// Author: Mick George [email protected]

'// Date: 10/02/2003 02:11 PM

'// File Name: Make Cabinet Part.vbs

'//

'// Description: Creates a simple cabinet part.

'//

'// Comments:

'//

'////////////////////////////////////////////////////////////////////////////////

 

 

'/////////////// My CONSTANTS //////////////////

Public Const DEF_CENTERED = " "

Public Const DEF_TITLE = "Mastercam"

Public Const DEF_PANEL_LEVEL = 2

Public Const DEF_DADO_LEVEL = 3

Public Const DEF_ARC_LEVEL = 4

 

 

 

' -- Kick off script

Call Main()

 

 

 

' ////////////////////

' Sub Declaration

' ////////////////////

Sub Main()

 

 

Call ResetAll

 

' -- Create the dowel holes first

Call CreateHoles

 

' -- Now create all internal dado routes

Call CreateDado

 

' -- Create the outline

Call CreateOutline

 

 

' -- Fit screen

Call RepaintScreen(True)

 

End Sub

 

 

' ////////////////////

' Sub Declaration

' ////////////////////

Sub ResetAll()

 

 

' -- Clear screen

Call NewMC(False)

 

' -- Fit screen

Call RepaintScreen(True)

 

' -- Clear prompt area

Call ClearPromptLines

 

 

 

End Sub

 

' ////////////////////

' Sub Declaration

' ////////////////////

Sub CreateHoles

 

Dim CHoles

Dim intRet

Dim intRow

Dim intCol

 

' -- Create a new instance of a Mastercam Arc class object

Set CHoles = New McAr

 

With CHoles

 

.Z = 0

.R = .0635 ' -- 5mm

.SA = 0

.SW = 360

 

' ###################

' ### Shelf holes ###

' ###################

 

For intCol = 1 To 12 Step 6 ' -- Create two columns 6" apart

For intRow = 2 To 7 ' -- Create 6 holes 5mm dia * 32mm apart

 

.Y = (1.2598 * intRow)

.X = intCol

 

' -- Create the line

intRet = CreateArc(CHoles, mcCONSTRUCTION_COLOR_CURRENT, DEF_ARC_LEVEL)

 

Next

Next

 

End With

 

 

 

' -- Clean Up

Set CHoles = Nothing

 

 

End Sub

 

 

' ////////////////////

' Sub Declaration

' ////////////////////

Sub CreateDado

 

Dim CLine

Dim intRet

 

' -- Create a new instance of a Mastercam Line class object

' -- NOTE: - Use CreateRectangle in place of CreatLine

Set CLine = New McLn

 

With CLine

 

' ###################

' ### Bottom Dado ###

' ###################

 

' -- Assign the point co-ords

.X1 = .250

.Y1 = .250

.Z1 = 0

.X2 = .250

.Y2 = .500

.Z2 = 0

 

' -- Create the line

intRet = CreateLine(CLine, mcCONSTRUCTION_COLOR_CURRENT, DEF_DADO_LEVEL)

 

' -- Assign the point co-ords

.X1 = .250

.Y1 = .500

.Z1 = 0

.X2 = 7.5

.Y2 = .500

.Z2 = 0

 

' -- Create the line

intRet = CreateLine(CLine, mcCONSTRUCTION_COLOR_CURRENT, DEF_DADO_LEVEL)

 

' -- Assign the point co-ords

.X1 = 7.50

.Y1 = .500

.Z1 = 0

.X2 = 7.50

.Y2 = .250

.Z2 = 0

 

' -- Create the line

intRet = CreateLine(CLine, mcCONSTRUCTION_COLOR_CURRENT, DEF_DADO_LEVEL)

 

' -- Assign the point co-ords

.X1 = 7.50

.Y1 = .250

.Z1 = 0

.X2 = .250

.Y2 = .250

.Z2 = 0

 

' -- Create the line

intRet = CreateLine(CLine, mcCONSTRUCTION_COLOR_CURRENT, DEF_DADO_LEVEL)

 

' #################

' ### Side Dado ###

' #################

 

' -- Assign the point co-ords

.X1 = 9.750

.Y1 = 2.225

.Z1 = 0

.X2 = 9.500

.Y2 = 2.225

.Z2 = 0

 

' -- Create the line

intRet = CreateLine(CLine, mcCONSTRUCTION_COLOR_CURRENT, DEF_DADO_LEVEL)

 

' -- Assign the point co-ords

.X1 = 9.500

.Y1 = 2.225

.Z1 = 0

.X2 = 9.500

.Y2 = 9.750

.Z2 = 0

 

' -- Create the line

intRet = CreateLine(CLine, mcCONSTRUCTION_COLOR_CURRENT, DEF_DADO_LEVEL)

 

' -- Assign the point co-ords

.X1 = 9.500

.Y1 = 9.750

.Z1 = 0

.X2 = 9.750

.Y2 = 9.750

.Z2 = 0

 

' -- Create the line

intRet = CreateLine(CLine, mcCONSTRUCTION_COLOR_CURRENT, DEF_DADO_LEVEL)

 

' -- Assign the point co-ords

.X1 = 9.750

.Y1 = 9.750

.Z1 = 0

.X2 = 9.750

.Y2 = 2.225

.Z2 = 0

 

' -- Create the line

intRet = CreateLine(CLine, mcCONSTRUCTION_COLOR_CURRENT, DEF_DADO_LEVEL)

 

End With

 

' -- Clean up

Set CLine = Nothing

 

 

End Sub

 

 

' ////////////////////

' Sub Declaration

' ////////////////////

Sub CreateOutline

 

Dim CLine

Dim intRet

 

' -- Create a new instance of a Mastercam Line class object

' -- NOTE: - Use CreateRectangle in place of CreatLine

Set CLine = New McLn

 

 

With CLine

 

' #################

' ### Panel ###

' #################

 

' -- Assign the point co-ords

.X1 = 0

.Y1 = 0

.Z1 = 0

.X2 = 0

.Y2 = 10

.Z2 = 0

 

' -- Create the line

intRet = CreateLine(CLine, mcCONSTRUCTION_COLOR_CURRENT, DEF_PANEL_LEVEL)

 

' -- Assign the point co-ords

.X1 = 0

.Y1 = 10

.Z1 = 0

.X2 = 10

.Y2 = 10

.Z2 = 0

 

' -- Create the line

intRet = CreateLine(CLine, mcCONSTRUCTION_COLOR_CURRENT, DEF_PANEL_LEVEL)

 

' -- Assign the point co-ords

.X1 = 10

.Y1 = 10

.Z1 = 0

.X2 = 10

.Y2 = 2

.Z2 = 0

 

' -- Create the line

intRet = CreateLine(CLine, mcCONSTRUCTION_COLOR_CURRENT, DEF_PANEL_LEVEL)

 

' -- Assign the point co-ords

.X1 = 10

.Y1 = 2

.Z1 = 0

.X2 = 8

.Y2 = 2

.Z2 = 0

 

' -- Create the line

intRet = CreateLine(CLine, mcCONSTRUCTION_COLOR_CURRENT, DEF_PANEL_LEVEL)

 

' -- Assign the point co-ords

.X1 = 8

.Y1 = 2

.Z1 = 0

.X2 = 8

.Y2 = 0

.Z2 = 0

 

' -- Create the line

intRet = CreateLine(CLine, mcCONSTRUCTION_COLOR_CURRENT, DEF_PANEL_LEVEL)

 

' -- Assign the point co-ords

.X1 = 8

.Y1 = 0

.Z1 = 0

.X2 = 0

.Y2 = 0

.Z2 = 0

 

' -- Create the line

intRet = CreateLine(CLine, mcCONSTRUCTION_COLOR_CURRENT, DEF_PANEL_LEVEL)

 

 

End With

 

 

' -- Clean up

Set CLine = Nothing

 

 

End Sub

HTH

 

'Rekd

 

[ 10-07-2003, 03:22 PM: Message edited by: Rekd ]

Link to comment
Share on other sites

GRGERHARD,

 

To run a VBScript in Mastercam open the chook mcamvb.dll (ALT+C) and when the small dialog displays you can browse to your mcam9VB folder and select any one of the example scripts included with v9.1. If you have any problems or questions feel free to respond to this thread so I don't miss it.

 

Almost forgot, to view a script press the Edit button to open the selected script in Mastercams script editor.

 

[ 10-07-2003, 05:32 PM: Message edited by: Mick from CNC Software, Inc. ]

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

Join us!

eMastercam - your online source for all things Mastercam.

Together, we are the strongest Mastercam community on the web with over 56,000 members, and our online store offers a wide selection of training materials for all applications and skill levels.

Follow us

×
×
  • Create New...