iLogic rule to detect or create text parameter then fill it out causing Crash

iLogic rule to detect or create text parameter then fill it out causing Crash

Anonymous
Not applicable
962 Views
1 Reply
Message 1 of 2

iLogic rule to detect or create text parameter then fill it out causing Crash

Anonymous
Not applicable

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

 

963 Views
1 Reply
Reply (1)
Message 2 of 2

MegaJerk
Collaborator
Collaborator

Change this line : 

 

ParameterChecker = oUserParams.AddByValue(Weight, "text",UnitsTypeEnum.kTextUnits)

 

Into this line : 

 

ParameterChecker = oUserParams.AddByValue("Weight", "text",UnitsTypeEnum.kTextUnits)

 

You were not correctly naming the parameter. Without quotes, Weight just looks like a blank variable, and therefore will throw an error. 



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub