hexagon logo

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
  • Note: the "CMM1" value might be different depending on your language setting.
  • 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).
    :-)
  • 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.
  • 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.

    [ [B] xlSheet.Cells(RCount,2).Value = fncsheet.Round((DCmd.Nominal - DCmd.Minus),RND)[/B]
    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?
  • Maybe something like this (untested).

    Pseudocode:

    [COLOR=#0000ff]Set DcmdID = Cmd.DimensionCommand
    DimType = right (DcmdID.ID, 1)
    if DimType = """ then
      DimType = left(right (DcmdID.ID, 2),1)
    
    [/COLOR]

    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.
  • 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.


  • 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
    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.

    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
     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…):
    
    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
    
    
    
  • 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.
  • 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
  • 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-dmis-enterprise-metrology-software/pc-dmis-for-cmms/21594-set-flag-if-dimension-out-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?