Create custom text file / report output

Post Reply
User avatar
US_Helpdesk
Moderator
Moderator
Posts: 1089
Joined: Wed Feb 23, 2011 7:26 pm

Create custom text file / report output

Post by US_Helpdesk » Wed Dec 04, 2013 5:23 pm

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.

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.

Code: Select all

NumPorts = InputBox("How many port locations?")
MyTLO = InputBox("Please enter Tool Length Offset")

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

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

Code: Select all

For i = 1 to NumPorts

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

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

X = Round(GetReportInfo("POINT2", "X", 2), myPrec)
Y = Round(GetReportInfo("POINT2", "Y", 2), myPrec)
Z = Round(GetReportInfo("POINT2", "Z", 2), myPrec)

filetxt.WriteLine("LOAD_" & MyPort & ".BEF")
filetxt.WriteLine("$LOAD_" & MyPort & "[1]=COORSYS=DX=" & DX & ";DZ=" & DZ & ";NZ=" & NZ & ";")
filetxt.WriteLine("$LOAD_" & MyPort & "[2]=MOVZERO=X=" & X & ";Y=" & Y & ";Z=" & Z)
filetxt.WriteLine("$LOAD_" & MyPort & "[3]=VAR $Tlc=" & MyTLO)
If i <> NumPorts Then
filetxt.WriteLine("")
End If

Next

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
You do not have the required permissions to view the files attached to this post.
I've migrated to a new user account, see my other posts here

Martin
Regular User
Regular User
Posts: 20
Joined: Sat May 02, 2015 10:25 am

Re: Create custom text file / report output

Post by Martin » Thu Aug 27, 2015 8:20 pm

Hello,

I am not allowed to open this file using software Notepad. I tried to use Ultimate file opener and hotdocs, which are recommended by internet, but i still could not open this attachment.

It is highly appreciated if somebody has solution.

Tabor
Super User
Super User
Posts: 175
Joined: Thu Dec 20, 2012 3:43 pm

Re: Create custom text file / report output

Post by Tabor » Fri Aug 28, 2015 10:03 am

Right click on the file, choose "Open With", and choose Notepad.
Tabor

Martin
Regular User
Regular User
Posts: 20
Joined: Sat May 02, 2015 10:25 am

Re: Create custom text file / report output

Post by Martin » Sat Aug 29, 2015 8:19 am

It is still miscoded after following above instruction.

User avatar
US_Helpdesk
Moderator
Moderator
Posts: 1089
Joined: Wed Feb 23, 2011 7:26 pm

Re: Create custom text file / report output

Post by US_Helpdesk » Mon Aug 31, 2015 11:52 am

Could be encoding settings.... Is your file saved as ANSI or Unicode .txt file?
I've migrated to a new user account, see my other posts here

jswope
Super User
Super User
Posts: 176
Joined: Fri May 17, 2013 12:50 pm

Re: Create custom text file / report output

Post by jswope » Thu Jan 31, 2019 12:03 pm

Is there a way to continue adding text instead of overwriting the data in the text file?

User avatar
CrashN8
Site Admin
Site Admin
Posts: 447
Joined: Thu Feb 09, 2017 4:07 pm

Re: Create custom text file / report output

Post by CrashN8 » Thu Jan 31, 2019 1:55 pm

  • Check if file exists using FSO.FileExists()
  • Open File instead of Create File using FSO.OpenTextFile()
  • Then depending on whether file exists or not use FSO.OpenTextFile() to open for either writing or for appending.
Details for OpenTextFile() Method here - https://www.w3schools.com/asp/met_opentextfile.asp

Code: Select all

NumPorts = InputBox("How many port locations?")
MyTLO = InputBox("Please enter Tool Length Offset")
myPrec = 4  'Change the myPrec value to adjust how many digits are reported.

Set filesys = CreateObject("Scripting.FileSystemObject")
If filesys.FileExists("c:\CMM-Manager\OFFSET.DAT") Then
   Set filetxt = filesys.OpenTextFile("c:\CMM-Manager\OFFSET.DAT", 8)
Else
   Set filetxt = filesys.OpenTextFile("c:\CMM-Manager\OFFSET.DAT", 2,True)
End If
path = filesys.GetAbsolutePathName("c:\CMM-Manager\OFFSET.DAT")
getname = filesys.GetFileName(path)

Post Reply