hexagon logo

Script help needed - export point data to txt file

I have a program that measures 700+ points on an airfoil surface. I'm looking for an easy way to export the nominal and measured values into a txt file as feature name, X nom, Y nom, Z nom, X meas, Y meas, Z meas, X dev, Y dev, Z dev. I'm currently programming to put the values into an array and write to a file after every point measurement.

It would obviously be easier to have a script that would look for all feature names in a certain format, i.e. PNT_1, PNT_2, etc, write the data to a file, then look for the next feature. I wasn't planning on dimensioning any of the points but will if I have to. If someone can point me in the right direction I would greatly appreciate it.
  • Did you try to Export - Generic? Is that format good for you?

    Its not a script, but if that format works, I do believe its easy enough to automate it.
  • It's close. Actually Export - XYZ is closer but I need nominal, measured, and deviations without IJK's. And I'm looking to automate this at the end of program execution.

    I'm working on modifying a script I found here but am stuck on a couple things. First, how do I get the values I want without a DIM command? I can DIM each point but trying to keep the program size down. Second, how do I get data formatted onto one line per point instead of one line for each piece of information per point?
  • You parse the program for certain "knowns" and when these "knowns" are found, you fetch the data you want, concatenate these into a string and print the string to a file.
    That's the pseudocode for it.

    Are you using a certain naming scheme for the points carrying the data you need?
  • Ok, this is a deadlisting I just made - with deadlisting I mean that I have typed without syntax check and without a compiler to test it.
    In other words, coded in Notepad @ home = run it at your own risk.

    ' vpt.se in 2013
    
    Sub Main
    Dim PCDApp, PCDPartPrograms, PCDPartProgram, PCDCommands, PCDCommand
    Dim tX, tY, tZ, mX, mY, mZ As String
    
    Set PCDApp = CreateObject("PCDLRN.Application")
    Set PCDPartPrograms = PCDApp.PartPrograms
    Set PCDPartProgram = PCDApp.ActivePartProgram
    Set PCDCommands = PCDPartProgram.Commands
    
    Dim iCnt as integer
    
    Open PCDPartProgram.Path & "POINTDATA.TXT" For Append As #1
    For iCnt = 1 To PCDCommands.Count
    Set PCDCommand = PCDCommands.Item(iCnt)
    
    If Left(PCDCommand.ID, 3) = "PNT" Then
    
      tX = PCDCommand.GetText(THEO_X, 0)
      tY = PCDCommand.GetText(THEO_Y, 0)
      tZ = PCDCommand.GetText(THEO_Z, 0)
      
      mX = PCDCommand.GetText(MEAS_X, 0)
      mY = PCDCommand.GetText(MEAS_Y, 0)
      mZ = PCDCommand.GetText(MEAS_Z, 0)
      
      Write #1, PCDCommand.ID & " " & tX & " " & tY & " " & tZ & " " & mX & " " & mY & " " & mZ
    
    End If
    
    Next iCnt
    
    Close #1
    Set PCDCommands = Nothing
    Set PCDPartProgram = Nothing
    Set PCDPartPrograms = Nothing
    Set PCDApp = Nothing
    End Sub


    It will look for features where the feature name begins with PNT. If a feature is found, the ID and theo X, Y, Z and meas X, Y and Z will be saved to a file called POINTDATA.TXT in the same folder as the current partprogram.
    The file is appended everytime the script is run, which means it will add to the textfile. If you want the deviation, you'll have to add that calculation to the script.

    Hopefully it will work, if it doesn't it will give you a nice foundation to build on.
  • Thank you vpt.se, worked as advertised!

    Now I'm working with the script to customize the location and filename of the output file. I'm trying to pass variable values back to the script for use in the filename. I've added the following:

    Dim txtPartNumber As Object
    Dim txtSerialNumber As Object
    
    Set txtPartNumber = PCDPartProgram.GetVariableValue ("V_PARTNUMBER")  
    Set txtSerialNumber = PCDPartProgram.GetVariableValue ("V_SERIALNUMBER")
    
    Dim strFile As String
          strFile = txtPartName.StringValue & "_" & txtSerialNumber.StringValue & "_" & "POINTDATA.TXT" 
    
    Open "J:\Quality\Enginetics Part Numbers\5000 - 5999\5313057SK01\CMM Reports\" & strFile For Append As #1
    



    The variable V_PARTNUMBER is set using an "ASSIGN" command and V_SERIALNUMBER is assigned from a user input comment command. The problem is the filename ends up being "__POINTDATA.TXT". It's supposed to be "PARTNUMBER_SERIALNUMBER_POINTDATA.TXT" but the variable values are not being passed back. What am I doing wrong?

    As a side note, the output file included "" around each data line. I changed the WRITE command to PRINT and the "" marks disappeared. Just a formatting preference I guess.
  • Great! Lucky me (and you) Stuck out tongue closed eyes

    Tried removing the ".StringValue" and just use the variable name?
  • Well, it turns out everything is working correctly. I could tell the variables had data assigned within the edit window but just running the script within the script editor wasn't showing and variable data. I had to run the actual program to get the variables to pass, not sure why. Anyway, I'm up and running and making modifications to the script as I go. Thanks again!