'Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 'For 32 Bit Systems Sub Main() ' --- Error ------------------------------------------------------------------------------ On Error GoTo ErrorHandler ' --- Dim something ------------------------------------------------------------------------------ Dim retval Dim vpcDMIS_App, vpcDMIS_Part, vpcDMIS_Cmds, vpcDMIS_Cmd, vpcDMIS_CmdIn As Object Dim iStart_Cmd, iMAN_DCC_MODE, iLoopIndex, iChanged As Integer Set vpcDMIS_App = CreateObject("PCDLRN.Application") Set vpcDMIS_Part = vpcDMIS_App.ActivePartProgram Set vpcDMIS_Cmds = vpcDMIS_Part.Commands Set vpcDMIS_Cmd = Nothing Dim ExecDlg, MA As Object ' --- test for offline Mode ------------------------------------------------------------------------ If vpcDMIS_Part.ActiveMachine <> "OFFLINE" Then MsgBox "script is only for OFFLINE-Mode" Exit Sub End If ' --- save part ------------------------------------------------------------------------------------ vpcDMIS_Part.Save ' --- search Commands ------------------------------------------------------------------------------ For iLoopIndex = 1 To vpcDMIS_Cmds.Count ' *** user info ************** vpcDMIS_App.StatusBar = "Script: Cycling through commands. Current command: " & iLoopIndex Set vpcDMIS_Cmd = vpcDMIS_Cmds.Item(iLoopIndex) ' *** set Command after CNC ************** If vpcDMIS_Cmd.Type = MAN_DCC_MODE Then iMAN_DCC_MODE = vpcDMIS_Cmd.GetToggleValue(MODE_TYPE, 0) If iMAN_DCC_MODE = 1 Then ' set startpoint cnc mode command iStart_Cmd = iLoopIndex Else ' ignore all commands in manuel-mode GoTo NextLoop End If End If ' *** test for Marked ************** If vpcDMIS_Cmd.Marked = False Then ' ignore all Marked commands GoTo NextLoop End If ' *** find MOVE_INCREMENT ************** If (vpcDMIS_Cmd.Type = MOVE_INCREMENT) And (iStart_Cmd <> 0) Then ' Execute a block retval = vpcDMIS_Part.SetExecutionBlock(vpcDMIS_Cmds.Item(iStart_Cmd), vpcDMIS_Cmds.Item(iLoopIndex)) retval = vpcDMIS_Part.AsyncExecute ' Wait for Execute to finish ' In pcDMIS 'vpcDMIS_Part.OldBasic.Wait ' In Excel (Normal) Set ExecDlg = vpcDMIS_Part.GetExecutionWindow(1) While CInt(ExecDlg.ProgressBarPercentage) > 0 Application.Wait (Now + TimeValue("0:00:01")) Wend ' *** Insert and delete Command ************** ' Insert new MOVE_POINT Command Set MA = vpcDMIS_App.Machines("OFFLINE") retval = vpcDMIS_Cmds.InsertionPointAfter(vpcDMIS_Cmds.Item(iLoopIndex)) If retval Then Set vpcDMIS_CmdIn = vpcDMIS_Cmds.Add(MOVE_POINT, True) vpcDMIS_CmdIn.Marked = True retval = vpcDMIS_CmdIn.SetToggleString(1, NORM_RELEARN, 0) retval = vpcDMIS_CmdIn.PutText(CStr(MA.ProbePosition.X), THEO_X, 0) retval = vpcDMIS_CmdIn.PutText(CStr(MA.ProbePosition.Y), THEO_Y, 0) retval = vpcDMIS_CmdIn.PutText(CStr(MA.ProbePosition.Z), THEO_Z, 0) End If ' Delete MOVE_INCREMENT Command retval = vpcDMIS_Cmds.RemoveCommandRange(vpcDMIS_Cmd, vpcDMIS_Cmd) ' set new Execute startpoint after insert iStart_Cmd = iLoopIndex + 1 End If NextLoop: Next iLoopIndex ' --- end ----------------------------------------------------------------------------------------- ErrorHandler: vpcDMIS_Part.RefreshPart vpcDMIS_App.StatusBar = "Script: " & iLoopIndex & " searched commands | " & iChanged & " changed commands" ' --- free something ------------------------------------------------------------------------------ Set MA = Nothing Set ExecDlg = Nothing Set vpcDMIS_Cmd = Nothing Set vpcDMIS_Cmds = Nothing Set vpcDMIS_Part = Nothing Set vpcDMIS_App = Nothing End Sub