hexagon logo

Being dimension specific with VB script

Someone was checking thickness of a part with PCDMIS using distance. The part program had over 150 dimensions. Wanting to know the minimum distance he asked me if it could be coded instead of sifting through a 150+ dimension report. Knowing that distance is the only type of dimension in the program I wrote him this .bas

Sub Main()

Dim pcdmis As Object
Dim Part As Object
Dim Cmds As Object
Dim Cmd As Object
Dim DimCmd As Object

Set pcdmis = CreateObject("pcdlrn.application")
Set Part = pcdmis.ActivePartProgram
Set Cmds = Part.Commands

Dim dblMeasurment As Double
Dim dblMinimum As Double
Dim intCounter As Integer

intCounter = 0


For Each Cmd In Cmds

    If Cmd.IsDimension Then
    Set DimCmd = Cmd.DimensionCommand
    dblMeasurment = DimCmd.Measured
    
        If intCounter = 0 Or dblMeasurment < dblMinimum Then
        dblMinimum = dblMeasurment
        End If
        
    intCounter = intCounter + 1
    End If

Next Cmd

Dim strTheFile As String
strTheFile = "C:\Minimum.txt"
Open strTheFile For Output As #1
Write #1, dblMinimum
Close #1

End Sub


My question is how do I check what type of dimension I am looking at? If there are any other dimensions in the program this will not ignore them and they will be used in the calculation of finding the minimum. I want to be able to go through and only use distance data. For now this works fine for him but I think it would be nice to be able to be specific as to the exact type of dimension. Right now because he has 3.2063 (does not support SetVariableValue) he reads it in from the text file with PCDMIS to set a variable. The variable has to be reported in a comment of some kind (either report or operator). If it is assigned to a generic feature and dimensioned that dimension gets evaluated by the .bas and returns 0 because it has not been set at the time the script runs. Does anyone know how to evaluate dimensions to get their specific type (ie location, true position, concentricity, flatness etc)?

Craig
  • Is there a way to interrogate the Dimension name? I was trying to figure that out, but I am not hitting on anything.

    I used something similar on features. I can sort through the feature names by using TutorElement. I do something similar as to what you want to accomplish, but then for features. Works nice.

    But TutorElement does not work for a dimension, I just found out. Maybe there is another way.

    Just a thought, Jan.
  • I see the Command.DimensionCommand object lists the various types but I'm not sure how to enumerate them...

    I also found a Commands.GetCommandText that could be searched for "Distance" if it is a distance command...

    Not sure if any of this would help, though...
  • try this, in general

    You want to go into the edit window and right mouse click on the command. At the bottom of the list you'll see an option to Change Pop-Up Display and a sub-menu, where you'd want to select the option to display Command Information.

    Now, go back to the same command in the edit window and position the cursor over the command, and you'll see both the type description and the numerical type. As an example, for my command I see a type description of 'Dimension 2d Distance' and a type of '1107'.

    At that point, back in your BASIC program, you have several choices. You could use the form -

    If Cmd.TypeDescription = "Dimension 2d Distance" Then "action"

    or the form

    If Cmd.Type = DIMENSION_2D_DISTANCE Then "action"

    but both of these are (English) language specific. If you want to make the program usable no matter what language the software is in (German, French, etc.) you could use the form -

    If Cmd.Type = "1107" Then "action"

    My syntax might be off slightly, but I think you get the idea. This will work for any type of command.
  • Thank you much. I just started toying with the pop up display a bit ago when bisandmore came up with a solution. I need to look at that feature more often.

    Craig