Ilogic to add volume to user parameter, and create the param it its not there.

Ilogic to add volume to user parameter, and create the param it its not there.

BrandonW9
Advocate Advocate
1,705 Views
2 Replies
Message 1 of 3

Ilogic to add volume to user parameter, and create the param it its not there.

BrandonW9
Advocate
Advocate

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? 

0 Likes
Accepted solutions (1)
1,706 Views
2 Replies
Replies (2)
Message 2 of 3

rossano_praderi
Collaborator
Collaborator
Accepted solution

Hi,

this code solve your problem.

 

On Error Resume Next
Parameter.Quiet = True
ThisApplication.CommandManager.ControlDefinitions.Item("AppUpdateMassPropertiesCmd").Execute
oMyParameter = ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters
doc = ThisDoc.Document
volume = iProperties.Volume
oUOM = doc.UnitsOfMeasure
sVolumeUnit = oUOM.GetStringFromType(11266) & "^3"
Dim strVolumeft As String = oUOM.ConvertUnits(volume, sVolumeUnit, "ft^3")

If Parameter.Param("Volume_cuft")="" Then
	Parameter.Param("Volume_cuft").Expression = Round(Val(strVolumeft),2).tostring
Else
	Parameter=oMyParameter.AddByExpression("Volume_cuft", "3", "ft^3")
	Parameter.Param("Volume_cuft").Expression = Round(Val(strVolumeft),2).tostring
End If

 

 

Bregs

Rossano Praderi



--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------
Message 3 of 3

BrandonW9
Advocate
Advocate

Thank you very much. I have a lot to learn.

0 Likes