Changing Positional Representation Error

Changing Positional Representation Error

ahmed.hagi
Enthusiast Enthusiast
563 Views
6 Replies
Message 1 of 7

Changing Positional Representation Error

ahmed.hagi
Enthusiast
Enthusiast

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):

ahmedhagi_0-1641917725892.png

 

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

 

0 Likes
564 Views
6 Replies
Replies (6)
Message 2 of 7

JelteDeJong
Mentor
Mentor

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.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 7

ahmed.hagi
Enthusiast
Enthusiast

Thanks so much for your reply. I tried modifying the code to include your count.

It comes up with this:

ahmedhagi_0-1641936348036.png

 

Followed by this:

 

ahmedhagi_1-1641936367514.png

 

It is odd that it would say this because the sub assembly definitely has this positions:

ahmedhagi_2-1641936434700.png

 

Any other ideas?

0 Likes
Message 4 of 7

A.Acheson
Mentor
Mentor

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"

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 5 of 7

ahmed.hagi
Enthusiast
Enthusiast

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...

0 Likes
Message 6 of 7

el_jefe_de_steak
Collaborator
Collaborator

Is it possible that there is an extra space in the positional rep name compared to the text you are searching for?

0 Likes
Message 7 of 7

ahmed.hagi
Enthusiast
Enthusiast

I double checked the name and string for differences. There are none 😞

0 Likes