Clear all appearance overrides in part with ilogic?

Clear all appearance overrides in part with ilogic?

Anonymous
Not applicable
5,033 Views
18 Replies
Message 1 of 19

Clear all appearance overrides in part with ilogic?

Anonymous
Not applicable

Hey,

I have a very big list of parts, all these parts need their appearance overrides cleared. I've tried the solution in this thread, but it didn't work (no overrides were deleted).

 

Thanks in advance

 

Stijn

0 Likes
5,034 Views
18 Replies
Replies (18)
Message 2 of 19

Jef_E
Collaborator
Collaborator

So, correct me if i'm wrong you want to clear the override for all parts / assemblies from the top assembly level?



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
Message 3 of 19

Anonymous
Not applicable

No there is no assembly,

It's just a lot of seperate parts in a folder. They are not linked to eachother. I want to write a rule that does it for me.

0 Likes
Message 4 of 19

Jef_E
Collaborator
Collaborator

Okay, I created a small iLogic rule that does this for you, you just need to point it too the right directory, change the value marked in red.

 

To run the rule create a empty part file, create a new iLogic rule and paste the code. Adjust the text marked in red and your ready.

 

Imports System.IO

Sub Main

' Set the directory
Dim oDirectoryPath As String
oDirectoryPath = "C:\Temp\"

' Get the directory info
Dim oDirectoryInfo As New DirectoryInfo(oDirectoryPath)

' Create collection to hold all part files from the directory
Dim oFiles As IO.FileInfo()
oFiles = oDirectoryInfo.GetFiles("*ipt")

' Set a counter for the end message
Dim oCount As Integer = 0

' Set reference to the inventor documents
Dim oDocs As Documents
oDocs = ThisApplication.Documents

' Loop all the files
For Each oFile As FileInfo In oFiles
	
	' Set reference to the file
	Dim oDoc As PartDocument
	oDoc = oDocs.Open(oFile.FullName, True)
	
	' Set the appearance Source Type
	oDoc.AppearanceSourceType = AppearanceSourceTypeEnum.kMaterialAppearance
		
	' Save the document
	oDoc.Save

	' Close the document
	oDoc.Close
	
	' Add to the counter
	oCount += 1

Next

' Finish message
MsgBox("Number of files processed = " & oCount)

End Sub

Sorry if I spoiled the fun of writing the code yourself? It seemed to me you were asking more for a solution than help writing the code. ( correct me if i'm wrong )

 

NOTE this code only works for part files that have read/write permissions ( so files checked-in into vault will cause an error, if the files are vaulted please check them out before running the code )



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
Message 5 of 19

Anonymous
Not applicable

Wow, thank you for the quick and extensive reply, you helped me alot already.

The rule runs fine and opens and closes every part, but the overrides are not deleted.

I'm sorry but there is one thing that I forgot to add, that might cause the problem; The files are not part files (ipt), but ".IGS" files. I changed the "*ipt" to "*IGS" but the overrides are not being deleted.

0 Likes
Message 6 of 19

Anonymous
Not applicable

Just for testing puposes, I opened and saved some of the files as ipt, and tried to run the original rule. It didnt delete the overrides. So apparently the fact that the files are IGS doesnt matter.

 

This is what I mean by clearing/deleting the appearance overrides:

Untitled.png

Then I click "Select all" --> "Ok"

Message 7 of 19

Jef_E
Collaborator
Collaborator

Well... thats just wow.. you speak of parts, and in Inventor partdocuments are .ipt 😉

 

What version of Inventor are you using? I used a function available since 2014 which should work..

 

 

See spoiler for reference to API page

 

 

Spoiler

PartDocument.AppearanceSourceType Property

Parent Object: PartDocument

Description

Gets and sets the source of the appearance for the part. Setting to kMaterialAppearance will clear appearance override so the document uses the appearance associated with the active material.

Syntax

PartDocument.AppearanceSourceType() As AppearanceSourceTypeEnum

Version

Introduced in Inventor version 2014

 

 

 



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
Message 8 of 19

Anonymous
Not applicable

I am using Inventor Professional 2016

0 Likes
Message 9 of 19

Jef_E
Collaborator
Collaborator

I checked it for me, and it works on Inventor 2014. I don't know if there is a change in the appearance API since 2014?

 

Maybe someone else can fill that in, but for me this is the best working solution I can give as it works seamless at my end.



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
Message 10 of 19

Anonymous
Not applicable

Maybe it's the file? Can I send you one of the files so you can try?

0 Likes
Message 11 of 19

Jef_E
Collaborator
Collaborator

Sure, attach a file and I will check.



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
Message 12 of 19

Anonymous
Not applicable

Hey, sorry for my late response. I thought I replied but the post didn't go through or something.

I've attached a file for you to look at, it's an IPT file because I can't attach IGS files. (I opened the IGS and saved it as IPT)

 

Thank you

0 Likes
Message 13 of 19

Curtis_Waguespack
Consultant
Consultant

Hi stijn_paardekooper,

 

I only skimmed though this discussion, but here is an example that I use. I run it from an assembly and it strips the overrides for each part, and for the assembly file. I've used this in Inventor 2015, but I don't recall if I've tested this in Inventor 2016 or 2017 yet.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Trace.WriteLine("Strip Color OverRides", "iLogic") 'debug 

Dim oAssyDoc As AssemblyDocument
oAssyDoc = ThisApplication.ActiveDocument
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = oAssyDoc.ComponentDefinition
Dim oOcc As ComponentOccurrence
 
'strip color overrides at the assembly level	
For Each oOcc In oAssyDoc.ComponentDefinition.AppearanceOverridesObjects
	oOcc.AppearanceSourceType = 100612 'kPartAppearance
Next


'strip color overrides at the part level
For Each oOcc In oAsmCompDef.Occurrences.AllLeafOccurrences
    oDef = oOcc.Definition'.Document 
	oDef.Material.UpdateFromGlobal
	oDef.Document.AppearanceSourceType = 100614 'kMaterialAppearance 
	'Trace.WriteLine(oOcc.Name, "iLogic") 'debug 
	 For Each obj In oDef.AppearanceOverridesObjects
		'strip color overrides at the feature level
		If TypeOf obj Is SurfaceBody Then
            obj.AppearanceSourceType = 100612 'kPartAppearance
			'Trace.WriteLine(obj.Name, "iLogic") 'debug 
        ElseIf TypeOf obj Is PartFeature Then
            obj.AppearanceSourceType = 100612 'kPartAppearance
			'Trace.WriteLine(obj.Name, "iLogic") 'debug 
        ElseIf TypeOf obj Is Face Then
            obj.AppearanceSourceType = 100612 'kPartAppearance
			'Trace.WriteLine("Face", "iLogic") 'debug 
        Else
        End If
    Next
	'Purge Appearances And Materials
	'By Adam Nagy
	'http://adndevblog.typepad.com/manufacturing/2015/10/purge-appearances-and-materials.html
	Dim oDoc As PartDocument
	oDoc = oOcc.Definition.Document 
	
	' There can be references between assets,
	' so keep doing it until only used things remain
	Dim foundUnused As Boolean
	Do
		foundUnused = False
		Dim a As Asset
		For Each a In oDoc.Assets
			If Not a.IsUsed Then
			a.Delete
			foundUnused = True
			End If
		Next
	Loop While foundUnused
	
Next


	 

EESignature

Message 14 of 19

Anonymous
Not applicable

Hey,

Thanks for you reply. The code doesn't work for me, or at least doesn't do what I want it to do.

Have you tried it with the attached ipt file? Maybe it works for you

 

 

0 Likes
Message 15 of 19

Jef_E
Collaborator
Collaborator

Please attach the .igs file by zipping it. Then you can upload it.. I can't open Inventor 2016 files I am only capable to open up to 2014.



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
Message 16 of 19

Luisfmts
Enthusiast
Enthusiast

Jesus...how could i think about iLogic when I had a pretty easy solution like this and Styles Editor Purge/Update!? Smiley LOL

0 Likes
Message 17 of 19

Anonymous
Not applicable

Would it be a lot of work for someone familiar with Ilogic, to modify this code so it runs only on "selected" parts (not on ALL)?

 

https://forums.autodesk.com/t5/inventor-customization/clear-all-appearance-overrides-in-part-with-il...

0 Likes
Message 18 of 19

RoyWickrama_RWEI
Advisor
Advisor

Thanks for your posting. It improved my iLogic knowledge.

In my coding, I used the following to restore part color:

oDoc.AppearanceSourceType = AppearanceSourceTypeEnum.kMaterialAppearance

But, I now need to assign color (say Steel).

Could you help me to get around this.

 

Capture.PNG

look forward to receiving help.

Message 19 of 19

D.Motshagen
Contributor
Contributor

@RoyWickrama_RWEIThanks, this was what I was looking for!

 

To clear the override in a part:

DMotshagen_0-1661430094147.png

 

use this code in a part.

It is so simple.

 

 

'clear override in a part
'Found at: https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/clear-all-appearance-overrides-in-part-with-ilogic/m-p/8226065/highlight/true#M88140

Dim oDoc As PartDocument 
 	oDoc = ThisApplication.ActiveDocument 
oDoc.AppearanceSourceType = AppearanceSourceTypeEnum.kMaterialAppearance

 

0 Likes