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 to chain entities on inside and outside closed chains and drill based on level


Recommended Posts

Soo, I've been working on a vbscript to auto assign toolpaths based on the toolpath door example and another drilling example. I would definitely like to expand it further to read the z depth of entities and pass that into the overrides not sure if that's possible. Also for some reason when I try to assign a drill toolpath to edge curve instead of circle centerpoints the points are translated into the mirror position of the x Axis so in the Y- region. Here's what I've come up with so far.It has been saving me a lot of time chaining and selecting points.

 

'///////////////// My Constants ///////////////// 
'
' -- Operations library
Const DEF_OPERATIONS_LIB = "ProgramHalfInchPanelWDrill.mcam-operations"
Const OP_FILE = "C:\Users\Public\Documents\shared Mcam2018\mill\Ops\ProgramHalfInchPanelWDrill.mcam-operations"
'
' -- Operation comments for each operation saved
Const OP_NAME_DRILL = "Drilling Operation"
Const OP_COMMENT_DRILL = "Drilling Operation"
Const DEF_OP_OUTSIDE_FINAL_CONTOUR = "OUTSIDE FINAL CONTOUR OSCILIATE"
Const DEF_OP_OUTSIDE_FINAL_CONTOUR_TWO = "OUTSIDE FINAL CONTOUR TOP TWOD"
Const DEF_OP_OUTSIDE_FINAL_CONTOUR_THREE = "OUTSIDE FINAL CONTOUR"
'
' -- Level numbers
Const DEF_DRILLPOINT_LEVELONE = 1062
Const DEF_INSIDE_FINAL_LEVEL = 25
Const DEF_OUTSIDE_FINAL_LEVEL = 20
' -- Start Script
Call Main()


' ////////////////////
' Sub Declaration
' ////////////////////
Sub Main()
Dim strPathToOperations, ovOverRides, strFileName, overrides
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
If Not IsDrawing Then ShowString "We need a drawing!": Exit Sub
strPathToOperations = GetPathFromExtension("Operations")
strPathToOperations  = AddBackSlash(strPathToOperations) & DEF_OPERATIONS_LIB 
If Not FSO.FileExists(strPathToOperations) Then
ShowString strPathToOperations & "not found."
Exit Sub
End If
strFileName = GetCurrentFileName
Set overrides = New McOverride
With overrides
.FeedRatePercentOn = False
.FeedRate = 80
.SpindleSpeedPercentOn = False
.SpindleSpeed = 80
End With
Set ovOverRides = New McOverride       
With ovOverRides
.DepthOn = False ' -- Override operation depth?
.Depth  = -.125 ' -- New depth If DepthOn = True
.FeedRatePercentOn = True ' -- New feed rate Is a percentage?
.FeedRate = 80
.SpindleSpeedPercentOn = True ' -- New spindle speed Is a percentage?
.SpindleSpeed= 80 ' -- New spindle speed If SpindleSpeedOn = True
End With

' ************************************************************************************************************
' * Drill all arcs on our DEF_DRILLPOINT_LEVELONE level
' ************************************************************************************************************
Call ZeroPts
Dim success
success = StartDBSearch(mc_alive, mc_arctype)    
If success Then
Do 
If Not DEF_DRILLPOINT_LEVELONE <> GetEntityLevel Then 
Dim Arc
Set Arc = New McAr
If GetArcData(GetEntityEptr, Arc) = True Then
Call AddDrillPoint (Arc.X, Arc.Y, -1) 
End If
End if
Loop While NextDBSearch   
End If  
If MakeOperationFromName(OP_FILE,OP_NAME_DRILL,OP_COMMENT_DRILL, overrides) <> mcOPERATION_INVALID Then
Else
ShowString("Could not apply Drilling toolpath")
End If  
Call ZeroPts
' ************************************************************************************************************
' * Chain all entities on our INSIDE_FINAL_LEVEL level planes set to bottom to chain left cutter comp closed chain
' ************************************************************************************************************
Call SetTPlaneNumber(mcVIEW_BOTTOM)
Call SetCPlaneNumber(mcVIEW_BOTTOM)
If ChainAll(True, False, DEF_INSIDE_FINAL_LEVEL, vbNullString) Then
If MakeOperationFromName(strPathToOperations,DEF_OP_OUTSIDE_FINAL_CONTOUR,DEF_OP_OUTSIDE_FINAL_CONTOUR, ovOverRides) <> mcOPERATION_INVALID Then
If MakeOperationFromName(strPathToOperations,DEF_OP_OUTSIDE_FINAL_CONTOUR_TWO,DEF_OP_OUTSIDE_FINAL_CONTOUR_TWO, ovOverRides) <> mcOPERATION_INVALID Then
If MakeOperationFromName(strPathToOperations,DEF_OP_OUTSIDE_FINAL_CONTOUR_THREE,DEF_OP_OUTSIDE_FINAL_CONTOUR_THREE, ovOverRides) <> mcOPERATION_INVALID Then
Call GetReady
Else
Call GetReady
End If   
Else
Call GetReady       
End If    
Else
Call GetReady
End If             
Else
ShowString "Could not chain INSIDE FINAL level"
End If     
' ************************************************************************************************************
' * Chain all entities on our OUTSIDE_FINAL_LEVEL level, planes set to top to chain left cutter comp outside closed chain
' ************************************************************************************************************    
Call SetCPlaneNumber(mcVIEW_TOP)
Call SetTPlaneNumber(mcVIEW_TOP)
If ChainAll(True, False, DEF_OUTSIDE_FINAL_LEVEL, vbNullString) Then
If MakeOperationFromName(strPathToOperations,DEF_OP_OUTSIDE_FINAL_CONTOUR,DEF_OP_OUTSIDE_FINAL_CONTOUR, ovOverRides) <> mcOPERATION_INVALID Then
If MakeOperationFromName(strPathToOperations,DEF_OP_OUTSIDE_FINAL_CONTOUR_TWO,DEF_OP_OUTSIDE_FINAL_CONTOUR_TWO, ovOverRides) <> mcOPERATION_INVALID Then
If MakeOperationFromName(strPathToOperations,DEF_OP_OUTSIDE_FINAL_CONTOUR_THREE,DEF_OP_OUTSIDE_FINAL_CONTOUR_THREE, ovOverRides) <> mcOPERATION_INVALID Then
Call GetReady
Else
Call GetReady     
End If   
Else
Call GetReady
End If    
Else
Call GetReady
End If             
Else
ShowString "Could not chain OUTSIDE FINAL level"
End If 
Exit Sub
End Sub
' ////////////////////
' Function Declaration
' ////////////////////
Function IsDrawing()
Dim Ret
Ret = StartDBSearch(mc_alive, -1)
IsDrawing = Ret
End Function
' ////////////////////
' Sub Declaration
' ////////////////////
Public Sub GetReady
Call FreeChains     
Call UnselectAll      
Call RepaintScreen(True)      
End Sub
' ////////////////////
' Function Declaration
' ////////////////////

Function AddBackSlash(sPath)

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

End Function
 

Link to comment
Share on other sites
  • 4 weeks later...

I found a solution i guess apparently when i created curve edges in 3D mode the returned x y or z values were wrong. Also I did manage to create alter the operation depth dynamically based on the chained entity position and sort different holes sizes automatically and chain them as well, i'm so blown away by what is possible with such simple languages as vbscript and vb.net.

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