Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Demote Frame Member through API

fakeru
Advocate

Demote Frame Member through API

fakeru
Advocate
Advocate

Hi,

Did anyone try to demote a frame member through API?

I tried with command manager:

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:\temp\test\demoted.iam"

Dim oControlDef As ControlDefinition
Set oControlDef = oCM.ControlDefinitions("AssemblyDemoteCmd")

' Execute the demote command
oControlDef.Execute

ThisApplication.SilentOperation = False

I also tried with this example:

 

Public Sub Demote()
    ' Get the active assembly document
    Dim oDoc As AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument

    Dim oDef As AssemblyComponentDefinition
    Set oDef = oDoc.ComponentDefinition

    ' Get the occurrence to be demoted
    Dim oOcc As ComponentOccurrence
    Set oOcc = oDef.Occurrences.Item(1)

    ' Create a new sub-assembly to demote the occurrence into
    Dim oNewSubAssy As AssemblyDocument
    Set oNewSubAssy = ThisApplication.Documents.Add(kAssemblyDocumentObject, , False)

    Dim oMat As Matrix
    Set oMat = ThisApplication.TransientGeometry.CreateMatrix

    ' Create an instance of the new sub-assembly
    Dim oSubAssyOcc As ComponentOccurrence
    Set oSubAssyOcc = oDef.Occurrences.AddByComponentDefinition(oNewSubAssy.ComponentDefinition, oMat)

    ' Get the model browser
    Dim oPane As BrowserPane
    Set oPane = oDoc.BrowserPanes.Item("Model")

    ' Get the browser node that corresponds to the new sub-assembly occurrence
    Dim oSubAssyNode As BrowserNode
    Set oSubAssyNode = oPane.GetBrowserNodeFromObject(oSubAssyOcc)

    ' Get the last visible child node under the sub-assembly occurrence
    Dim oTargetNode As BrowserNode
    Dim i As Long
    For i = oSubAssyNode.BrowserNodes.Count To 1 Step -1
        If oSubAssyNode.BrowserNodes.Item(i).Visible Then
            Set oTargetNode = oSubAssyNode.BrowserNodes.Item(i)
            Exit For
        End If
    Next

    ' Get the browser node that corresponds to the occurrence to be demoted
    Dim oSourceNode As BrowserNode
    Set oSourceNode = oPane.GetBrowserNodeFromObject(oOcc)

    ' Demote the occurrence
    Call oPane.Reorder(oTargetNode, False, oSourceNode)
End Sub

But no luck, it won't demote.

 

Same codes work in a standard assembly.

Any advice?

Thanks

Autodesk Inventor 2015 Certified Professional
0 Likes
Reply
730 Views
7 Replies
Replies (7)

bradeneuropeArthur
Mentor
Mentor
for me the first code works fine...................................

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

0 Likes

fakeru
Advocate
Advocate

Can you please post the entire code?

Here is mine:

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(3)

Dim oItemToMove As Object
    Set oItemToMove = oOcc

'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:\Users\asi\Desktop\1000-Desktop\Inventor\frame test\Assembly3.iam"

Dim oControlDef As ControlDefinition
Set oControlDef = oCM.ControlDefinitions("AssemblyDemoteCmd")

' Execute the demote command
oControlDef.Execute

ThisApplication.SilentOperation = False

End Sub

It seems like oControlDef.Execute doesn't run, because occurrence item(3) stays selected after I run the macro.

 

Untitled.png

Autodesk Inventor 2015 Certified Professional
0 Likes

bradeneuropeArthur
Mentor
Mentor
for me that code works fine!

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

0 Likes

bradeneuropeArthur
Mentor
Mentor
use this instead:
Dim oControlDef As ControlDefinition
Set oControlDef = oCM.ControlDefinitions("AFG_CMD_Demote")

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

0 Likes

fakeru
Advocate
Advocate

Hm... The dialog box appeared now even though the SilentOperation is set to True.

That's really strange..

Untitled.png

Autodesk Inventor 2015 Certified Professional
0 Likes

fakeru
Advocate
Advocate

                      

Can you please post the entire code? I just can't figure out why it's not working for me...

Autodesk Inventor 2015 Certified Professional
0 Likes

fakeru
Advocate
Advocate

Hey Arthur,

Would you be able to help on this subject? 🙂

I still can't demote a frame member with oCM.ControlDefinitions("AFG_CMD_Demote")...

 

Thanks

Autodesk Inventor 2015 Certified Professional
0 Likes