Changing a User Parameter in an assembly

Changing a User Parameter in an assembly

Anonymous
No aplicable
542 Vistas
5 Respuestas
Mensaje 1 de 6

Changing a User Parameter in an assembly

Anonymous
No aplicable
I have a part file ("part1.ipt") that has a user parameter called "Height". When I open this file as a part document, I can modify the "Height" parameter to change the height of the part. This functionality works great:

Set oPartDoc = oApp.Documents.Open(sPartFileName, True)
Set oParameters = oPartDoc.ComponentDefinition.Parameters
'change part height to 30 cm
oParameters.Item("Height").Expression = 30

Now, I am wanting to add this part to an ASSEMBLY document, then change the parameter to 30, but have been unable to do it.
I have this so far:

Dim oAsmCompDef As AssemblyComponentDefinition
Set oAsmCompDef = oApp.ActiveDocument.ComponentDefinition
Dim oOcc As ComponentOccurrence
Set oOcc = oAsmCompDef.Occurrences.Add(sPartFileName, oMatrix)

After I add all the parts, I highlight a part in the assembly pane, I click on FxParameters but I don't see the User Parameters for the part. Are the User Parameters not available when a part is placed into an assembly?

This assembly will have multiple parts added from the same file name, but the "Height" parameter needs to be modified for each occurence.

Can anyone give me some direction on how to change these types of parameters?

tia,

clu
0 Me gusta
543 Vistas
5 Respuestas
Respuestas (5)
Mensaje 2 de 6

Anonymous
No aplicable

I made some additions to your code that should work.  I didn't test it
so there could be a typo or two.


Dim oAsmCompDef As AssemblyComponentDefinition
Set oAsmCompDef =
oApp.ActiveDocument.ComponentDefinition
Dim oOcc As ComponentOccurrence

Set oOcc = oAsmCompDef.Occurrences.Add(sPartFileName, oMatrix)

' Get
the parameter from the part.  This uses the Definition property of
' the
occurrence to get the PartComponentDefinition of the part.  This
' is
the same definition you would access if you opened the part directly.
Dim
oParam As Parameter
Set oParam =
oOcc.Definition.Parameters.Item("Height")
oParam.Expression = "30"

'
Update the assembly.
oApp.ActiveDocument.Update


-Brian



style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
I
have a part file ("part1.ipt") that has a user parameter called "Height". When
I open this file as a part document, I can modify the "Height" parameter to
change the height of the part. This functionality works great:

Set oPartDoc = oApp.Documents.Open(sPartFileName, True)
Set oParameters
= oPartDoc.ComponentDefinition.Parameters
'change part height to 30 cm

oParameters.Item("Height").Expression = 30

Now, I am wanting to add this part to an ASSEMBLY document, then change the
parameter to 30, but have been unable to do it.
I have this so far:

Dim oAsmCompDef As AssemblyComponentDefinition
Set oAsmCompDef =
oApp.ActiveDocument.ComponentDefinition
Dim oOcc As ComponentOccurrence

Set oOcc = oAsmCompDef.Occurrences.Add(sPartFileName, oMatrix)

After I add all the parts, I highlight a part in the assembly pane, I click
on FxParameters but I don't see the User Parameters for the part. Are the User
Parameters not available when a part is placed into an assembly?

This assembly will have multiple parts added from the same file name, but
the "Height" parameter needs to be modified for each occurence.

Can anyone give me some direction on how to change these types of
parameters?

tia,

clu

0 Me gusta
Mensaje 3 de 6

Anonymous
No aplicable
Brian,

Thanks for the code. It does give me access to the user parameters, but it changes every occurrence of the part I have inserted. For example, the height each successive part needs to be 6" more than the previous one. I insert the first part then change the height to 6". I insert the next part, change it's height to 12". But now both parts are 12" tall instead of 6" and 12". Is this because the parts are added using the same part file?

thanks,

clu
0 Me gusta
Mensaje 4 de 6

Anonymous
No aplicable
Each part is unique, so if you insert the same part
again and change anything, it will change each part.


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Brian,

Thanks for the code. It does give me access to the user parameters, but it
changes every occurrence of the part I have inserted. For example, the height
each successive part needs to be 6" more than the previous one. I insert the
first part then change the height to 6". I insert the next part, change it's
height to 12". But now both parts are 12" tall instead of 6" and 12". Is this
because the parts are added using the same part file?

thanks,

clu

0 Me gusta
Mensaje 5 de 6

Anonymous
No aplicable
If you want each occurrence to be different you
need to create a unique part for that occurrence to reference.  If you
place the same part multiple times, each occurrence is referencing the same
part, so if you modify that part, all the occurrences will reflect that
change.  This happens the same way interactively.  If you insert a
part multiple times and then in-place activate one of them and edit it, then go
back to the assembly you'll see that all the occurrences reflect that
edit.

 

-Brian


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Brian,

Thanks for the code. It does give me access to the user parameters, but it
changes every occurrence of the part I have inserted. For example, the height
each successive part needs to be 6" more than the previous one. I insert the
first part then change the height to 6". I insert the next part, change it's
height to 12". But now both parts are 12" tall instead of 6" and 12". Is this
because the parts are added using the same part file?

thanks,

clu

0 Me gusta
Mensaje 6 de 6

amitnkukanur
Collaborator
Collaborator

what is oMatrix, even i am have same kind of project. can u suggest me some ideas

Senior Software Engineer
0 Me gusta