VB Script - Import XYZ Points from external source

VB Script - Import XYZ Points from external source

CMM-Manager has built-in Import Points Operation to import point data from an external source such as 3rd party metrology software. Maybe this 3rd party system lacks CAD and reporting capabilities needed for the current task... If so, import your point and CAD data to CMM-Manager and perform Alignment, Feature constructions, Best-Fitting, Reporting, etc. 

Point data format can vary to some extent... For example, both formats shown below are acceptable. Typically the data should be comma delimited and could contain Point Name, X, Y, Z, I, J, K. The Point Name should start with an alpha character, afterwords CMM-Manager automatically detects XYZ / IJK data.

Quote
//----------------------------------------------------------
// name: CAD_CLOUD < total_points: 2205 >
// probe radius: 0.0000000
//----------------------------------------------------------
// X Y Z
//----------------------------------------------------------
1.7131581, 0.0000000, -67.0721419
5.2486686, 0.0000000, -70.6076524
8.7841529, 0.0000000, -74.1431367
9.1457864, 0.0000000, -74.5047703
9.0714713, 1.7695448, -76.2000000

Or this...
Quote
Feature,CAD_CLOUD
RefFrame,Use Current
Data#,2205
Probe Diameter,0.00000
, X, Y, Z
P1,1.71316,0.00000,-67.07214
P2,5.24867,0.00000,-70.60765
P3,8.78415,0.00000,-74.14314
P4,9.14579,0.00000,-74.50477
P5,9.07147,1.76954,-76.20000

Unfortunately, the data coming from Automeasure software is a bit strange since it contains a Point label that only includes Numeric text, thus confusing the CMM-Manager import mechanism that is trying to automatically distinguish a difference between numeric point data and alpha-numeric point labels. Automeasure file looks something like this:
Quote
1,1.71316,0,-67.07214
2,5.24867,0,-70.60765
3,8.78415,0,-74.14314
4,9.14579,0,-74.50477
5,9.07147,1.76954,-76.2
6,5.53587,5.30515,-76.2
7,2.00038,8.84064,-76.2

Now we use VBScript to Read, edit, and then re-write the file from Automeasure to be usable in CMM-Manager. In summary, this Script prompts the user for an input file, reads the input file, removes blank lines, ignores lines that start with "//", and then writes each line to a new file while adding "P" to the Point Label. Here is the script:

CODE: 

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWShell = CreateObject("WScript.Shell")
Set ChooseFile = objWShell.Exec( "mshta.exe ""about: <input type=file id=X><script>X.click();new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).WriteLine(X.value);close();resizeTo(0,0);</script>""" )
MyFile = ChooseFile.StdOut.ReadAll

'strip out Carriage Return
ChrPos = InStr(MyFile, Chr(13))
ChrPos = ChrPos -1
MyFile = Left(MyFile, ChrPos)

'Create file for writing
MyFileOut = "C:\ProgramData\QxSoft\xyz_data_file.dat"
Set objFileOut = objFSO.CreateTextFile(MyFileOut)

' Open file and read all lines
Set objFile = objFSO.OpenTextFile(MyFile, 1)
i = 0
Do While objFile.AtEndOfStream = False
MyLine = objFile.ReadLine
If Left(MyLine, 2) = "//" Then
Else
MyLine = "P" + CStr(MyLine)
objFileOut.WriteLine(MyLine)
i = i + 1
End If
Loop
objFile.Close 'close input file
objFileOut.Close 'close output file
When you run the CMM-Manager program, you will see the standard Windows file selection dialog, like this:

Once the script runs, you should see points imported automatically. The remaining program could include Alignment, Feature Constructions, Reporting, etc. It is typical to use CAD for Best-Fitting and Comparison in these cases. See attached example file including Automeasure XYZ Point data file.