parameter function but for top level assembly

parameter function but for top level assembly

Noah.ClarkX5FEF
Contributor Contributor
819 Views
6 Replies
Message 1 of 7

parameter function but for top level assembly

Noah.ClarkX5FEF
Contributor
Contributor

Hi there,

So I like using the parameter function because it allows you to input the component name and parameter name as a string and gives you the data from that parameter.  this is nice because you can modify the string to cycle through similarly named parameters like box1, box2, box3,  etc...

However it doesn't seem to work on the top level assembly.  My question is if there is any existing function or something within the parameter function that would allow me to do the same thing as the parameter function but I'm able to access the top levels parameters?

My goal is not to write out a bunch of code that would let me do the same thing or change a bunch of component parameters and other rules so that I can make the normal function work.

0 Likes
Accepted solutions (2)
820 Views
6 Replies
Replies (6)
Message 2 of 7

dalton98
Collaborator
Collaborator

If im understanding correctly you want to change/get parameter values at the top level assembly?

Heres some example code:

Parameter("screwdriver_body:1", "Body_Color") = ScrewdriverColor

Parameter(docAndParameterName as String, paramName as String) = topAssemblyParamName

paramValue = Parameter("screwdriver_body:1", "Body_Color")

 

You can also replace, supress, model state, and add components in your top assembly. If this is what your looking for I can link you some notes I took on parameter/component functions in an assembly.

 

0 Likes
Message 3 of 7

Noah.ClarkX5FEF
Contributor
Contributor

that is correct I would like to get/set top level assembly parameters using the Parameter function that allows me to simply input the top level assembly as a string and then its parameter as a string.  But the Parameter function won't let me use the top level assembly.  I checked that I typed it correctly multiple time but I still get an error that it can't be found.

0 Likes
Message 4 of 7

dalton98
Collaborator
Collaborator

Do this to add text parameters:

Dim oAss As AssemblyDocument
oAss = ThisApplication.ActiveDocument

Dim oUserParameters As UserParameters
oUserParameters = oAss.ComponentDefinition.Parameters.UserParameters

oUserParameters.AddByValue("title", "value", UnitsTypeEnum.kTextUnits)

 I think your better off just manually adding parameters. Then you can make them multivalue and link parameter values between components with with ilogic. I'm not sure what you are wanting to do with ur code.

0 Likes
Message 5 of 7

Noah.ClarkX5FEF
Contributor
Contributor

Top Level Assembly has Parameters BoltLoc1, BoltLoc2, BoltLoc3, BoltLoc4, BoltCount(Keeps track of how many bolt components are active)

 

to check or set these values I could just use a bunch of If statements or possibly select case statements.  However I would prefer if I could do something like this

For i = 1 to BoltCount
if Parameter("Top Assembly", "BoltLoc" & i) > value then
Parameter("Top Assembly", "BoltLoc" & i) = other thing
end if Next i

this makes the code not only easier to understand but also reduces the amount of code in my rule I need to write

 

A lot of the sub assemblies have similar redundant parameters that are linked to the top assembly like this but whoever at my work made these sub assemblies did not always name their parameters properly thus if I were to change them I would have to change a bunch of other code and parameter names in other areas as well.

0 Likes
Message 6 of 7

dalton98
Collaborator
Collaborator
Accepted solution

I think this is what your after. It numbers each component and counts the total number of components. It doesn't account for repeats.

Dim oAss As AssemblyDocument
oAss = ThisApplication.ActiveDocument

Dim oUserParameters As UserParameters
oUserParameters = oAss.ComponentDefinition.Parameters.UserParameters

Dim pBoltCount As Integer
pBoltCount = Components.Count
Try
paramBoltCount = oUserParameters.Item("BoltCount").Value
Catch
paramBoltCount = oUserParameters.AddByExpression("BoltCount", pBoltCount, UnitsTypeEnum.kUnitlessUnits)
'paramBoltCount = oUserParameters.AddByExpression("BoltCount", pBoltCount, UnitsTypeEnum.kTextUnits)

End Try

For i = 1 To pBoltCount
Try
oUserParameters.Item("BoltLoc" & i).Value = True
Catch
oUserParameters.AddByValue("BoltLoc" & i, True, UnitsTypeEnum.kBooleanUnits)
End Try
Next
0 Likes
Message 7 of 7

Noah.ClarkX5FEF
Contributor
Contributor
Accepted solution
I think I found the answer in your answer. I didn't realize you could just get a parameter using a string as the item value shown in line:
oUserParameters.Item("BoltLoc" & i).Value = True

I just needed to iterate through all the parameters that started with a specific word in their name and just using i to represent the end number on the parameter name
0 Likes