- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Ive been fiddling with this small piece of code all afternoon to try to get it to do what i want.
I finally came up with what appears to be a working, if inelegant solution, but i'd love to know the "right way" to do it.
I had a piece of code that just sticks the volume of my part into a user parameter in ft^3, it works great.
I wanted to make it a little smarter and add some functionality, first up, i wanted to have it create the user parameter if it doesnt already exist.
I came up with this mess:
oMyParameter = ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters doc = ThisDoc.Document volume = iProperties.Volume Dim oUOM Dim conv oUOM = doc.UnitsOfMeasure Dim strVolume Dim sLengthUnit sLengthUnit = oUOM.GetStringFromType(11266) Dim sVolumeUnit sVolumeUnit = sLengthUnit & "^3" Dim strVolumeft As String strVolumeft = oUOM.ConvertUnits(volume, sVolumeUnit, "ft^3") Try Parameter.Param("Volume_cuft").Expression = Str (Round(Val(strVolumeft),2)) Catch oParameter=oMyParameter.AddByExpression("Volume_cuft", "3", "ft^3") End Try Parameter.Param("Volume_cuft").Expression = Str (Round(Val(strVolumeft),2))
I know i should be able to just set the Parameter to what i want in that catch line, but i just couldnt get it to work, so i just set it to a random number, then reset it to my volume the only way i know how in that last line.
Help a brotha out?
Solved! Go to Solution.