Set decimal places using Automation API

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

  • Set decimal places using Automation API

    Is there a way to set DISPLAYPRECISION using API? Here is the context behind this ask. I'm currently developing a code using API that automatically exports all the measured dimensions to a JSON file. Instead of using the value of DISPLAYPRECISION in the part program, I would like to set the decimal places explicitly using API. Thanks!

  • #2
    What syntax are you using? If using VB.NET a console application would look like this....

    Code:
    Public Module Example
       Sub Main()
          Console.WriteLine(Math.Round(3.44, 1))
          Console.WriteLine(Math.Round(3.45, 1))
          Console.WriteLine(Math.Round(3.46, 1))
          Console.WriteLine()
    
          Console.WriteLine(Math.Round(4.34, 1))
          Console.WriteLine(Math.Round(4.35, 1))
          Console.WriteLine(Math.Round(4.36, 1))
       End Sub  
    End Module
    ' The example displays the following output:
    '       3.4
    '       3.4
    '       3.5
    '      
    '       4.3
    '       4.4
    '       4.4
    PcDmis 2015.1 SP10 CAD++
    Global 7-10-7 DC800S

    Comment


    • #3
      Kp61dude! Sorry for not being clear with my question. Let's say that I have a PC-DMIS command variable cmd and I can extract the measured dimension using API:
      Code:
      PCDLRN.Command cmd;
      measured = cmd.GetText(ENUM_FIELD_TYPES.LINE1_MEAS, 1);
      The number of decimal places for the variable, measured, is controlled by the PC-DMIS command DISPLAYPRECISION in the part program, or the default value which is 4. If I want to export measured to 6 decimal places, is there a way to set DISPLAYPRECISION in the code instead of adding DISPLAYPRECISION in the part program?

      Comment


      • #4
        Why not fetch the numerical values directly from the feature command, instead of using .GETTEXT? GETTEXT is primarily intended for the listing in the Edit Window.

        I think FeatCmd.GetPoints would be the correct way - take a look at the ToPoints.BAS script in the code section of this forum.
        AndersI
        SW support - Hexagon Metrology Nordic AB

        Comment


        • #5
          Originally posted by cmshieh View Post
          Kp61dude! Sorry for not being clear with my question. Let's say that I have a PC-DMIS command variable cmd and I can extract the measured dimension using API:
          Code:
          PCDLRN.Command cmd;
          measured = cmd.GetText(ENUM_FIELD_TYPES.LINE1_MEAS, 1);
          The number of decimal places for the variable, measured, is controlled by the PC-DMIS command DISPLAYPRECISION in the part program, or the default value which is 4. If I want to export measured to 6 decimal places, is there a way to set DISPLAYPRECISION in the code instead of adding DISPLAYPRECISION in the part program?
          cmshieh I highly recommend you follow AndersI recommendation but just to answer your question:

          looks like you're using C# if not just let me know what language you're using.

          First cast from string to integer:
          Code:
                      PCDLRN.Command cmd;
                      string measured = cmd.GetText(PCDLRN.ENUM_FIELD_TYPES.LINE1_MEAS, 1);
          
                      float convert2Float = float.Parse(measured);
          
                      double dblMeasured = Math.Round(convert2Float, 4); // 4 decimal places
                      dblMeasured = Math.Round(convert2Float, 2); // 2 decimal places
          since you're pulling the string from PcDmis Edit Window you're limited to whatever the length is in your PcD program. Using the BASIC script mentioned above will return a type 'double' that's way longer than whatever your PcD decimal precision is, then you can control the length of your decimals with this code inside your API.

          You probably don't want to start from scratch, which is understandable, if you post your code some of us may help and guide you to get it to work as desired...
          Last edited by Kp61dude!; 01-10-2020, 12:05 PM.
          PcDmis 2015.1 SP10 CAD++
          Global 7-10-7 DC800S

          Comment


          • #6
            Fetch the values from PC-DMIS to your app (as AndersI mentions).
            Perform the rounding/display precision of said values in your app.
            Export to JSON.
            PC-DMIS CAD++ 2o23.1 SP1

            Comment

            Related Topics

            Collapse

            Working...
            X