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: 

Demote Frame Member through API

7 REPLIES 7
Reply
Message 1 of 8
fakeru
650 Views, 7 Replies

Demote Frame Member through API

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
7 REPLIES 7
Message 2 of 8
bradeneuropeArthur
in reply to: fakeru

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

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
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 !

Message 3 of 8
fakeru
in reply to: bradeneuropeArthur

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
Message 4 of 8
bradeneuropeArthur
in reply to: fakeru

for me that code works fine!

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
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 !

Message 5 of 8

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

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
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 !

Message 6 of 8
fakeru
in reply to: bradeneuropeArthur

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
Message 7 of 8
fakeru
in reply to: bradeneuropeArthur

                      

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
Message 8 of 8
fakeru
in reply to: bradeneuropeArthur

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

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

Post to forums  

Autodesk Design & Make Report