Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Need help with VBA and renaming browser nodes

8 REPLIES 8
Reply
Message 1 of 9
bshbsh
2898 Views, 8 Replies

Need help with VBA and renaming browser nodes

Hello everyone,

 

I'd like to ask some advice on this:

(Preface: I am *very* beginner with VBA. Basically have no clue. Smiley Wink )

 

We have the following problem (on AIS2010): we often recycle existing designs with small changes/adapting, means: the (sub)assembly is saved with a new name and part number, and the subcomponents that need to be changed, get a new part number and file name too. So we save a copy, save the parts need changes and then replace the "old" parts in the new assy.

Doing so unfortunatelly retains the "name" of the component in the model browser tree. I have no idea why is that in the first place.

But I'm trying to write a macro that resets the dspalyed names in the browser.

What I found so far, is that under BrowserNodeDefinition, there's a Label property which contains the displayed name, and this does not get changed when the part is replaced. So I thought, I can just compare these BrowserNodeDefinition.Labels with the actual file names and forge a new Label from the new name and the sequence number, however, the BrowserNodeDefinition object is read only, can't be changed.

I haven't found anything else that would contain this name that is displayed in the browser.

 

So my question is, how can I do this thing? Any help or link to a documentation would be good. TIA.

bsh

8 REPLIES 8
Message 2 of 9
mrattray
in reply to: bshbsh

You need to go through the actual component occurrences to change this, not the browser tree nodes.
ComponentOccurrence.Name
Mike (not Matt) Rattray

Message 3 of 9
bshbsh
in reply to: mrattray

That's what I tried first of course, but the OccurenceNames are all good and "up to date". It's just the browser that displays the name of the old replaced parts still.

Message 4 of 9
mrattray
in reply to: bshbsh

Have you tried the Document.DisplayName or Document.DisplayNameOverridden properties?
Mike (not Matt) Rattray

Message 5 of 9
bshbsh
in reply to: mrattray

yes, the displaynames are all correct after the replacing of parts, and names are not overridden. (or i'm looking at them at the wrong point?)

I made some screenshots, maybe they help.

screenshot1

screenshot2

And this is what the BrowserPane contains:

screenshot2

The Label (2047-03-312) was the old part's name, 2047-03-325 is the part replacing it. Since I havent found this old number anywhere else, only in BrowserNodes, I assumed this is where it needs to be reset. (only if it weren't read only...)

 

Message 6 of 9
mrattray
in reply to: bshbsh

I'm not familiar with the browser (from an API point of view), but I find this odd. I would expect the BrwoserNode.Label to always be equal to the Document.DisplayName.
There is the ClientBrowserNodeDefinition.SetLabel method available in the object browser, but this is uncharted territory for me.
Perhaps we should try a different direction. Maybe the browser needs to be refreshed. There is the BrowserPane.Refesh method. Perhaps we should try this before we dive into the SetLabel method.
Mike (not Matt) Rattray

Message 7 of 9
bshbsh
in reply to: mrattray

already tried the browserpane.refresh (perhaps wrong?), doesn't do anything.

Message 8 of 9
JarFu
in reply to: bshbsh

In your case, BrowserNodeDefinition.Lable should be the same as the corresponding ComponentOccurrence.Definition.Document.DisplayName. Not sure why it shows different now.

 

Maybe we can try set Document.DisplayName to the old one (as current browser node's name), then reset it to the new one to see if browser node can be updated to the new one.



Jar Fu
SW Engineer
Inventor QA
Autodesk, Inc.
Message 9 of 9
bshbsh
in reply to: JarFu

Thanks for the tip.

While it won't work that simple (document.displayname must be tampered with occurrence index, etc.), this lead me to the right direction and now I have a semi-working script (which is rather simple too!)

I've attached it if anyone is interested.

Basically it works through all componentdefinition.occurrences, gets their name (which already has the sequence number in it), then gets the browsernode for this occurrence and gets the label (which stores the old part's name).

If the two are different, then it changes the occurrence name of the object, then changes it to the actual document name.

The key here is the change of the occurrence name. Simply re-applying the occurrence name to itself is not enough, there must be a change in it. I guess this triggers the OnBrowserNodeLabelEdit event, which somehow does not trigger when the part is replaced in the assembly.

Anyway, this is working quite good, except for one thing: If the part is manually renamed in the browser tree, this script will not reset its name. But this is just a minor annoyance, we don't often rename things in the browser. (But if there's an easy workaround for this, that'd be welcome!)

Thanks for the help so far.

 

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

Post to forums  

Autodesk Design & Make Report