Clear All Overrides tick box

Clear All Overrides tick box

lyndon
Explorer Explorer
461 Views
4 Replies
Message 1 of 5

Clear All Overrides tick box

lyndon
Explorer
Explorer

Hello,

I want to tick the box for clear all overrides on solid bodies properties using iLogic.

 

I been using oSurfaceBody.ClearAppearanceOverrides() for some year but it seems to not work via code until you go into the solid properties an tick the box while applying the appearance.

 

Shouldn't this tickbox be a Boolean parameter? true as ticked and false and left unticked?

 

 

Normally I use this code:

 

 

 

Dim Doc_P As PartDocument = ThisDoc.Document
Dim oDoc_P_Def As ComponentDefinition = Doc_P.ComponentDefinition

Dim Colour_1 As Asset
Dim oSurfaceBody As SurfaceBody
Dim oSurfaceBodies As WorkSurface

Colour_1 = Doc_P.Assets.Item("Default") 

For s = 1 To  oDoc_P_Def.SurfaceBodies.Count
oSurfaceBody = oDoc_P_Def.SurfaceBodies(s)
oFeature = oSurfaceBody.CreatedByFeature
oSurfaceBody.ClearAppearanceOverrides()
If InStr(oSurfaceBody.Name, "Front Panel") > 0 Then
'MessageBox.Show(oSurfaceBody.Name, "Front")
oSurfaceBody.Appearance = Colour_1
End If
Next s

InventorVb.DocumentUpdate()

 

 

0 Likes
462 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Hi @lyndon.  Since all visibility, colors, & appearances settings are stored in the DVR's (DesignViewRepresentations), it sounds reasonable to effectively clear appearance overrides from there.  Below is a simple example of that.

Dim oPDoc As PartDocument = ThisDoc.Document
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
oPDef.RepresentationsManager.ActiveDesignViewRepresentation.RemoveAppearanceOverrides

...However, if you only want to clear appearance overrides on SurfaceBody objects, below is another way of doing it.

Dim oPDoc As PartDocument = ThisDoc.Document
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim oBodyCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
For Each oBody As SurfaceBody In oPDef.SurfaceBodies : oBodyCol.Add(oBody) : Next
'if you do not provide any input, it will clear all appearance overides in design view
oPDef.ClearAppearanceOverrides(oBodyCol)

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

lyndon
Explorer
Explorer

Tried as a body collection but the code does not work. Still have to manually tick the box.

 

Below is the code used for testing, even if you skip the second time I override the solid bodies its still not working.

 

Code:

Dim oPDoc As PartDocument = ThisDoc.Document
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
'oPDef.RepresentationsManager.ActiveDesignViewRepresentation.RemoveAppearanceOverrides


Dim Colour_1 As Asset
Dim T_Colour_Asset As Asset
Dim M_Colour_Asset As Asset
Dim B_Colour_Asset As Asset
Dim oFeature As PartFeature

Dim oSurfaceBody As SurfaceBody
Dim oSurfaceBodies As WorkSurface
Dim oSurf_body As SurfaceBody
Dim oWorkSurface As WorkSurface



Dim oBodyCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
For Each oBody As SurfaceBody In oPDef.SurfaceBodies : oBodyCol.Add(oBody) : Next
'if you do not provide any input, it will clear all appearance overides in design view
oPDef.ClearAppearanceOverrides(oBodyCol)


InventorVb.DocumentUpdate()


'GoTo Skip_1


If InStr(Parameter("HDPE_Colours"), "/") > 0 Then
Colours_Mixed = Parameter("HDPE_Colours")
T_Colour = (Left(Colours_Mixed, InStr(Colours_Mixed, "/") -1))
B_Colour = (Right(Colours_Mixed, Len(Colours_Mixed) -InStrRev(Colours_Mixed, "/")))
M_Colour = Left(Colours_Mixed, Len(Colours_Mixed) -Len(Left(Colours_Mixed, InStr(Colours_Mixed, "/") -1)) -1)
M_Colour = (Right(M_Colour, Len(M_Colour) -InStrRev(M_Colour, "/")))
'MessageBox.Show(T_Colour + " HDPE" & vbCr & M_Colour + " HDPE" &  vbCr & B_Colour + " HDPE")
Front_Colour = T_Colour + " HDPE"
Middle_Colour = M_Colour + " HDPE"
Back_Colour = B_Colour + " HDPE"
T_Colour_Asset = oPDoc.Assets.Item(Front_Colour) 
M_Colour_Asset = oPDoc.Assets.Item(Middle_Colour)
B_Colour_Asset = oPDoc.Assets.Item(Back_Colour)	
'MessageBox.Show(T_Colour + " HDPE" & vbCr & M_Colour + " HDPE" &  vbCr & B_Colour + " HDPE")
Else
Front_Colour = Parameter("HDPE_Colours")
Middle_Colour = Parameter("HDPE_Colours")
Back_Colour = Parameter("HDPE_Colours")
T_Colour_Asset = oPDoc.Assets.Item(Front_Colour) 
M_Colour_Asset = oPDoc.Assets.Item(Middle_Colour)
B_Colour_Asset = oPDoc.Assets.Item(Back_Colour)	
End If



For s = 1 To  oPDef.SurfaceBodies.Count
oSurfaceBody = oPDef.SurfaceBodies(s)
oFeature = oSurfaceBody.CreatedByFeature
If InStr(oSurfaceBody.Name, "Front Panel") > 0 Then
oSurfaceBody.ClearAppearanceOverrides
oSurfaceBody.Appearance = T_Colour_Asset
'Feature.Color(oFeature.Name) = T_Colour_Asset.Name
ElseIf InStr(oSurfaceBody.Name, "Middle Panel") > 0 Then
oSurfaceBody.ClearAppearanceOverrides
oSurfaceBody.Appearance = M_Colour_Asset
'Feature.Color(oFeature.Name) = M_Colour_Asset.Name
ElseIf InStr(oSurfaceBody.Name, "Back Panel") > 0 Then
oSurfaceBody.ClearAppearanceOverrides
oSurfaceBody.Appearance = B_Colour_Asset
'Feature.Color(oFeature.Name) = B_Colour_Asset.Name
End If
Next s

Skip_1 :
InventorVb.DocumentUpdate()

 

0 Likes
Message 4 of 5

J-Camper
Advisor
Advisor

@lyndon,

 

Try setting the AppearanceSourceType like this:

Dim pDoc As PartDocument = TryCast(ThisApplication.ActiveDocument, PartDocument)
If IsNothing(pDoc) Then Logger.Debug("Not Run In Part Document") : Exit Sub

Dim oTransMan As TransactionManager = ThisApplication.TransactionManager
Dim oTrans As Transaction = oTransMan.StartTransaction(pDoc, "Clear Overridden Appearances")
On Error GoTo Errrr

For Each sb As SurfaceBody In pDoc.ComponentDefinition.SurfaceBodies
	If sb.AppearanceSourceType <> AppearanceSourceTypeEnum.kOverrideAppearance Then Continue For
	sb.AppearanceSourceType = AppearanceSourceTypeEnum.kPartAppearance
	oTransMan.SetCheckPoint()
Next

oTrans.End
	
Exit Sub

Errrr :
Logger.Debug("Error in: " & oTransMan.CurrentTransaction.DisplayName)
If oTransMan.CurrentTransaction.CheckPoints.Count < 1 Then Logger.Debug("Aborted: " & oTransMan.CurrentTransaction.DisplayName) : oTransMan.CurrentTransaction.Abort 
oTransMan.GoToCheckPoint(oTransMan.CurrentTransaction.CheckPoints.Item(oTransMan.CurrentTransaction.CheckPoints.Count))
oTransMan.CurrentTransaction.End

 

Let me know if you have any questions, or if this is not working as intended.

0 Likes
Message 5 of 5

lyndon
Explorer
Explorer
0 Likes