Data from script to dc dmis

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Data from script to dc dmis

    Hello,

    My target is to create unique number for every single report, number should be in a format 00000. Script should read this number from .txt file, then increase by 1 and add text "Report no.: ". Final result should be: like "Report no.: 0015". I have script:

    [Sub Main

    Dim App As Object
    Set App = CreateObject ("PCDLRN.Application")
    Dim Text As String
    Dim Part As Object
    Set Part = App.ActivePartProgram
    Dim RepNo As String
    Dim No As Integer
    Dim V100 As Object
    Set V100 = part.getvariablevalue ("V100")

    Open "X:\CMM_Data\Proven programs\SCRIPT\REPORTNO.txt" For Input As #1
    Do While Not EOF(1)
    Line Input #1, No
    Loop
    Close #1

    No=No+1

    If No>9999Then
    Set Text = "Report no.: "
    End If
    If No>999 Then
    Set Text = "Report no.: 0"
    End If
    If No>99 Then
    Set Text = "Report no.: 00"
    End If
    If No>9 Then
    Set Text = "Report no.: 000"
    End If
    If No<=9 Then
    Set Text = "Report no.: 0000"
    End If
    'MsgBox Text
    'MsgBox No

    RepNo = Text & No

    MsgBox RepNo

    PART.SetVariableValue "V100", RepNo

    Part.RefreshPart


    End Sub]

    This script giving report number which I want but I can't transfer RepNo (report number) to pc dmis, pc dmis showing massage "Runtime error on line: 43 - type mismatch". line 43: "PART.SetVariableValue "V100", RepNo" I did try the way of tries and mistakes but no result achieved. Can please any one tel me what is the problem with this script?


    Code in Pc dmis:
    [ASSIGN/100="REPORT NO.: 0001"
    CS3 =SCRIPT/FILENAME= C:\USERS\DMILIUS\DESKTOP\DELETE\TEST.BAS
    FUNCTION/Main,SHOW=NO,,
    STARTSCRIPT/
    COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,
    V100]

    Regards
    Last edited by Darius11; 02-22-2019, 05:23 AM.

  • #2
    Get/SetVariableValue only works during the execution of the script. If you want to change the actual value of the assignment in your program, you should use PutText instead. That is a little more tedious though, you can find an example of how to utilize that in the source of my "Program Logger" script:

    https://www.pcdmisforum.com/forum/pc...-logger-script
    PC-DMIS CAD++ 2o19 R1

    Comment


    • #3
      That's not what the help says:

      SetVariableValue.PNG
      AndersI
      SW support - Hexagon Metrology Nordic AB

      Comment


      • Darius11
        Darius11 commented
        Editing a comment
        Hi,
        I'm using BASIC "Language Reference Manual" PC-DMIS 3.6, there is the same example as in you post plus this example working well. It working in the way pcdmis-script-pcdmis and with numbers. I need script which should work in the way .txt-script-pcdmis and with string.

    • #4
      You probably have a newer helpfile than my v4.3 BASIC, but this one says:

      ren.JPG

      However, the status of the helpfiles could be the same as with the software itself...

      The only way to find out is to try it out, just to have it not work the same way in the next version *cough* *cough*
      Last edited by vpt.se; 02-25-2019, 01:23 AM.
      PC-DMIS CAD++ 2o19 R1

      Comment


      • Darius11
        Darius11 commented
        Editing a comment
        Thanks for help, I do like your script, I will consider to use it as it is.
        Thanks.

    • #5
      RepNo = Text & No

      MsgBox RepNo

      V100.StringValue = RepNo

      PART.SetVariableValue "V100", V100

      Part.RefreshPart


      Also your logic for the string generation is wrong.

      If No>9999Then
      Set Text = "Report no.: "
      End If
      If No>999 Then
      Set Text = "Report no.: 0"
      End If
      If No>99 Then
      Set Text = "Report no.: 00"
      End If
      If No>9 Then
      Set Text = "Report no.: 000"
      End If
      If No<=9 Then
      Set Text = "Report no.: 0000"
      End If


      You need to reverse the order of the if statements.

      If No<=9 Then
      Set Text = "Report no.: 0000"
      End If
      If No>9 Then
      Set Text = "Report no.: 000"
      End If
      If No>99 Then
      Set Text = "Report no.: 00"
      End If
      If No>999 Then
      Set Text = "Report no.: 0"
      End If
      If No>9999Then
      Set Text = "Report no.: "
      End If



      Automettech - Automated Metrology Technology

      Comment


      • Darius11
        Darius11 commented
        Editing a comment
        Thanks for help,
        By using your first suggestion I did overcome this problem.
        About "logic for the string generation" as i see I'm still struggle to think in more complex way.
        Regards
        Finished code of stage:
        [Sub Main

        Dim App As Object
        Set App = CreateObject ("PCDLRN.Application")
        Dim Text As String
        Dim Part As Object
        Set Part = App.ActivePartProgram
        Dim No As Integer
        Dim V100 As Object
        Set V100 = part.getvariablevalue ("V100")

        Open "X:\CMM_Data\Proven programs\SCRIPT\REPORTNO.txt" For Input As #1
        Do While Not EOF(1)
        Line Input #1, No
        Loop
        Close #1

        No=No+1

        If No>9999Then
        Text = "Report no.: "
        Else
        If No>999 Then
        Text = "Report no.: 0"
        Else
        If No>99 Then
        Text = "Report no.: 00"
        Else
        If No>9 Then
        Text = "Report no.: 000"
        Else
        If No<=9 Then
        Text = "Report no.: 0000"
        End If
        End If
        End If
        End If
        End If

        RepNo = Text & No

        'MsgBox RepNo

        V100.StringValue = RepNo

        PART.SetVariableValue "V100", V100

        Part.RefreshPart
        End Sub]

    • #6
      Hi,

      Other think What I do need is to ensure that when program will be run offline, script should not save number of report to file. I do need insert peace of code which will indicate when script is used in online. I believe that for this purpose should be used GetProgramOption and PCD_ISONLINE but at the moment I have no success. So how I can get 1 if CMM is online and 0 if offline?

      Regards

      Comment


      • #7
        Try PartProgram.ActiveMachine instead - its value is "OFFLINE" when offline and (at least for me) "CMM1" when online.
        AndersI
        SW support - Hexagon Metrology Nordic AB

        Comment


        • vpt.se
          vpt.se commented
          Editing a comment
          Note: the "CMM1" value might be different depending on your language setting.

        • AndersI
          AndersI commented
          Editing a comment
          That's why I added "(at least for me)" in my post. I expect anyone using automation to actively explore the actual values received on their machine(s).
          :-)

        • Darius11
          Darius11 commented
          Editing a comment
          vpt.se,

          You are right, from other hand MsgBox will show exact output of PartProgram.ActiveMachine and by that can be edited code.
          I think when code working but giving unexpected result it is already around 80 percents of result and when code do not work it is barely 20 percents of result.

      • #8
        Hi,

        Next problem which I can't overcome related with ID of dimensions.
        This is piece of code:


        [If Cmd.IsDimension Then
        If Cmd.Type = DIMENSION_START_LOCATION Or _
        Cmd.Type = DIMENSION_TRUE_START_POSITION Then
        Set DcmdID = Cmd.DimensionCommand
        DimType = left(right (DcmdID.ID, 2),1)
        ReportDim = Cmd.GetText ( OUTPUT_TYPE, 0)
        End If
        If Cmd.Type <> DIMENSION_START_LOCATION And _
        Cmd.Type <> DIMENSION_END_LOCATION And _
        Cmd.Type <> DIMENSION_TRUE_START_POSITION And _
        Cmd.Type <> DIMENSION_TRUE_END_POSITION Then
        Set DCmd = Cmd.DimensionCommand
        CheckDim = Cmd.GetText ( OUTPUT_TYPE, 0)
        If CheckDim <> "" Then
        ReportDim = CheckDim
        End If
        If ReportDim = "BOTH" Or ReportDim = "REPORT" Then
        Set DcmdID = Cmd.DimensionCommand
        DimType = right (DcmdID.ID, 1)]



        DcmdID.ID is ID of dimension. In end of ID is letter B, letter R, letter G or no letter and target of above code is to extract B or R or G. Code below should to do actions which depends on letters B R and G from previous piece.

        [ xlSheet.Cells(RCount,2).Value = fncsheet.Round((DCmd.Nominal - DCmd.Minus),RND)
        xlSheet.Cells(RCount,3).Value = fncsheet.Round((DCmd.Nominal + DCmd.Plus),RND)
        If DCmd.Plus <> DCmd.Minus Then
        xlSheet.Cells(RCount,5).Value = fncsheet.Round(DCmd.Nominal,RND) & "+" & fncsheet.Round(DCmd.Plus,RND) & "/-" & fncsheet.Round(DCmd.Minus,RND)
        Else
        xlSheet.Cells(RCount,5).Value = fncsheet.Round(DCmd.Nominal,RND) & "+/-" & fncsheet.Round(DCmd.Plus,RND)
        End If
        If DimType = "B" Then
        xlSheet.Cells(RCount,5).Font.ColorIndex = 32
        xlSheet.Cells(RCount,5).Value = "[" & fncsheet.Round(DCmd.Nominal,RND) & "]" & "+/-" & fncsheet.Round(DCmd.Plus,RND)
        Else
        If DimType = G Then
        xlSheet.Cells(RCount,5).Value = fncsheet.Round(DCmd.Nominal - DCmd.Minus,RND) & "-" & fncsheet.Round((DCmd.Nominal + DCmd.Plus),RND)
        Else
        If DimType = "R" Then
        xlSheet.Cells(RCount,5).Font.ColorIndex = 53
        xlSheet.Cells(RCount,5).Value = "(" & fncsheet.Round(DCmd.Nominal,RND) & ")" & "+/-" & fncsheet.Round(DCmd.Plus,RND)
        Else
        If DCmd.Plus <> DCmd.Minus Then
        xlSheet.Cells(RCount,5).Value = fncsheet.Round(DCmd.Nominal,RND) & "+" & fncsheet.Round(DCmd.Plus,RND) & "/-" & fncsheet.Round(DCmd.Minus,RND)
        End If]


        I'm using two lines (see below) of code to set DcmdiD and extract letter as DimType. I do understand that probably I don't need to use two identical line for the same purpose but It was method of tries and mistakes.

        Set DcmdID = Cmd.DimensionCommand
        DimType = left(right (DcmdID.ID, 2),1)

        Script extracting letters, not returning error, doing actions related with letters and giving result. Letters representing different kind of dimensions:
        [63]+/-0.1
        5.25-5.65
        (73.25)+/-0.15
        73.25+/-0.15
        My problem is that code sometime giving wrong type of dimensions. I would guess that it is because of letters, as example G and "G", G working better than "G". My question is what can I do to ensure that script will always proper read letter and will interpret the same letter as same variable in all script?
        Last edited by Darius11; 03-12-2019, 04:49 AM.

        Comment


        • #9
          Maybe something like this (untested).

          Pseudocode:

          Code:
          Set DcmdID = Cmd.DimensionCommand
          DimType = right (DcmdID.ID, 1)
          if DimType = """ then
            DimType = left(right (DcmdID.ID, 2),1)
          


          Grab the last character in the ID.
          If that character is a " then
          grab the second last character in the ID

          If-then clause depending on what character is in DimType.
          PC-DMIS CAD++ 2o19 R1

          Comment


          • Darius11
            Darius11 commented
            Editing a comment
            if I do understand well, this " mean nothing. If yes then, dimension ID always will be something. From other hand dimension ID can be easy controlled and I can ensure that I will add right letter.
            This suggestion can be used if some programs RGB have as first letter right to left, some programs have RGB as second but problem that script, in some cases, giving wrong interpretation of RGB.

          • vpt.se
            vpt.se commented
            Editing a comment
            You could always grab the last two characters of DimType and look for either R, G or B in both. But these two characters can only have one instance of either R, G or B or the logic will fail.

        • #10
          Originally posted by Darius11 View Post

          Set DcmdID = Cmd.DimensionCommand
          DimType = right (DcmdID.ID, 1)]

          DcmdID.ID is ID of dimension. In end of ID is letter B, letter R, letter G or no letter and target of above code is to extract B or R or G. Code below should to do actions which depends on letters B R and G from previous piece.
          It should be possible to write directly
          Code:
           DimType = Right(Cmd.DimensionCommand.ID, 1),
          but what do you mean by "or no letter" above - that there is nothing there? Doesn't work, as the Right(anything, 1) will always find the last character, and the ID can't be zero characters long.

          Code:
          If DimType = G Then
          This is wrong - you're comparing DimType to the variable G, which is probably not even declared, and certainly has no value assigned to it. To make it impossible to do such mistakes, you begin your script with
          Code:
           Option Explicit
          to get an error message for each undeclared variable/misspelling.


          I think the main problem is that Cmd.DimensionCommand.ID is only valid on single command line dimensions and the DIMENSION_START_xxx commands, not on the subsequent 'real' dimension axis commands that lie between the DIMENSION_START_xxx and DIMENSION_END_xxx.

          In my export script the similar part of code looks as (lots of detail removed…):
          Code:
          State = 1
          
          For ix = 1 To DmisCommands.Count
          
              Set DmisCommand = DmisCommands(ix)
          
              If DmisCommand.IsDimension Then
          
                Skip = FALSE
          
                Set DmisDimension = DmisCommand.DimensionCommand
          
                Select Case State
          
                  Case 1 '  Normal Case
                      ID = DmisDimension.ID
                      ...
                      If (DmisCommand.Type = DIMENSION_TRUE_START_POSITION) Then
                        State = 2
                      ElseIf (DmisCommand.Type = DIMENSION_START_LOCATION) Then
                        State = 3
                      Elseif (DmisCommand.Type = DATDEF_COMMAND) Then
                         State = 1
                         Skip = TRUE
                      End If
          
                      If (SKIP = FALSE) And (State = 1) Then
                         ' single command line dimension
                         ...
                      End If
          
                  Case 2 '  True Position
                        ' one or more command lines for the actual position axes, handle and stay in state 2
                        ...
          
                  Case 3 '  Location 
                        ' one or more command lines for the actual location axes, handle and stay in state 3
                         ...
          
                End Select
          
                Set DmisDimension = Nothing
          
              ElseIf (DmisCommand.Type = DIMENSION_TRUE_END_POSITION) Then
          
                State = 1
          
              ElseIf (DmisCommand.Type = DIMENSION_END_LOCATION) Then
          
                State = 1
          
              Elseif (DmisCommand.Type = FEATURE_CONTROL_FRAME) Then
          
                  ...
                  State = 1
          
              End If
          
              Set DmisCommand = Nothing
          
            Next ix
          Last edited by AndersI; 03-12-2019, 09:01 AM.
          AndersI
          SW support - Hexagon Metrology Nordic AB

          Comment


          • Darius11
            Darius11 commented
            Editing a comment
            By "or no letter" I meant that as last symbol can be R G B or number but only R G B is a meter.
            Actually G is error but not mistake. I did try a lot of things and I do understand that to use just G is wrong, but somehow it did work better than "G". Yeah probably I will use Option Explicit.
            I will try think about your piece of code if I will be capable to digest it.
            Thanks

          • Darius11
            Darius11 commented
            Editing a comment
            Hi,
            I think your guess is right, it do work for single command line dimensions (distance) but it do not work for diameters.
            Sorry I am too weak to digest your example. If I understand well, I just need change "..." to ID calculations and it should work but no result has achieved. Similar example I did find in a forums:

            https://www.pcdmisforum.com/forum/pc...t-of-tolerance

            This script didn't show any errors and didn't give any result. I am not sure how do work States, and Cases and how working piece of your code. Could you please explain, how should work your piece of code, and how working Case and State?

        Related Topics

        Collapse

        Working...
        X