hexagon logo

Script for automated csv output

Writing a script to export the feature nominals and actuals to a .csv file. The file will be read back in later in the program to populate the nominal and actuals for Generic points to report from. The .csv file will be serialized for each part so that the data will be retrievable for a partial re-run of reworked surfaces. Instead of renspecting the whole part, the csv file will contain all of the previous data for repopulating the generic points.

Having great success up to a point. I have the feature ID's in the csv file but I cannot figure out the right code to write the nominals and actuals into the file. This is a work in progress and some of the lines are commented out. I want to start with nominal X in the B column of the file and end with the actual K vectors in the N column. Just can't figure out the right code to start writing the hit data. Everything else is working great.

'Declares the File System Object And Instantiates it
Dim  objFSO
Set  objFSO = CreateObject("Scripting.FileSystemObject")

' PC-DMIS APPLICATION DECLARATIONS
Dim  PCDApp As Object
Set PCDApp = CreateObject("PCDLRN.Application")
Dim  PRG As Object
Set  PRG = PCDApp.ActivePartProgram
Dim Cmds As Object
Set Cmds = PRG.Commands
Dim Cmd As Object
Dim DCmd As Object
Dim  CCmd As Object
Dim   DCmdID As Object

'VARIABLES FROM THE PART PROGRAM For FILE SAVE And EXCEL FILE HEADER
Dim VPART As Object 
Set VPART = PRG.GetVariableValue("VPART")

Dim VDESCRIPTION As Object
Set VDESCRIPTION = PRG.GetVariableValue("VDESCRIPTION")

Dim VSERIALNUMBER As Object
Set VSERIALNUMBER = PRG.GetVariableValue("VSERIALNUMBER")

Dim  VSRLFLDRPATH As Object
Set  VSRLFDRPATH = PRG.GetVariableValue("VSRLFLDRPATH")


'EXCEL APPLICATION DECLARATIONS
Dim Xcl As Object
Set Xcl = CreateObject("Excel.Application") 
Dim Xclwrkbks As Object
Dim  Xclwrkbk As Object
Dim Xclsht  As Object
Dim  count As Integer

Set  Xclwrkbks = Xcl.Workbooks
Set  Xclwrkbk = Xcl.Workbooks.Open("D:\CMM_PROGRAMS\PC-DMIS_SUPPORT_FILES\EXCEL_FILES\TEMPLATE.csv")
Set  Xclsht = Xclwrkbk.Worksheets("TEMPLATE")


'EXCEL SHEET HEADER
Xclsht.Range("A2").Value = "Part Number"
Xclsht.Range("A3").Value = "Description"
Xclsht.Range("A4").Value = "Serial #"
Xclsht.Range("B2").Value = VPART.StringValue
Xclsht.Range("B3").Value = VDESCRIPTION.StringValue
Xclsht.Range("B4").Value = VSERIALNUMBER.StringValue
count = 7

Xclsht.Range("A7").Value = "FeatureName"
Xclsht.Range("B7").Value = "Nominal X"
Xclsht.Range("C7").Value = "Nominal Y"
Xclsht.Range("D7").Value = "Nominal Z"
Xclsht.Range("E7").Value = "Nominal I"
Xclsht.Range("F7").Value = "Nominal J"
Xclsht.Range("G7").Value = "Nominal K"

Xclsht.Range("I7").Value = "Measured X"
Xclsht.Range("J7").Value = "Measured Y"
Xclsht.Range("K7").Value = "Measured Z"
Xclsht.Range("L7").Value = "Measured I"
Xclsht.Range("M7").Value = "Measured J"
Xclsht.Range("N7").Value = "Measured K"


Dim FCmd As Object

   For Each Cmd In Cmds

    If Cmd.IsFeature Then

    Dim  Fcntr As Integer
    
    count = count + 1

    Set FCmd = Cmd.FeatureCommand
    FeatureList(Fcntr) = FCmd.ID 
    Fcntr = Fcntr + 1 
Set  PRBHIT = CreateObject("PCDLRN.PointData")

   'Set PRBHIT = FCmd.GetHit (Fcntr, FHITDATA_CENTROID, FDATA_THEO, FDATA_PART, AlignID, PLANE_TOP)
   'Set PRBHIT = FCmd.GetHit (Fcntr, FHITDATA_CENTROID, FDATA_MEAS, FDATA_PART, AlignID, PLANE_TOP)
   'Set PRBHIT = FCmd.GetHit (Fcntr, FHITDATA_VECTOR, FDATA_THEO, FDATA_PART, AlignID, PLANE_TOP)


     Xclsht.Range("A" & count).Value = FCmd.ID

'Script is correct up To this point
     Xclsht.Range("B" & count).Value = FCmd.TX


Xcl.Visible=True

End If

Next
Parents Reply Children
No Data