I'm trying to change a positional representation of a subassembly with the API, but I run into this error, "Unspecified error (Exception from HRESULT: 0x80004005(E_FAIL):
It is odd because I am able to change the representation of the subassembly manually.
For Each oCompOcc In oCompDef.Occurrences If Component.IsActive("REJECT DEVICE:1") = True Then If oCompOcc.Name = "REJECT DEVICE:1" Then oCompOcc.ActivePositionalRepresentation = "Master" 'Fails at this point End If End If Next
I could reproduce this error only if the PositionalRepresentation name did not exist. You can try the following rule. This will check if the PositionalRepresentation with the name exsits.
Dim doc As AssemblyDocument = ThisDoc.Document Dim oCompDef = doc.ComponentDefinition Dim representationName = "Master" Dim occName = "REJECT DEVICE:1" For Each oCompOcc As ComponentOccurrence In oCompDef.Occurrences If oCompOcc.Name = occName Then If Component.IsActive(occName) = True Then Dim def As AssemblyComponentDefinition = oCompOcc.Definition Dim reps = def.RepresentationsManager.PositionalRepresentations. Cast(Of PositionalRepresentation). Where(Function(p) p.Name = representationName).ToList() If (reps.Count = 0) Then MsgBox(occName & " does not have a PositionalRepresentation called: " & representationName) Else oCompOcc.ActivePositionalRepresentation = representationName 'Fails at this point End If End If End If Next
PositionalRepresentation
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Blog: hjalte.nl - github.com
Thanks so much for your reply. I tried modifying the code to include your count.
It comes up with this:
Followed by this:
It is odd that it would say this because the sub assembly definitely has this positions:
Any other ideas?
Here is a post discussing this. If you keep the same name you can change them manually or by code as they become linked. Or use the override "PositionalRepresentation.SetPositionalRepresentationOverride"
Thanks for the reply! I've already looked at that post, doesn't help my scenario, the positional representation I am trying to access is only in the subassembly, not the top level assembly. That approach won't really work because I need to maintain the master position in the top level and only change the subassembly...
Is it possible that there is an extra space in the positional rep name compared to the text you are searching for?
Can't find what you're looking for? Ask the community or share your knowledge.