Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

iLogic: Find parts with certain appearance

Anonymous

iLogic: Find parts with certain appearance

Anonymous
Not applicable

I have a huge assembly with many sub assemblies and hundreds of parts. Some appearances are redundant and I would like to find all parts which contain a certain appearance (by name), either applied to a surface or the entire part.

 

How do do this in iLogic, so that I provide the name of the appearance and it spits out a list of all parts which contain that appearance?

0 Likes
Reply
Accepted solutions (1)
1,376 Views
7 Replies
Replies (7)

pball
Advisor
Advisor

The code from this post will get you most of the way to what you are trying to do. It goes through each part in an assembly and gets the appearance of every face. You'll just have to replace the code that is adding up the surface area to check for and create a list of parts that match the input.

If I have time later I'll put something together but here is the post.

http://forums.autodesk.com/t5/inventor-forum/how-do-i-get-inventor-to-calculate-and-sum-up-painted-f...

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes

Anonymous
Not applicable

Thanks, that should get me started.

0 Likes

Anonymous
Not applicable

So far I have this code which outputs all appearances found in a separate messagebox each (from parts in an assembly).

 

'Define the open document
Dim openDoc As Document
openDoc = ThisDoc.Document

'Create a dictionary which will be used to store the appearances
Dim Appearances As Object
Appearances = CreateObject("Scripting.Dictionary")

'Look at all of the files referenced in the open document
Dim docFile As Document
For Each docFile In openDoc.AllReferencedDocuments

'format file name
Dim FNamePos As Long
FNamePos = InStrRev(docFile.FullFileName, "\", -1)
Dim docFName As String
docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos)

'Get the part faces
Dim oFaces As Faces
oFaces = docFile.ComponentDefinition.SurfaceBodies(1).Faces

'Loop through each face and store the appearance in the dictionary
Dim oFace As Face
For Each oFace In oFaces
Appearances(oFace.Appearance.DisplayName) = Appearances(oFace.Appearance.DisplayName)
Next

'Display the contents of the dictionary
For Each Item In Appearances
MessageBox.Show("Part: " & docFName & vbLf & "Appearance: " & Item)
Next
Next

However, I am not sure how to make a form where I can input an appearance name and then format the dictionary so it displays only the parts which contains that appearance.

 

Any ideas?

0 Likes

Anonymous
Not applicable

Ok, it kind of made it work. The code below just shows one messagebox with all parts which contain one or more of the appearance provided. You can change the appearance name at the first line. Not too user friendly but at least it is easier to install and distribute then a form. If you have a better idea, please do let me know.

 

Dim appearanceToFind As String = "Default"

'Define the open document
Dim openDoc As Document
openDoc = ThisDoc.Document

'Create a dictionary which will be used to store the appearances
Dim Appearances As Object
Appearances = CreateObject("Scripting.Dictionary")

'Look at all of the files referenced in the open document
Dim docFile As Document
For Each docFile In openDoc.AllReferencedDocuments

'format file name
Dim FNamePos As Long
FNamePos = InStrRev(docFile.FullFileName, "\", -1)
Dim docFName As String
docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos)

'Get the part face
Dim oFaces As Faces
oFaces = docFile.ComponentDefinition.SurfaceBodies(1).Faces

'Loop through each face and store the part in the dictionary if the appearance matches
Dim oFace As Face
For Each oFace In oFaces
If appearanceToFind = oFace.Appearance.DisplayName Then
Appearances(docFName) = Appearances(docFName)
End If
Next
Next

Dim partList As String

'Display the contents of the dictionary
For Each Item In Appearances
partList += Item + vbLf
Next

MessageBox.Show("Parts found with appearance " & appearanceToFind & ":" & vbLf & partList)

bshbsh
Collaborator
Collaborator

I would put an Exit For into the "For Each oFace..." cycle once the first face appearance is found. No need to check the rest of the faces I guess, it's pretty slow.

Another approach what might work is: purge all unused appearances in the main assembly INCLUDING all occurrences. then only go through all documents and check if the appearance is still in there - meaning it is used somewhere in the part. This should be much faster than going through faces I think.

Anonymous
Not applicable

An exit in the for loop is a good idea!

 

I find the appearance purge function very buggy though. One time after a purge, it deleted all appearance overrides in all assemblies. The effect of this was that an appearance showed sometimes correctly in the assembly (inconsistent), but the appearance was not present in the appearance browser - document appearances (of the assembly). When importing the assembly into 3ds Max, all appearance overrides are lost. This makes purging both unreliable for checking if an appearance is present, and it makes it unusable as fixing this problem caused me a whole day work.

 

Anyway, I will implement the for loop exit.

0 Likes

Anonymous
Not applicable
Accepted solution

Here is a version which does some error checking (previous version could throw an error) and is a bit faster. It also prints the output into a text file.

 

Dim appearanceToFind As String = "Axe grip"

'Define the open document
Dim openDoc As Document
openDoc = ThisDoc.Document

'Create a dictionary which will be used to store the appearances
Dim Appearances As Object
Appearances = CreateObject("Scripting.Dictionary")

'Look at all of the files referenced in the open document
Dim docFile As Document
For Each docFile In openDoc.AllReferencedDocuments

'format file name
Dim FNamePos As Long
FNamePos = InStrRev(docFile.FullFileName, "\", -1)
Dim docFName As String
docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos)

'Get the part face
Dim oFaces As Faces

'Only look at part files
If docFile.DocumentType = kPartDocumentObject Then
Try
oFaces = docFile.ComponentDefinition.SurfaceBodies(1).Faces
Catch ex As Exception
End Try
End If

'Loop through each face and store the part in the dictionary if the appearance matches
Dim oFace As Face
For Each oFace In oFaces
If appearanceToFind = oFace.Appearance.DisplayName Then
Appearances(docFName) = Appearances(docFName)
Exit For
End If
Next
Next

Dim partList As String

'Gather the contents of the dictionary
For Each Item In Appearances
partList += Item + vbCrLf
Next

'MessageBox.Show("Parts found with appearance " & appearanceToFind & ":" & vbLf & partList)

oWrite = System.IO.File.CreateText(ThisDoc.PathAndFileName(False) & " parts with appearance" & ".txt")
oWrite.WriteLine(partList)
oWrite.Close()
0 Likes