Demote OccurrencePattern

<?xml encoding=”UTF-8″>By Adam Nagy

There is a sample in the API Help about demoting an occurrence using the BrowserPane.Reorder function – search for “Demote occurrence API Sample
However, it does not work in case of an OccurrencePattern, because that is not supported by the product either:

OccurrenceVsPattern
If you think this would be something useful to have in the product then please log it on the IdeaStation:
http://forums.autodesk.com/t5/inventor-ideas/idb-p/v1232/tab/most-recent

There is another way to demote a component however: use the “AssemblyDemoteCmd” control definition.
Just make sure that you are selecting the correct component – if you select Occurrences(1) that will only return an item inside the pattern and not the pattern object itself:

OccurrencePattern

Sub DemoteWithCommand()
Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument
Dim oDef As AssemblyComponentDefinition
Set oDef = oDoc.ComponentDefinition
'Set a reference to the first occurrence
Dim oOcc As ComponentOccurrence
Set oOcc = oDef.Occurrences.Item(1)
Dim oItemToMove As Object
If oOcc.IsPatternElement Then
Set oItemToMove = oOcc.PatternElement.Parent
Else
Set oItemToMove = oOcc
End If
'Clear select set
oDoc.SelectSet.Clear
'Add the occurrence to demote to the select set
oDoc.SelectSet.Select oItemToMove
ThisApplication.SilentOperation = True
Dim oCM As CommandManager
Set oCM = ThisApplication.CommandManager
' Prepopulate the file name of new component in
' the 'Create Component' dialog
oCM.PostPrivateEvent kFileNameEvent, "C:temptestdemoted.iam"
Dim oControlDef As ControlDefinition
Set oControlDef = oCM.ControlDefinitions("AssemblyDemoteCmd")
' Execute the demote command
oControlDef.Execute
ThisApplication.SilentOperation = False
End Sub

 


Comments

2 responses to “Demote OccurrencePattern”

  1. Hi Adam
    Great code and thanks for this. Do you think it is possible to do same with a picker and multiple occurrences?
    Got the code working direct in iLogic but struggle with the picker to have multiple parts inside the demote.
    Thx
    Jens

  2. You can select multiple objects like this: https://adndevblog.typepad.com/manufacturing/2013/11/do-selection-from-ilogic.html
    Then in a loop you could select the relevant object and execute AssemblyDemoteCmd

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading