CMM-Manager - VB Script - Create custom text / report file

VB Script - Create custom text / report file

With VB Scripting it is possible to read / write text files to / from the CMM-Manager program. This could be useful for reading data from an external source or for writing custom reports or sending data to a third party or even a machine tool. This is not limited to simple text files, but could also include Windows Registry, SQL database, Excel spreadsheets, etc.

Learn more about sharing this file with your Haas, Fanuc, or other CNC milling center - Establishing an SMB share between a CNC controller and a Windows PC

Here is a VB Script that writes a file that is accepted by a CNC machine tool for setting Tool Length Offset, XYZ and rotation offsets for multiple parts.
  1. NumPorts = InputBox("How many port locations?")
  2. MyTLO = InputBox("Please enter Tool Length Offset")

  3. 'Change the myPrec value to adjust how many digits are reported.
  4. myPrec = 4

  5. Set filesys = CreateObject("Scripting.FileSystemObject")
  6. Set filetxt = filesys.CreateTextFile("c:\CMM-Manager\OFFSET.DAT", True)
  7. path = filesys.GetAbsolutePathName("c:\CMM-Manager\OFFSET.DAT")
  8. getname = filesys.GetFileName(path)

  9. For i = 1 to NumPorts

  1. MyPort = InputBox("Please enter pallet port number")

  2. DX = Round(GetReportInfo("ANGL BT LINE2 and Z AXIS", "YZ", 2), myPrec)
  3. DZ = Round(GetReportInfo("ANGL BT LINE2 and Z AXIS", "ZX", 2), myPrec)
  4. NZ = Round(GetReportInfo("ANGL BT LINE1 and X AXIS", "XY", 2), myPrec)

  5. X = Round(GetReportInfo("POINT2", "X", 2), myPrec)
  6. Y = Round(GetReportInfo("POINT2", "Y", 2), myPrec)
  7. Z = Round(GetReportInfo("POINT2", "Z", 2), myPrec)

  8. filetxt.WriteLine("LOAD_" & MyPort & ".BEF")
  9. filetxt.WriteLine("$LOAD_" & MyPort & "[1]=COORSYS=DX=" & DX & ";DZ=" & DZ & ";NZ=" & NZ & ";")
  10. filetxt.WriteLine("$LOAD_" & MyPort & "[2]=MOVZERO=X=" & X & ";Y=" & Y & ";Z=" & Z)
  11. filetxt.WriteLine("$LOAD_" & MyPort & "[3]=VAR $Tlc=" & MyTLO)

  12. 'On Error Resume Next
  13. 'On Error MsgBox("ERROR")

  14. Next
  15. filetxt.Close

The file output is this...
LOAD_016.BEF
$LOAD_016[1]=COORSYS=DX=0.0264;DZ=0.0392;NZ=0.0182;
$LOAD_016[2]=MOVZERO=X=-103.8971;Y=-174.3916;Z=-288.0937
$LOAD_016[3]=VAR $Tlc=0.0123565

LOAD_020.BEF
$LOAD_020[1]=COORSYS=DX=0.0264;DZ=0.0392;NZ=0.0182;
$LOAD_020[2]=MOVZERO=X=-103.8971;Y=-174.3916;Z=-288.0937
$LOAD_020[3]=VAR $Tlc=0.0123565

LOAD_028.BEF
$LOAD_028[1]=COORSYS=DX=0.0264;DZ=0.0392;NZ=0.0182;
$LOAD_028[2]=MOVZERO=X=-103.8971;Y=-174.3916;Z=-288.0937
$LOAD_028[3]=VAR $Tlc=0.0123565

LOAD_024.BEF
$LOAD_024[1]=COORSYS=DX=0.0264;DZ=0.0392;NZ=0.0182;
$LOAD_024[2]=MOVZERO=X=-103.8971;Y=-174.3916;Z=-288.0937
$LOAD_024[3]=VAR $Tlc=0.0123565