BrowserFolder How to add a workpoint with vba?

BrowserFolder How to add a workpoint with vba?

wolfgang_nickl
Advocate Advocate
791 Views
2 Replies
Message 1 of 3

BrowserFolder How to add a workpoint with vba?

wolfgang_nickl
Advocate
Advocate

When I try to add a Workpointnode to a existing Browserfolder an error occurs.

When I do the same with a part it works.

How can I add a Workpoint to a given Browserfolder.

 

You can see it with the following example:

1. Open an new assembly

2. Insert a Browserfolder "NewFolder"

3. Insert a Part

4. Insert a Workpoint

5. run the following code

 

Sub AddtoBrowserFolder()
    ' Ref to AssebmlyDocument
    Dim oAssmDoc As AssemblyDocument
    Set oAssmDoc = ThisApplication.ActiveDocument
    ' Ref to activePane
    Dim oPane As BrowserPane
    Set oPane = oAssmDoc.BrowserPanes.ActivePane
    'Ref to Folder 'NewFolder'
    Dim oFolder As BrowserFolder
    Set oFolder = oPane.TopNode.BrowserFolders("NewFolder")
    'ref to secondlast nod(Part)
    Dim oBrowserNode As BrowserNode
    Set oBrowserNode = oPane.TopNode.BrowserNodes.Item(oPane.TopNode.BrowserNodes.Count - 1)
    Debug.Print oBrowserNode.FullPath
    Call oFolder.Add(oBrowserNode)
    oPane.Refresh
    MsgBox "no error"
    'ref to last node (Workpoint)
    Set oBrowserNode = oPane.TopNode.BrowserNodes.Item(oPane.TopNode.BrowserNodes.Count)
    Debug.Print oBrowserNode.FullPath
    Call oFolder.Add(oBrowserNode)
End Sub

What is wrong?

 

Best Regards

Wolfgang

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

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

Hi @wolfgang_nickl

 

Try the following approach to add workspoint to browser folder.

 

Sub AddtoBrowserFolder()
    ' Ref to AssebmlyDocument
    Dim oAssmDoc As AssemblyDocument
    Set oAssmDoc = ThisApplication.ActiveDocument
    ' Ref to activePane
    Dim oPane As BrowserPane
    Set oPane = oAssmDoc.BrowserPanes.ActivePane
    'Ref to Folder 'NewFolder'
    Dim oFolder As BrowserFolder
    Set oFolder = oPane.TopNode.BrowserFolders("NewFolder")
    'ref to secondlast nod(Part)
    Dim oBrowserNode As BrowserNode
    Set oBrowserNode = oPane.TopNode.BrowserNodes.Item(oPane.TopNode.BrowserNodes.Count - 1)
    Debug.Print oBrowserNode.FullPath
    
    Dim oNew As BrowserFolder
    Dim oCol As ObjectCollection
    Set oCol = ThisApplication.TransientObjects.CreateObjectCollection
    oCol.Add oBrowserNode
    
    Set oNew = oPane.AddBrowserFolder("NewFolder", oCol)
    
    ' Delete the redundant browser folder
    oFolder.Delete

End Sub

Please feel free to contact if there is any doubt.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 3 of 3

wolfgang_nickl
Advocate
Advocate

Hello Chandra,

 

thank you for your solution.

Also 'new folder' is moving down in the browser,

it works for me because in my case position of folder can move.

 

Best Regards

Wolfgang

0 Likes