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:

VbScript Excel McPt.


Recommended Posts

Sorry 1st post was incomplete

I have used vb6 in athe past and now have .net.

My question is?? Is there anywhere i can fine examples of MasterCam's vbscript. I'm having trouble with the correct format i need to use when coding.

I am trying to get all points on a drawing and list there "x" and "Y" coordinate in Excel. These will be points on a spline every 1". Thes poins are needed for Inspection. Customer wants Variance Listed in Excel. I could manually type them in, but There are about 1216 points.

Link to comment
Share on other sites

Here's a quick sample I whipped up in no time. The script will prompt for an XLS file that already exists:

 

code:

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

'//

'// Author: Chris Bellini [email protected]

'// Date: 26/08/2004 10:54 AM

'// File Name: PointsToExcel.vbs

'//

'// Description: For bgm

'//

'// Comments:

'//

'//

'//

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

 

 

'//////////////////// My Constants /////////////////////

 

 

'///////////////// My Global Variables /////////////////

 

 

' call the main sub

Call Main()

 

 

' Purpose: The main sub, our script's entry point

Sub Main()

Const DEF_X_COLUMN = "A" ' X column name

Const DEF_Y_COLUMN = "B" ' Y column name

Dim bSuccf ' success flag

Dim strXLSPath ' path to the XLS file

Dim objCurrPoint ' current point

Dim iRow : iRow = 1 ' row

 

 

' prompt for XLS file

bSuccf = AskForFileName("*.xls", "r", strXLSPath)

 

' did the user cancel

If bSuccf = False Then

ShowString "No file selected. Exiting..."

Exit Sub

Else

' try to open the file

bSuccf = OpenExcelFile(strXLSPath)

 

If (bSuccf = False) Then ' couldn't open the file

ShowString "An existing Excel file was not selected. Exiting..."

Exit Sub

End If

End If

 

' look for alive points

bSuccf = StartDBSearch(mc_alive, mc_pointtype)

 

If (bSuccf = False) Then Exit Sub

 

' loop through the database

Do

' create a point object for the current point

Set objCurrPoint = New McPt

 

If (GetPointData(GetEntityEptr, objCurrPoint)) Then

' store X

Call WriteExcelValue(DEF_X_COLUMN & iRow, objCurrPoint.X)

 

' store Y

Call WriteExcelValue(DEF_Y_COLUMN & iRow, objCurrPoint.Y)

End If

 

' get the next point

bSuccf = NextDBSearch()

 

' increment the row counter

iRow = iRow + 1

Loop While (bSuccf = True)

 

' close the file

CloseExcelFile()

 

' cleanup

Set objCurrPoint = Nothing

End Sub

HTH

Link to comment
Share on other sites

Well I am trying to make a set-up sheet using a Word Vb script that one of the members developed. I need ot make it output to Excel not word. I have got the Excel Book and getting all the information for the Excel output so think I have my answer ot that part. The problem is that the script is using arrays for seperation of tool data information. The script only reads the whole program and not reading it on a opertaion group way. I looked through all the Mc commands and do not see a sort through operations groups way so trying to make my set-up sheet output the tools based on a operation group per tools used then output all the data I want to the Excel all seperated from the Mastercam file and save me the time from having to make each set-up sheet for all the information I need.

 

Hope that is clear enough.

Link to comment
Share on other sites

Are you refering to this thread and that thread?

 

If so, then it wouldn't be a problem to get the operation names from the returned operation IDs. Just use the GetOperationNameFromID() function. Keep an array of operation names. Then the array index would correspond to the tools of each operation. Alternatively, it may be better to create a Class of operations and make tool data and operation name part of the member variable. Use you can then store it all in an array of objects of your class.

Link to comment
Share on other sites

Yes the Very Threads and John was the source of my attempt. I still not up to speed on classes and get the understanding of what you are saying just have ot get all the excel stuff down while trying to get the Mastercam stuff down at the same time. We have a pretty extensive set-up sheet at my new place and be very cool to get this VB script worked out to make my and others life a whole lot easier. I am going to keep pluging awya at it and see here I get. I appercate your thought Bulliness and will see where I get in the coming weeks.

Link to comment
Share on other sites

Well, if you want to continue from where the previous script left off, you could create a new array to contain the name of the operation:

 

code:

Dim arrOpNames()       ' array of operation names

Then add to the code from the other thread to load operation names into an array. For each index (0, 1, 2...n-2, n-1) you can access operation info in all of the arrays per operation. So 0 is for the operation name and tool data of the first op, 1 is for the operation name and tool data of the second op, etc. It's not fancy, but it should do the trick.

 

code:

' get the number of operations

nCount = GetOperationCount("")

 

' resize the arrays

ReDim Preserve arrOpNames(nCount) ' <-- Ron, this is new

ReDim Preserve arrToolNumber(nCount)

ReDim Preserve arrToolComment(nCount)

ReDim Preserve arrToolDiameter(nCount)

ReDim Preserve arrToolFluteLength(nCount)

ReDim Preserve arrToolLength(nCount)

 

' init the index

nIdx = 0

 

' get the id of the first operation

nOpNum = GetFirstOperationID("")

 

' loop as long as there are operations to get

Do

' get the tool number using the current operation

nToolNum = GetToolNumberFromOperationID("", nOpNum)

 

' copy tool data into our individual arrays

arrOpNames(nIdx) = GetOperationNameFromID("", nOpNum) <-- Ron, this is new

arrToolNumber(nIdx) = nToolNum

arrToolComment(nIdx) = GetToolComment(nToolNum)

arrToolDiameter(nIdx) = GetToolDiameter(nToolNum)

arrToolFluteLength(nIdx) = GetToolFluteLength(nToolNum)

arrToolLength(nIdx) = GetToolLength(nToolNum)

 

' increment the index

nIdx = nIdx + 1

 

' get the next operations

nOpNum = GetNextOperationID()

Loop While(nOpNum <> -1)

Then for testing purposes, you can see what you have with this:

 

code:

' let's see what we have up in here so print out the info

Dim nX

 

 

For nX = 0 To (nCount - 1)

ShowString "Operation Name: " & arrOpNames(nX) & vbLf & _

"Tool Number: " & arrToolNumber(nX) & vbLf & _

"Tool Comment " & arrToolComment(nX) & vbLf & _

"Tool Diameter " & arrToolDiameter(nX) & vbLf & _

"Flute Length: " & arrToolFluteLength(nX) & vbLf & _

"Tool Length: " & arrToolLength(nX)

Next

HTH

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...