Parametric Program for part families

Parametric Programming - Part Families

Do you manufacture and inspect Part Families?  Meaning, variety of parts having similar overall geometry but with varying dimensional characteristics?  Instead of cresting one program for each unique part, you can realize significant time savings by creating one parametric program that can inspect a variety of parts.

The following KB article describes a simple parametric program that will inspect cubes (blocks) or varying size.  This article will serve as an example that can be expanded upon as needed.  In this simple example we will only vary 3 dimensions for the work-piece, of course a more complex parametric program is possible.  The short video below shows the results of the example we'll review.



First we'll consider, how should we specify the parameters?  We could prompt the CMM operator to enter individual dimensions, we could prompt for a Rev Number and then lookup parameters that have been pre-configured in the VB Script, or we could refer to an outside data source such as a Sql database or simple text file.  The third option is best as it allows you to add new part configurations by simply adding data to this external data source.  In our example we'll use a simple text file.  Contents of three unique files as shown below:


File # 1 contents:
File # 2 contents:
File # 3 contents:
Part # / ID
MyPart123,
MyPart246,
MyPart112,
Length, Upper & Lower Tolerance
76.2,0.5,0.5,
152.4,0.5,0.5,
50.8,0.25,0.25,
Width, Upper & Lower Tolerance
50.8,0.5,0.5,
101.6,0.5,0.5,
15,0.75,0.75,
Height, Upper & Lower Tolerance
25.4,0.5,0.5
50.8,0.5,0.5
12.5,0.75,0.75


We'll need to give the CMM program operator a chance to specify which file should be used.  This can be done with VB Script as follows:
  1. Set objWShell = CreateObject("WScript.Shell") 
  2. Set ChooseFile = objWShell.Exec( "mshta.exe ""about: <input type=file id=X><script>X.click();new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).WriteLine(X.value);close();resizeTo(0,0);</script>""" )
  3.  MyFile = ChooseFile.StdOut.ReadAll

  4.   ChrPos = InStr(MyFile, Chr(13))
  5.   ChrPos = ChrPos -1
  6.   MyFile = Left(MyFile, ChrPos)

This will create a VB variable "MyFile" that contains the complete file path / name of file picked by operator using standard Windows dialog.

Better yet, we can prompt user to enter part ID and then look for file xxxx.txt in the specified folder, then fall back to file picker method if file cannot be located, like this:
  1. 'Locate Job Config Txt File
  2. Set objFSO = CreateObject("Scripting.FileSystemObject")
  3. Set objWShell = CreateObject("WScript.Shell")

  4. MyJob = InputBox("Please Enter Job Number")
  5. MyFile = "C:\Users\Public\Jobs\" + CStr(MyJob) + ".txt"

  6. 'check to see that Jobxxx.txt file exists
  7. If objFSO.FileExists(MyFile) Then
  8. 'If not - then prompt user to pick file manually
  9. Else   

  10.   MsgBox "Job not found - Please locate Job config .txt file"

  11.   Set ChooseFile = objWShell.Exec( "mshta.exe ""about: <input type=file id=X><script>X.click();new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).WriteLine(X.value);close();resizeTo(0,0);</script>""" )
  12.   MyFile = ChooseFile.StdOut.ReadAll

  13.   ChrPos = InStr(MyFile, Chr(13))
  14.   ChrPos = ChrPos -1
  15.   MyFile = Left(MyFile, ChrPos)
  16. End If

Now that we know what file to open / read, we can open the file and extract contents to VB Script variables - these variables will be used to adjust measured feature sizes and report tolerances:
Parsing the input file could be done more efficiently using the VB Split() function  for comma separated files.  The example below has overhead Script to deal with inconsistent line format, some ending in comma, others do not.
  1. ' Open file and read line by line
  2. Set objFile = objFSO.OpenTextFile(MyFile, 1)
  3. If objFile.AtEndOfStream = False Then
  4.   Line1 = (objFile.ReadLine)
  5. Else
  6.   Line1 = "custom_job"
  7. End If

  8. If objFile.AtEndOfStream = False Then
  9.   Line2 = (objFile.ReadLine)
  10. Else
  11.   Line2 = "777,1,1"
  12. End If
  13. If objFile.AtEndOfStream = False Then   
  14.   Line3 = (objFile.ReadLine)
  15. Else
  16.   Line3 = "50.8,1,1"
  17. End If 
  18. If objFile.AtEndOfStream = False Then   
  19.   Line4 = (objFile.ReadLine)
  20. Else
  21.   Line4 = "25.4,1,1"
  22. End If
  23. objFile.Close

  24. MsgText = "Job file contents:" + Chr(10) + "   Job Number:  " + Line1 + Chr(10) + "   Length:  " + Line2 + Chr(10) + "   Width:  " + Line3 + Chr(10) + "   Height:  " + Line4
  25. DoEdit = MsgBox(MsgText, 64, "Job Setup Info")

  26. 'parse read lines into variables
  27. 'Remove comma from end of Line1
  28.   DelimPos = InStr(Line1, ",")
  29.   strJobNum = Left(Line1, DelimPos-1)
  30.   'MsgBox(strJobNum)

  31. 'split Line2 into Length and Tol Variables
  32.   DelimPos = InStr(Line2, ",")
  33.   Length = Left(Line2, DelimPos-1)
  34.   Line2 = Right(Line2, Len(Line2) - DelimPos)
  35.   DelimPos = InStr(Line2, ",")
  36.   LenLoTol = Left(Line2, DelimPos-1)
  37.   LenLoTol = LenLoTol * -1
  38.   Line2 = Right(Line2, Len(Line2) - DelimPos)
  39.   DelimPos = InStr(Line2, ",")
  40.   LenUpTol = Left(Line2, DelimPos-1)
  41.   'MsgBox(CStr(Length) + Chr(10) + CStr(LenLoTol) +Chr(10) + CStr(LenUpTol))

  42. 'split Line3 into Width and Tol Variables
  43.   DelimPos = InStr(Line3, ",")
  44.   Width = Left(Line3, DelimPos-1)
  45.   Line3 = Right(Line3, Len(Line3) - DelimPos)
  46.   DelimPos = InStr(Line3, ",")
  47.   WidLoTol = Left(Line3, DelimPos-1)
  48.   WidLoTol = WidLoTol * -1
  49.   Line3 = Right(Line3, Len(Line3) - DelimPos)
  50.   DelimPos = InStr(Line3, ",")
  51.   WidUpTol = Left(Line3, DelimPos-1)
  52.   'MsgBox(CStr(Width) + Chr(10) + CStr(WidLoTol) +Chr(10) + CStr(WidUpTol))

  53. 'split Line4 into Height and Tol Variables
  54.   DelimPos = InStr(Line4, ",")
  55.   Height = Left(Line4, DelimPos-1)
  56.   Line4 = Right(Line4, Len(Line4) - DelimPos)
  57.   DelimPos = InStr(Line4, ",")
  58.   HtLoTol = Left(Line4, DelimPos-1)
  59.   HtLoTol = HtLoTol * -1
  60.   Line4 = Right(Line4, Len(Line4) - DelimPos)
  61.   'DelimPos = InStr(Line4, ",")
  62.   'HtUpTol = Left(Line4, DelimPos-1)
  63.   HtUpTol = Line4  'last line has no trailing comma
  64.   'MsgBox(CStr(Height) + Chr(10) + CStr(HtLoTol) +Chr(10) + CStr(HtUpTol))

Finally, we'll create the variables that drive the motion of each measured feature.  In this case Length, Width, Height, and some associated clearance and edge offsets:
  1. 'set variables for PtMeas and Move Points
  2. XLeft = 3
  3. XRight = Length - 3
  4. XCenter = Length / 2

  5. YFront = 3
  6. YRear = Width - 3
  7. YCenter = Width / 2

  8. Z = Height
  9. ZClear = Height + 10
  10. XClear = Length + 5
  11. YClear = Width + 5

Now to apply VB Variables to the Measurement and Reporting Operations.  Look for the Set Variable button.  This can be used both for Features Nominal but also for underlying Path and Point locations.  Note - the Measurement Commands that facilitate VB Variable will begin with "@" - this will serve as a quick visual indicator when reviewing the measurement operation.  In the example below, the X & Y location of Move Point is set by VB Variables XLeft and YClear when program runs.




While i n this example, the reported Length by VB Variable  Length  when program runs.



We recommend that you pick one part from the similar part family and write the initial program.  Create a program for this one part, then after it's tested and operates as expected add the VB Script and references to Variables as described above.  See the attached CMM-Manager Project file and associated job config files.  You can run this program easily if you have access to a 1,2,3 and 2,4,6 block.  Alternately, you could modify the attached job files to accommodate any sized blocks- i.e. gage blocks - that you have available.
    • Related Articles

    • VB Script - Getting Started

      What can I do with VB Scripting? CMM-Manager VB Scripts run in line with program execution and can be used to perform loops and flow control, display custom messages, prompt user for input that then influences program execution - i.e. skip section of ...
    • Programming with Part and Fixture CAD Models

      The main advantage of utilizing the fixture CAD file in conjunction with the part model is that CMM-Manager will generate a measurement path to avoid both details, eliminating any manual adjustments. For example, programming the part shown in the ...
    • VB Script - Variable use for Feature Names and User Notes

      When looping Program steps by use of VB Script loop - i.e. For Loop, Do Until, etc. - Features that have been executed more than one time will automatically be renamed using standard convention as such - Circle1, Circle1...1, Circle1...2, ...
    • VB Script - Prompt to skip manual Alignment

      Many times a CMM program may have a manual alignment followed by a DCC alignment. In some cases, the manual alignment does not need to be executed each time the program is run. This is true if subsequent running of the program is done with each part ...
    • Launch CMM-Manager Program using External Command

      It is possible to run another CMM-Manager Program from the External Command operation. This is useful if you'd like to create a simple launching program - i.e. main program that prompts user for next program, and then runs accordingly to user ...