Method 'Reorder' for Demoting Pattern to New Sub-Assembly Fails

Method 'Reorder' for Demoting Pattern to New Sub-Assembly Fails

jacofiero
Contributor Contributor
614 Views
2 Replies
Message 1 of 3

Method 'Reorder' for Demoting Pattern to New Sub-Assembly Fails

jacofiero
Contributor
Contributor

I'm trying to automate the creation of a new subassembly and demote a circular occurrence pattern to it.  I can do it, manually, without incident but the VBA macro kicks out an error.  I set SilentOperation = True, but VBA still kicks out the error and my pattern doesn't get demoted.

 

Here's the code.  I'd appreciate any help.

 

Public Function TESTDemoteDeck()
    Call InitializeMainObjects
    Dim oNewSubAssy As AssemblyDocument
    Set oNewSubAssy = oApp.Documents.Add(kAssemblyDocumentObject, , False)
    Dim oMat As Matrix
    Set oMat = ThisApplication.TransientGeometry.CreateMatrix
    Dim oSubAssyOcc As ComponentOccurrence
    Set oSubAssyOcc = oAsmCompDef.Occurrences.AddByComponentDefinition(oNewSubAssy.ComponentDefinition, oMat)
    Dim oPane As BrowserPane
    Set oPane = oDoc.BrowserPanes.Item("Model")
    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 Integer, j As Integer
    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

    Dim oSourceNode As BrowserNode
    Set oPattern = oAsmCompDef.OccurrencePatterns.Item("PatternName")
    Set oSourceNode = oPane.GetBrowserNodeFromObject(oPattern)
    oApp.SilentOperation = True
    On Error GoTo CheckError
    '##ERROR FROM THE LINE BELOW THIS
    Call oPane.Reorder(oTargetNode, False, oSourceNode)
    oApp.SilentOperation = False
    
CheckError:
    Debug.Print "!!!!Run-time Error!!!!"
    Debug.Print "    Err.Number = " & Err.Number
    Debug.Print "    Err.Descri = " & Err.Description
Resume Next

End Function

 Most of it is taken directly from the code example in the API Help reference

 

 

Oh, here's the error.  I believe it's just a generic automation runtime error.

 

Err.Number = -2147467259
Err.Descri = Method 'Reorder' of object 'BrowserPaneObject' failed

0 Likes
Accepted solutions (1)
615 Views
2 Replies
Replies (2)
Message 2 of 3

MjDeck
Autodesk
Autodesk
Accepted solution

Although you can use BrowserPane.Reorder to demote a component into a subassembly, it doesn't work for a component pattern. We should be able to make it work in a future version.


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 3 of 3

jacofiero
Contributor
Contributor
Fair enough. Thanks for the reply.
0 Likes