Message 1 of 2
iLogic rule to detect or create text parameter then fill it out causing Crash

Not applicable
01-19-2015
03:19 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
This is supposed to check for a custom parameter "Weight" and if it's not there create it. Then once/if a paramter exists it calculates the extents of the model and calculates the mass for the appropriate unit. It's a bit of a cut and paste job, and had been running into an issue with line 11 where it wouldn't accept "ParameterChecker = oUserParams.AddByValue(Weight, "text",UnitsTypeEnum.kTextUnits)" until I put the paramter value into text. With that change, it now causes Inventor to crash
doc = ThisDoc.Document Munits=doc.unitsofmeasure.MassUnits Lunits=doc.unitsofmeasure.LengthUnits Dim oPartCompDef As PartComponentDefinition = doc.ComponentDefinition Dim oParams As Parameters = oPartCompDef.Parameters Dim oUserParams As UserParameters = oParams.UserParameters Dim ParameterChecker As Parameter Try ParameterChecker = oParams(“Weight“) Catch ParameterChecker = oUserParams.AddByValue(Weight, "text",UnitsTypeEnum.kTextUnits) ParameterChecker.ExposedAsProperty = True End Try If Lunits=11272 Then Volume = (Measure.ExtentsLength * 2.54) * (Measure.ExtentsWidth * 2.54) * (Measure.ExtentsHeight* 2.54) Else If Lunits=11269 Then Volume = (Measure.ExtentsLength/10) * (Measure.ExtentsWidth/10) * (Measure.ExtentsHeight/10) End If materialDensity = ThisDoc.Document.ComponentDefinition.Material.Density Material_Weight = (materialDensity * Volume) If Munits=11286 Then Weight = "(Material_Weight * 0.00220462) lbs" Else If Munits=11284 Then Weight = "(Material_Weight) Grams" Else If Munits=11283 Then Weight = "(Material_Weight/1000) KG" End If