hexagon logo

Another Excel Script Problem

Hey, guys. Trying to make an excel script to output the dimensions that appear on the report. We have several that are not shown on the report that are used in the code for logic purposes.

Problem in code is where the xlsht.Range("D" + Count) = Nominal
code starts. No matter what I put after the equal sign, I get an OLE error.

The other "xlsht.Range" commands in the code work fine.

Suggestions?

xlsht.Range("D" + Count) = Nominal

Sub Main

'Excel Declarations
       Dim xlApp As Object
       Dim xlwrkbks As Object
       Dim xlwrkbk As Object
       Dim xlsht As Object
       Dim Count As Integer


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






        'Variables From Part Program
        Dim VPART, VSERIALNUMBER, VPROGRAMID, VDATE, VTIME, VDESCRIPTION, VCMMOPERATOR, VLOCALCSV As Object
        Dim VREV As Object

        Set VREV = Part.GetVariableValue("VREV")
        Set VPART = Part.GetVariableValue("VPART")
        Set VDESCRIPTION = Part.GetVariableValue("VDESCRIPTION")
        Set VSERIALNUMBER = Part.GetVariableValue("VSERIALNUMBER")
        Set VPROGRAMID = Part.GetVariableValue("VPROGRAMID")
        Set VDATE = Part.GetVariableValue("VDATE")
        Set VTIME = Part.GetVariableValue("VTIME")
        Set VCMMOPERATOR = Part.GetVariableValue("VCMMOPERATOR")
        Set VLOCALCSV = Part.GetVariableValue("VLOCALCSV")

        'Open Excel And Template File
        Set xlApp = CreateObject("Excel.Application")
        Set xlwrkbks = xlApp.Workbooks
        Set xlwrkbk = xlApp.Workbooks.Open("D:\CMM_PROGRAMS\PC-DMIS_SUPPORT_FILES\EXCEL_FILES\TEMPLATE.CSV")
        Set xlsht = xlwrkbk.Worksheets("TEMPLATE")


        'EXCEL SHEET HEADER INFO
        xlsht.Range("A2").Value = "GE Aviation Batesville Composites Operation"
        xlsht.Range("A3").Value = "Part # :"
        xlsht.Range("A4").Value = "Date :"
        xlsht.Range("A5").Value = "Description :"
        xlsht.Range("A6").Value = "Serial # :"
        xlsht.Range("A7").Value = "Operator :"
        xlsht.Range("A8").Value = "Rev:"

        xlsht.Range("C3").Value = VPART.StringValue
        xlsht.Range("C4").Value = VDATE.StringValue
        xlsht.Range("C5").Value = VDESCRIPTION.StringValue
        xlsht.Range("C6").Value = VSERIALNUMBER.StringValue
        xlsht.Range("C7").Value = VCMMOPERATOR.StringValue
        xlsht.Range("C8").Value = VREV.StringValue

        xlsht.Range("A11").Value = "Dimension Name"
        xlsht.Range("D11").Value = "Nominal"
        xlsht.Range("E11").Value = "+TOL"
        xlsht.Range("F11").Value = "-TOL"
        xlsht.Range("G11").Value = "Measured"
        xlsht.Range("H11").Value = "MAX"
        xlsht.Range("I11").Value = "MIN"
        xlsht.Range("J11").Value = "Deviation"
        xlsht.Range("K11").Value = "OOT"
        xlsht.Range("L11").Value = "Bonus Tol"




        Count = Count + 1



       For Each Cmd In Cmds

            If Cmd.IsDimension Then

                Set DCmd = Cmd.DimensionCommand
                Set DCmdID = DCmd.ID

                If Not DCmd.OutputMode = "None" Then

                   xlsht.Range("D" + Count) = Nominal

                End If
            End If

        Next Cmd


        xlApp.Visible = True



End Sub
Parents
  • Working pretty good now except that it is only outputting postion and location dimensions. I added a case for profiles with the same format as AndersI and it is not outputting the profile data.

    Not sure what is happening. Not much experience with Select Case Statements.


    Dim elType As String
    Dim elName As String
    Dim elValueType As String
    Dim elAct As Double
    Dim elNom As Double
    Dim elDev As Double
    Dim elMtol As Double
    Dim elPtol As Double
    Dim elOutTol As Double
    Dim elMax As Double
    Dim elMin As Double
    Dim elBTol As Double
    Dim elComment As String
    Dim elStarted As Integer
    
    ' ================================================================
    
    Sub ClearRecord
      elType = "type"
      elName = "name"
      elValueType = "valuetype"
      elAct = 0
      elNom = 0
      elDev = 0
      elMax = 0
      elMin = 0
      elMtol = 0
      elPtol = 0
      elOutTol = 0
      elBTol = ""
    End Sub
    
    Sub PrintLine(FileNum%)
      If elStarted Then
        Print #FileNum, elName; ","; elType; ","; elValueType; ","; elNom; ","; elPtol; ","; elMtol; "," ; elAct; ","; elMax; ","; elMin; ","; elDev; ","; elOutTol; ","; elBTol
        elStarted = 0
      End If
    End Sub
    
    Sub ExportAsCSV(FileName$)
    
    Dim DmisApp As Object
    Dim DmisPart As Object
    Dim DmisCommands As Object
    Dim DmisCommand As Object
    Dim DmisDimension As Object
    
      Dim ix As Integer
      Dim fNum As Integer
      Dim ID As String
      Dim State As Integer
      Dim DoOutput As Integer
    
      Set DmisApp = CreateObject("PCDLRN.Application")
      Set DmisPart = DmisApp.ActivePartProgram
      Set DmisCommands = DmisPart.Commands
    
      Dim VPART, VDESCRIPTION, VSERIALNUMBER, VDATE, VCMMOPERATOR As Object
    
      Set VPART = DmisPart.GetVariableValue("VPART")
      Set VDESCRIPTION = DmisPart.GetVariableValue("VDESCRIPTION")
      Set VSERIALNUMBER = DmisPart.GetVariableValue("VSERIALNUMBER")
      Set VDATE = DmisPart.GetVariableValue("VDATE")
      Set VCMMOPERATOR = DmisPart.GetVariableValue("VCMMOPERATOR")
    
    
      fNum = FreeFile
      Open FileName$ For Output As fNum
      ' 2005-11-17
      Print #fNum, "Company Name"
      Print #fNum, ""
      Print #fNum, "Part #:"; ","; VPART.StringValue
      Print #fNum, "Serial #:"; ","; VSERIALNUMBER.StringValue
      Print #fNum, "Description:"; ","; VDESCRIPTION.StringValue
      Print #fNum, "Date:"; ","; VDATE.StringValue
      Print #fNum, "CMM Operator:"; ","; VCMMOPERATOR.StringValue
    
      
      Print #fNum, ""
      Print #fNum, " Dimension Name,Dimension Type,Axis,Nominal,(+)Tol,(-)Tol,Measured,Max,Min,Dev,OutTol,BonusTol"
      Print #fNum, ""
      
    
      elStarted = 0
      State = 1
    
      For Each DmisCommand In DmisCommands
    
        
    
        If DmisCommand.IsDimension Then
    
          Set DmisDimension = DmisCommand.DimensionCommand
    
                If (DmisDimension.OutputMode <> DIMOUTPUT_NONE) Then
                  DoOutput = 1
                Else
                  DoOutput = 0
                End If
    
    
                  If (DmisCommand.Type = DIMENSION_TRUE_START_POSITION) Then
                  State = 2
                  ElseIf (DmisCommand.Type = DIMENSION_START_LOCATION) Then
                  State = 3
                  ElseIf (DmisCommand.Type = DIMENSION_PROFILE)  Then
                  State =4
                
                  End If
    
          Select Case State
    
            Case 1 '  Normal Case
    
                ID = DmisDimension.ID
    
               
    
                If (DoOutput = 1) And (State = 1) Then
    
                If (DmisDimension.OutputMode <> DIMOUTPUT_NONE) Then
                  DoOutput = 1
                Else
                  DoOutput = 0
                End If
    
    
                  PrintLine(fNum)
                  ClearRecord
                  elType = DmisCommand.TypeDescription
                  elName = ID
                  ' 2005-11-17
                  If DmisDimension.AxisLetter = "D" Then
                      elValueType = "DIAM"
                  Elseif DmisDimension.AxisLetter = "R" Then
                      elValueType = "RAD"
                  Else
                    elValueType = DmisDimension.AxisLetter
                  End If
                  ' ---------
                  elNom = DmisDimension.Nominal
                  ' 2005-11-16
                  If (Abs(DmisDimension.Deviation) > 0.00009) Then
    	              elDev = DmisDimension.Deviation
                  Else
                  	elDev = 0
                  End If
                  elAct = DmisDimension.Nominal + elDev
                  ' ---------
                  elMtol = -DmisDimension.Minus
                  elPtol = DmisDimension.Plus
                  ' 2005-11-16
                  If (Abs(DmisDimension.OutTol) > 0.00009) Then
    	              elOutTol = DmisDimension.OutTol
                  Else
                  	elOutTol = 0
                  End If
                  ' ---------
                  
                   elMax = ""
                  elMin = ""
    
                  If (Abs(DmisDimension.Bonus) > .00009) Then
                             elBTol = DmisDimension.Bonus
                  Else
                            elBTol = 0
                  End If 
    
    
                  elStarted = 1
    
                End If
    
            Case 2 '  True Position
    
                If (DoOutput = 1)  And (State =2) Then
    
                If (DmisDimension.OutputMode <> DIMOUTPUT_NONE) Then
                  DoOutput = 1
                Else
                  DoOutput = 0
                End If
    
    
    
                  PrintLine(fNum)
                  ClearRecord
                  elType = DmisCommand.TypeDescription
                  elName = ID
                  ' 2005-11-17
                  If DmisDimension.AxisLetter = "D" Then
                      elValueType = "DIAM"
                  ElseIf DmisDimension.AxisLetter = "R" Then
                      elValueType = "RAD"
                  Else
                    elValueType = DmisDimension.AxisLetter
                  End If
                  ' ---------
                  elNom = DmisDimension.Nominal
                  ' 2005-11-16
                  If (Abs(DmisDimension.Deviation) > 0.00009) Then
    	              elDev = DmisDimension.Deviation
                  Else
                  	elDev = 0
                  End If
                  elAct = DmisDimension.Nominal + elDev
                  ' ---------
                  elMtol = -DmisDimension.Minus
                  elPtol = DmisDimension.Plus
                  ' 2005-11-16
                  If (Abs(DmisDimension.OutTol) > 0.00009) Then
    	              elOutTol = DmisDimension.OutTol
                  Else
                  	elOutTol = 0
                  End If
                  ' ---------
                  elMax = ""
                  elMin = ""
    
                  If (Abs(DmisDimension.Bonus) > .00009) Then
                             elBTol = DmisDimension.Bonus
                  Else
                            elBTol = 0
                  End If 
    
    
                  elStarted = 1
                End If
    
    
Reply
  • Working pretty good now except that it is only outputting postion and location dimensions. I added a case for profiles with the same format as AndersI and it is not outputting the profile data.

    Not sure what is happening. Not much experience with Select Case Statements.


    Dim elType As String
    Dim elName As String
    Dim elValueType As String
    Dim elAct As Double
    Dim elNom As Double
    Dim elDev As Double
    Dim elMtol As Double
    Dim elPtol As Double
    Dim elOutTol As Double
    Dim elMax As Double
    Dim elMin As Double
    Dim elBTol As Double
    Dim elComment As String
    Dim elStarted As Integer
    
    ' ================================================================
    
    Sub ClearRecord
      elType = "type"
      elName = "name"
      elValueType = "valuetype"
      elAct = 0
      elNom = 0
      elDev = 0
      elMax = 0
      elMin = 0
      elMtol = 0
      elPtol = 0
      elOutTol = 0
      elBTol = ""
    End Sub
    
    Sub PrintLine(FileNum%)
      If elStarted Then
        Print #FileNum, elName; ","; elType; ","; elValueType; ","; elNom; ","; elPtol; ","; elMtol; "," ; elAct; ","; elMax; ","; elMin; ","; elDev; ","; elOutTol; ","; elBTol
        elStarted = 0
      End If
    End Sub
    
    Sub ExportAsCSV(FileName$)
    
    Dim DmisApp As Object
    Dim DmisPart As Object
    Dim DmisCommands As Object
    Dim DmisCommand As Object
    Dim DmisDimension As Object
    
      Dim ix As Integer
      Dim fNum As Integer
      Dim ID As String
      Dim State As Integer
      Dim DoOutput As Integer
    
      Set DmisApp = CreateObject("PCDLRN.Application")
      Set DmisPart = DmisApp.ActivePartProgram
      Set DmisCommands = DmisPart.Commands
    
      Dim VPART, VDESCRIPTION, VSERIALNUMBER, VDATE, VCMMOPERATOR As Object
    
      Set VPART = DmisPart.GetVariableValue("VPART")
      Set VDESCRIPTION = DmisPart.GetVariableValue("VDESCRIPTION")
      Set VSERIALNUMBER = DmisPart.GetVariableValue("VSERIALNUMBER")
      Set VDATE = DmisPart.GetVariableValue("VDATE")
      Set VCMMOPERATOR = DmisPart.GetVariableValue("VCMMOPERATOR")
    
    
      fNum = FreeFile
      Open FileName$ For Output As fNum
      ' 2005-11-17
      Print #fNum, "Company Name"
      Print #fNum, ""
      Print #fNum, "Part #:"; ","; VPART.StringValue
      Print #fNum, "Serial #:"; ","; VSERIALNUMBER.StringValue
      Print #fNum, "Description:"; ","; VDESCRIPTION.StringValue
      Print #fNum, "Date:"; ","; VDATE.StringValue
      Print #fNum, "CMM Operator:"; ","; VCMMOPERATOR.StringValue
    
      
      Print #fNum, ""
      Print #fNum, " Dimension Name,Dimension Type,Axis,Nominal,(+)Tol,(-)Tol,Measured,Max,Min,Dev,OutTol,BonusTol"
      Print #fNum, ""
      
    
      elStarted = 0
      State = 1
    
      For Each DmisCommand In DmisCommands
    
        
    
        If DmisCommand.IsDimension Then
    
          Set DmisDimension = DmisCommand.DimensionCommand
    
                If (DmisDimension.OutputMode <> DIMOUTPUT_NONE) Then
                  DoOutput = 1
                Else
                  DoOutput = 0
                End If
    
    
                  If (DmisCommand.Type = DIMENSION_TRUE_START_POSITION) Then
                  State = 2
                  ElseIf (DmisCommand.Type = DIMENSION_START_LOCATION) Then
                  State = 3
                  ElseIf (DmisCommand.Type = DIMENSION_PROFILE)  Then
                  State =4
                
                  End If
    
          Select Case State
    
            Case 1 '  Normal Case
    
                ID = DmisDimension.ID
    
               
    
                If (DoOutput = 1) And (State = 1) Then
    
                If (DmisDimension.OutputMode <> DIMOUTPUT_NONE) Then
                  DoOutput = 1
                Else
                  DoOutput = 0
                End If
    
    
                  PrintLine(fNum)
                  ClearRecord
                  elType = DmisCommand.TypeDescription
                  elName = ID
                  ' 2005-11-17
                  If DmisDimension.AxisLetter = "D" Then
                      elValueType = "DIAM"
                  Elseif DmisDimension.AxisLetter = "R" Then
                      elValueType = "RAD"
                  Else
                    elValueType = DmisDimension.AxisLetter
                  End If
                  ' ---------
                  elNom = DmisDimension.Nominal
                  ' 2005-11-16
                  If (Abs(DmisDimension.Deviation) > 0.00009) Then
    	              elDev = DmisDimension.Deviation
                  Else
                  	elDev = 0
                  End If
                  elAct = DmisDimension.Nominal + elDev
                  ' ---------
                  elMtol = -DmisDimension.Minus
                  elPtol = DmisDimension.Plus
                  ' 2005-11-16
                  If (Abs(DmisDimension.OutTol) > 0.00009) Then
    	              elOutTol = DmisDimension.OutTol
                  Else
                  	elOutTol = 0
                  End If
                  ' ---------
                  
                   elMax = ""
                  elMin = ""
    
                  If (Abs(DmisDimension.Bonus) > .00009) Then
                             elBTol = DmisDimension.Bonus
                  Else
                            elBTol = 0
                  End If 
    
    
                  elStarted = 1
    
                End If
    
            Case 2 '  True Position
    
                If (DoOutput = 1)  And (State =2) Then
    
                If (DmisDimension.OutputMode <> DIMOUTPUT_NONE) Then
                  DoOutput = 1
                Else
                  DoOutput = 0
                End If
    
    
    
                  PrintLine(fNum)
                  ClearRecord
                  elType = DmisCommand.TypeDescription
                  elName = ID
                  ' 2005-11-17
                  If DmisDimension.AxisLetter = "D" Then
                      elValueType = "DIAM"
                  ElseIf DmisDimension.AxisLetter = "R" Then
                      elValueType = "RAD"
                  Else
                    elValueType = DmisDimension.AxisLetter
                  End If
                  ' ---------
                  elNom = DmisDimension.Nominal
                  ' 2005-11-16
                  If (Abs(DmisDimension.Deviation) > 0.00009) Then
    	              elDev = DmisDimension.Deviation
                  Else
                  	elDev = 0
                  End If
                  elAct = DmisDimension.Nominal + elDev
                  ' ---------
                  elMtol = -DmisDimension.Minus
                  elPtol = DmisDimension.Plus
                  ' 2005-11-16
                  If (Abs(DmisDimension.OutTol) > 0.00009) Then
    	              elOutTol = DmisDimension.OutTol
                  Else
                  	elOutTol = 0
                  End If
                  ' ---------
                  elMax = ""
                  elMin = ""
    
                  If (Abs(DmisDimension.Bonus) > .00009) Then
                             elBTol = DmisDimension.Bonus
                  Else
                            elBTol = 0
                  End If 
    
    
                  elStarted = 1
                End If
    
    
Children
No Data