Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Changing Positional Representation Error

6 REPLIES 6
Reply
Message 1 of 7
ahmed.hagi
416 Views, 6 Replies

Changing Positional Representation Error

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

 

Labels (4)
6 REPLIES 6
Message 2 of 7
JelteDeJong
in reply to: ahmed.hagi

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

Message 3 of 7
ahmed.hagi
in reply to: JelteDeJong

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?

Message 4 of 7
A.Acheson
in reply to: ahmed.hagi

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
Message 5 of 7
ahmed.hagi
in reply to: A.Acheson

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

Message 6 of 7

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

Message 7 of 7

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report