Custom Browser Node

Custom Browser Node

dbrblg
Collaborator Collaborator
1,964 Views
12 Replies
Message 1 of 13

Custom Browser Node

dbrblg
Collaborator
Collaborator

Hi,

 

I would like to add a custom node under the Top Node in the Model Pane in the part environment.

 

Currently I have the following code which produces an error Method 'AddChild' of object 'BrowserNode' failed

 

Sub test()

    Dim BrowserPanes As BrowserPanes
    Dim BrowserNodeDefinition As BrowserNodeDefinition
    Dim BrowserNode As BrowserNode
    Dim Icon As IPictureDisp
    Dim ClientNodeResource As ClientNodeResource
    Dim ClientNodeResources As ClientNodeResources
    
    Set BrowserPanes = ThisApplication.ActiveDocument.BrowserPanes
    Set ClientNodeResources = BrowserPanes.ClientNodeResources
    Set Icon = LoadPicture("c:\testimage.bmp")
 
    Set ClientNodeResource = ClientNodeResources.ItemById("TestResource", 1)
    If (ClientNodeResource Is Nothing) Then
        Set ClientNodeResource = ClientNodeResources.Add("TestResource", 1, Icon)
    End If
    
    Set BrowserNodeDefinition = BrowserPanes.CreateBrowserNodeDefinition("TestNodeDefinition", 1000, ClientNodeResource)
    Set BrowserNode = BrowserPanes.Item("Model").TopNode.AddChild(BrowserNodeDefinition)

End Sub

The idea is to create a custom node, when clicked will run some code as yet have not looked at.

 

Does anyone have any idea why this is failing?  

 

I am running Inventor 2012 32bit.

 

Many thanks

 

0 Likes
1,965 Views
12 Replies
Replies (12)
Message 2 of 13

CadUser46
Collaborator
Collaborator

Im no expert but it is because you are trying to add the ID as 1.  I think that ID will already be used by the other browse nodes.


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
Message 3 of 13

dbrblg
Collaborator
Collaborator

I have tried changing this to an id of 10 to see whether this made any difference but unfortulately I still have the same problem.

 

Thanks for the suggestion though.

0 Likes
Message 4 of 13

YuhanZhang
Autodesk
Autodesk

It is not possible to add client nodes to built-in panes. You can create a custom pane and add client browser node onto it, you can find a sample in API Help via searching "Creating a custom pane and adding browser nodes".



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 5 of 13

dbrblg
Collaborator
Collaborator

I understood that was the case from the help files however the revision cloud feature under drawing tools in the SDK usertools does allow you to add an icon under the build in pane.

 

How is it possible for this to do it?

0 Likes
Message 6 of 13

YuhanZhang
Autodesk
Autodesk

I see what you mean. You could not ADD a client browser node to built-in pane, but you can customize a built-in browser node with your icon. NativeBrowserNodeDefinition.OverrideIcon would work for you.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 7 of 13

dbrblg
Collaborator
Collaborator

The only icon you can change is a built in one which isn't all that useful.  If you could add your own custom one that would be more useful.  Is there plans for Autodesk to allow the user to add their own icons to the built in panes in the future?

 

Thanks

0 Likes
Message 8 of 13

YuhanZhang
Autodesk
Autodesk

Maybe a workaround for you is to use the ClientFeature. You can easily create a ClientFeature and use its BrowserNode, a ClientFeature's node can be empty or include other browser nodes, you can also customize the browser node as you like. Hope this can help.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 9 of 13

dbrblg
Collaborator
Collaborator

Thanks for this Rocky, it looks promising.

 

I have a couple of questions though:

 

1) is it possible to determine the clientfeatures position in the tree? Maybe move it once it's created, perhaps?

 

2) Is there any way to prevent it being renamed, like 'normal' features are?

 

Thanks

0 Likes
Message 10 of 13

YuhanZhang
Autodesk
Autodesk

Yes, you can find the ClientFeature's node position through iterating the nodes in the tree.An empty ClientFeature node can be moved to any place on the same tree lelvel, you can move it via BrowserPane.Reorder.

 

As for the name, I am not sure I catch it here, if you mean the label of the browser node, you should be able to change it via PartFeature.Name.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 11 of 13

dbrblg
Collaborator
Collaborator

Sorry i've just realised something...

 

I didn't want the user to be able to double click on the ClientFeature in the tree and be able to change it's name.  I thought normal features such as Extrusions and Cutouts wouldn't allow you to change its name in this way but they do.  

 

I didn't want the user to be able to change the name to the same as one that already exists but on further investigation, Inventor deals with this problem by issuing a warning.  

 

Problem solved.  Thanks Smiley Happy

0 Likes
Message 12 of 13

dbrblg
Collaborator
Collaborator

Is there a way of searching nodes by clientID?

 

Sub reorderBrowserPane()
    
    Dim oPane As Inventor.BrowserPane
    Dim oNode As Inventor.BrowserNode
    
    Set oPane = ThisApplication.ActiveDocument.BrowserPanes.Item("Model")
    
     Set oNode = oPane.TopNode.BrowserNodes.[clientID("test")]
        
    'Call oPane.Reorder
    
End Sub

 I have the code above, which is clearly incomplete but should give you an idea what I am looking for!!

 

Once i've added the node it would be usefull to be able to find it easily in much the same way as the ItemByID() method does.

 

Is this possible?

 

Thanks

0 Likes
Message 13 of 13

YuhanZhang
Autodesk
Autodesk

I think you can either use the ClientFeature.BrowserNode to return the browser node object that you need. Or use the BrowserNodes.Item(Name) to return the browser node with passing a name as index as the Name(label) for a browser node is unique in the same pane tree. The ItemByID is used for client browser node only, so for the built-in node it does not help here:).



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes