Rule to Copy File Name to Description, Assembly Level

Rule to Copy File Name to Description, Assembly Level

emanuel.c
Collaborator Collaborator
355 Views
2 Replies
Message 1 of 3

Rule to Copy File Name to Description, Assembly Level

emanuel.c
Collaborator
Collaborator

I have this rule to copy file name to description for all parts and subassemblies in an assembly. However, at the end of the description I also get the occurrence number, such as ":2" if the part is used twice in an assembly. How can I copy only the filename?

Thank you!

 

'For each occurence in an assembly copy file name to description

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

'Iterate through all of the occurrences in the assembly
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
    Dim oName As String
    oName = oOccurrence.Name
    'Fill in part Description from File Name
	iProperties.Value(oOccurrence.Name, "Project", "Description") = oName
Next

 

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

A.Acheson
Mentor
Mentor
Accepted solution

Here is a post that deals with that but trying to use it in a different way. 

The (0) in the array represents the first segment of the string, if you type (1) you get the second segment. 


The snippet for your purpose. 

oName = oOccurrence.Name
oNameArray = Split(oName, ":") oName = oNameArray(0) Try iProperties.Value(oOccurrence.Name, "Project", "Description") = oName
Catch
End Try

 
You can also find that function by declaring oName as string and get split in the drop down. 

Some more info on string functions

https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/functions/string-functions

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 3

emanuel.c
Collaborator
Collaborator
That's beautiful and thank you for the link! A lot of good info there.
0 Likes