Ilogic to change name in browser tree

Ilogic to change name in browser tree

amarcoc
Advocate Advocate
4,220 Views
8 Replies
Message 1 of 9

Ilogic to change name in browser tree

amarcoc
Advocate
Advocate

Hi.

 

I want to change the name to default as in the picture.

 

How can it be done with ilogic?

 

Thanks

0 Likes
Accepted solutions (1)
4,221 Views
8 Replies
Replies (8)
Message 2 of 9

Owner2229
Advisor
Advisor
Accepted solution

Here you go:

 

Dim oDoc As Document = ThisApplication.ActiveDocument
oDoc.DisplayName = ""
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 3 of 9

amarcoc
Advocate
Advocate

Wow.

 

That was quick!

 

Thanks. Worked perfect.

0 Likes
Message 4 of 9

Anonymous
Not applicable

How would you do this for subassemblies within an assembly and their parts??

0 Likes
Message 5 of 9

Owner2229
Advisor
Advisor

Hey, like this:

 

Sub Main()
    Dim oDoc As Document = ThisApplication.ActiveDocument
oDoc.DisplayName = "" Dim oCD As ComponentDefinition = oDoc.ComponentDefinition NameReset(oCD.Occurrences) End Sub Sub NameReset(oOccs As ComponentOccurrences) For Each oOcc As ComponentOccurrence In oOccs Try oOcc.Name = "" NameReset(oOcc.SubOccurrences) Catch End Try Next End Sub
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 6 of 9

Anonymous
Not applicable

Thanks for the reply but that doesn't quite do it......

 

That does the top level assembly and the first sub assembly in the tree but none of the parts or subsequent subassemblies - see attached snapshot with Dave and Bob as example names.

0 Likes
Message 7 of 9

Owner2229
Advisor
Advisor

 

Hey, this rule is for name reset only (.Name = "").

The issue you run into is that you can't have 2+ assemblies (parts, etc.) with the exact same name (it's simply not allowed by Inventor).

You'd have to add something like ":1", ":2" at the end of the name.

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 8 of 9

Anonymous
Not applicable

I understand its for resetting the name - I just "bob" and "dave" in there so you could see what the code was doing. 

 

All the subassemblies do have unique file names and so do all their parts. Just so I understand is the code you've written only meant to look at one sub assembly or is it meant to go through all the sub assemblies within an assembly?

 

Thanks!

0 Likes
Message 9 of 9

Owner2229
Advisor
Advisor

It's supposed to reset the names of all sub-assemblies, sub-parts (sub-sub-assemblies and parts etc.) aka parts and assies of all levels.

 

You can try it like this, to see any errors (it might fail to rename something if it's read-only or something.):

 

Sub Main()
    Dim oDoc As Document = ThisApplication.ActiveDocument
oDoc.DisplayName = "" Dim oCD As ComponentDefinition = oDoc.ComponentDefinition NameReset(oCD.Occurrences) End Sub Sub NameReset(oOccs As ComponentOccurrences) For Each oOcc As ComponentOccurrence In oOccs Try oOcc.Name = ""
Catch ex As Exception
MsgBox(ex.Message)
End Try
Try NameReset(oOcc.SubOccurrences) Catch End Try Next End Sub

 

Also are these assies iAssemblies by any chance? I haven't tested it with them, so I'm not sure if it would work properly.

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods