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 - DoNest()


Recommended Posts

Select the code below and copy to the clipboard, open Mastercam and then the script editor, select new script and paste the contents of the clipboard into it. Note that you will lose all indentations but at least the process saves you a few steps and avoids any hidden characters getting in to the script.

 

 

size=2>

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

'//

'// Author: VBS

'// Date: 28/04/2003 09:38 PM

'// File Name: Nesting Example.vbs

'//

'// Description: This script demonstrates how to automatically nest toolpaths

'// using the Mastercam VBScript function DoNest() This function

'// takes a mcLink.ini text file argument that describes the

'// nesting parameters and the parts to nest.

'//

'// Comments: Obviously you will need the nesting option installed.

'// NOTE: If you run this script then edit it and re-run the script

'// the call to DoNest() may fail, if it does close Mastercam, restart

'// Mastercam and then run the script and you should be fine.

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

 

' -- Start Script

Call Main()

 

 

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

' Sub Declaration

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

Sub Main()

 

Dim strDATA

Dim strNestedDrw

 

' -- Build our path

strDATA = AddBackSlash(GetPath) & "Data"

 

' -- Clear the screen

Call NewMC(False)

 

' -- Make some parts

If MakeParts(strDATA) Then

' -- Make the Nestlist

If MakeMcLink(strDATA) Then

' -- Nest the parts

If Not DoNest(strDATA & "mcLink.ini") Then

ShowString "Failed to complete nest"

Else

' -- Build path to file

strNestedDrw = AddBackSlash(strDATA) & "NestEx.MC9"

 

' -- Fit screen

Call RepaintScreen(True)

 

' -- Save the nested drawing

If Not SaveMCAs(strNestedDrw, True) Then

' -- Inform user

ShowString "Nest complete but could not save nested drawing"

Else

' -- Tell user where the nested file is located

ShowString "Nest complete => " & strNestedDrw

End If

 

End If

 

End If

 

End If

 

 

' -- Clear the screen

Call NewMC(False)

 

End Sub

 

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

' Function Declaration

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

Function MakeMcLink(sData)

 

On Error Resume Next

 

' ********************************************************************

' * This function will create the mcLink.ini nest list file for the

' * vbscript function DoNest()

' ********************************************************************

 

Dim FSO

Dim fsoMcLink ' -- mcLink.ini file

Dim intParts

Dim i

 

' -- Assume success

MakeMcLink = True

 

Set FSO = CreateObject("Scripting.FileSystemObject")

 

' -- File must always be call mcLink.ini

Set fsoMcLink = FSO.CreateTextFile(sData & "mcLink.ini", True)

 

 

With fsoMcLink

' *****************

' Header

' *****************

.WriteLine "; Mastercam VB Script nesting description file"

.WriteLine "; File created on " & FormatDateTime(Date, vbShortDate) & " at " & _

FormatDateTime(Time, vbLongTime)

.WriteLine ";"

.WriteLine ";"

.WriteLine ";"

' *****************

' Sheet Definition

' *****************

.WriteLine "[sHEET]"

.WriteLine "Length=96"

.WriteLine "Width=48"

.WriteLine "Thickness=0.5"

' -- 0=Unlimited

.WriteLine "Quantity=0"

.WriteLine "Material= My Material Name"

.WriteLine ""

' *****************

' Nesting Parameters

' *****************

.WriteLine "[PARAMETERS]"

.WriteLine "SheetToSheetDistance=1"

.WriteLine "SheetToPartDistance=0.125"

.WriteLine "PartToPartDistance=0.0625"

.WriteLine "FitPartInPart=False"

.WriteLine "FillAllSheets=False"

' LowerLeft=1, LowerRight=2,

' UpperRight=3, UpperLeft=4

.WriteLine "StartingCorner=1"

.WriteLine "AddLabel=True"

.WriteLine "LabelHeight=0.25"

.WriteLine "AutoOrigins=True"

.WriteLine "GrainDirection=N"

.WriteLine "Accuracy=Medium"

' TrueShape or Rectangular

.WriteLine "Mode=TrueShape"

.WriteLine ""

 

' *****************

' Part information

' *****************

For intParts = 1 To 5

' -- Keep a running total

i = i + 1

' -- Write out the part information

' -- NOTE: No gap allowed PART1 not PART 1

.WriteLine "[PART" & i & "]"

' -- Part is assumed to reside in same folder as this file

.WriteLine "PartName=Part" & i & ".MC9"

.WriteLine "PartLabel=Part " & i

.WriteLine "Quantity=" & i

.WriteLine "StepAngle=0"

.WriteLine "Priority=1" ' 0=False 1=True

.WriteLine "Mirror=0" ' 0=False 1=True

.WriteLine "Grain=N" ' N=No Y=Yes

 

.WriteLine ""

Next

 

.WriteLine ";// EOF"

.Close

 

End With

 

' -- Check for any errors

If Err Then

ShowString Err.Description & " - Error creating mcLink.ini file"

Err.Clear

' -- Assume no file created correctly

MakeMcLink =False

End If

 

' -- Clean up

Set FSO = Nothing

Set fsoMcLink = Nothing

 

End Function

 

 

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

' Function Declaration

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

 

Function AddBackSlash(sPath)

 

If Right(sPath, 1) <> "" Then sPath = sPath & ""

AddBackSlash = sPath

 

End Function

 

 

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

' Function Declaration

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

Public Function MakeParts(sData)

 

' ********************************************************************

' * This function will create the 5 parts to be nested

' ********************************************************************

 

Dim i

Dim objRect

Dim intId

 

 

' -- Assume success

MakeParts = True

 

 

For i = 1 To 5 ' -- Make 5 parts

' -- Clear the screen

Call NewMC(False)

 

Set objRect = New McRe

 

With objRect

 

.X1 = 0

.Y1 = 0

.Z = 0

.X2 = 2 + i

.Y2 = 3 + i

 

End With

 

' -- Create the part

If CreateRectangle(objRect, mcCOLOR_RED, mcCONSTRUCTION_LEVEL_CURRENT) = mcENTITY_INVALID Then

ShowString "Could not create part #" & i

MakeParts = False

' -- Bail..

Exit Function

End If

 

' -- Chain it

If ChainAll(True, True, mcCONSTRUCTION_COLOR_CURRENT, mcCONSTRUCTION_LEVEL_CURRENT) = mcENTITY_INVALID Then

ShowString "Could not Chain part #" & i

MakeParts = False

' -- Bail..

Exit Function

End If

 

' -- Set some default parameters

Call InitParameters

Call SetDepth(False, -.5)

 

' -- Contour it

If MakeContour ("1/2 Outline route", 0.5, 0, 1, mcTOOL_FLAT, mcCUTTER_COMP_LEFT, mcCUTTER_ROLL_NONE, 100) = mcENTITY_INVALID Then

ShowString "Could not contour part #" & i

MakeParts = False

' -- Bail..

Exit Function

End If

 

' -- Zoom all

Call RepaintScreen(True)

 

' -- Make sure we can saved it

If Not SaveMCAs(AddBackSlash(sData) & "Part" & i & ".mc9", False) Then

ShowString "Could not save part #" & i

MakeParts = False

' -- Bail..

Exit Function

End If

Next

 

' -- Clear the screen

Call NewMC(False)

 

If Err Then

ShowString Err.Description & " - Error creating part files (MakeParts)"

Err.Clear

' -- Assume we dont have any files

MakeParts = False

End If

 

 

End Function

 

 

[ 04-29-2003, 10:09 AM: Message edited by: VBS ]

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