Error Getting parameters

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone,
I have a snippet of code I am using to open a template file and modify the parameters of the template. I usually then save the part under a new name and place it into an assembly
Here is the snippet:
SyntaxEditor Code Snippet
'Template Path TemPath= "K:\TKSY WASHER TEMPLATE.ipt" 'Open Template ThisApplication.Documents.Open(TemPath) Dim oDocument As inventor._Document = ThisApplication.documents.itembyname(TemPath) 'Modify Template Dim Testprop As String Dim oParameters As Parameters Dim oChangeParam As Parameter oParameters = ThisApplication.ActiveDocument.ComponentDefinition.Parameters Check=ThisApplication.ActiveEditDocument.FullFileName MessageBox.Show(Check) 'MsgBox("Here") oChangeParam = oParameters.Item("OD") oChangeParam.Expression = 100
This works fine on it's own or in some other rules.
I am making a new rule to place a custom washer. This rule replaces an existing rule which was a little messy (needing an input box for each parameter). The new rule creates user parameters in an assembly, shows a form for the user to change the parameters, opens the template file, uses the parameters inputted to the form to modify the washer, inserts the washer into the assembly and deletes the user parameters.
However, when I use the snippet of code above in my new rule I get an error. I think it is *something* to do with the "Material" parameter. Can anyone see my mistake(s)? Thanks in advance.
SyntaxEditor Code Snippet
Sub Main 'Washer Rule 2'Dim oDoc As AssemblyDocument=ThisDoc.Document oDoc = ThisDoc.Document Dim PartNum as String Dim MFCode As Single Dim NewPath As String = "K:\WASHERS\" oMyParameter=ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters oParameter=oMyParameter.AddByExpression("OD", "10", UnitsTypeEnum.kMillimeterLengthUnits) oParameter=oMyParameter.AddByExpression("ID", "5", "mm") oParameter=oMyParameter.AddByExpression("Thickness", "8", "mm") oParameter=oMyParameter.AddByExpression("CHAMFER", "1", "mm") oParameter=oMyParameter.AddByValue("Material", "070M20 (EN3B)", UnitsTypeEnum.kTextUnits) oParameter=oMyParameter.AddByValue("Finish", "Blacken", UnitsTypeEnum.kTextUnits) MultiValue.SetList("Material", "070M20 (EN3B)", "080M15 (EN32)", "BO1") 'iLogicForm.Show("Place Washer Form", FormMode.NonModal) iLogicForm.Show("Place Washer Form", FormMode.Modal) 'MsgBox(Parameter("Material")) Select Case Parameter("Material") Case "070M20 (EN3B)" MultiValue.SetList("Finish", "BLACKEN", "PROTECT WITH LIGHT OIL", "TUFFTRIDE 60±2 HRC", "ZINC PLATE AND YELLOW PASSIVATE FE/ZN8", "NATURAL") Dim ListString As ArrayList = MultiValue.List("Finish") Parameter("Finish") = InputListBox("Select Finish", ListString, "", "TKSY Standard Washer", "Available Finishes") Case "080M15 (EN32)" MultiValue.SetList("Finish", "CASE HARDEN 60±2 HRC CASE 0.5 DEEP") Case "BO1" MultiValue.SetList("Finish", "HARDEN & TEMPER 60±2 HRC") End Select 'Make Part Number'Material and Finish Code If Parameter("Material") = "070M20 (EN3B)" And Parameter("Finish") = "BLACKEN" Then MFCode=1 If Parameter("Material") = "070M20 (EN3B)" And Parameter("Finish") = "PROTECT WITH LIGHT OIL" Then MFCode=4 If Parameter("Material") = "070M20 (EN3B)" And Parameter("Finish") = "TUFFTRIDE 60±2 HRC" Then MFCode=5 If Parameter("Material")= "070M20 (EN3B)" And Parameter("Finish") = "ZINC PLATE AND YELLOW PASSIVATE FE/ZN8" Then MFCode=6 If Parameter("Material") = "080M15 (EN32)" Then MFCode = 2 If Parameter("Material") = "BO1" Then MFCode = 3 'FInal Part Number PartNum = "PS-" & Parameter("OD") & "-" & Parameter("ID") & "-" & Parameter("Thickness") & "-" & MFCode 'Check Result'MessageBox.Show(PartNum) 'Set the Chamfer size based on Washer OD'MsgBox(Parameter("OD")) Select Case Parameter("OD") Case <6 Parameter("CHAMFER") = 0.3 Case 6 To 16 Parameter("CHAMFER") = 0.5 Case 16 To 50 Parameter("CHAMFER") = 1 Case >50 Parameter("CHAMFER") = 1.5 End Select 'MsgBox(Parameter("CHAMFER")) MsgBox(NewPath & PartNum & ".ipt") 'Open Exhisting Washer If System.IO.File.Exists(NewPath & PartNum & ".ipt") Then ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, PartNum & ".ipt") ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute() ThisApplication.ActiveDocument.Update2(-1) Else 'MessageBox.Show("Not found, yo!") NewWasher End If 'Delete Parameters Dim param As Parameter Try param=oDoc.ComponentDefinition.Parameters.Item("OD") param.Delete param=oDoc.ComponentDefinition.Parameters.Item("ID") param.Delete param=oDoc.ComponentDefinition.Parameters.Item("Thickness") param.Delete param=oDoc.ComponentDefinition.Parameters.Item("CHAMFER") param.Delete param=oDoc.ComponentDefinition.Parameters.Item("Material") param.Delete param=oDoc.ComponentDefinition.Parameters.Item("Finish") param.Delete Catch MsgBox("Parameters not found!") End Try End Sub Sub NewWasher 'Template Path TemPath= "K:\TKSY WASHER TEMPLATE.ipt" 'Open Template ThisApplication.Documents.Open(TemPath) Dim oDocument As inventor._Document = ThisApplication.documents.itembyname(TemPath) 'Modify Template Dim Testprop As String Dim oParameters As Parameters Dim oChangeParam As Parameter oParameters = ThisApplication.ActiveDocument.ComponentDefinition.Parameters Check=ThisApplication.ActiveEditDocument.FullFileName MessageBox.Show(Check) MsgBox("Here") oChangeParam = oParameters.Item("OD") oChangeParam.Expression = 100 End Sub