Rule works, but still getting an error?!

Rule works, but still getting an error?!

CDuPlessisTQEZQ
Enthusiast Enthusiast
7,715 Views
6 Replies
Message 1 of 7

Rule works, but still getting an error?!

CDuPlessisTQEZQ
Enthusiast
Enthusiast

Hi Everyone.

 

Again, I don't know coding all that much but like creating little tools for now until I know how to properly code.

 

I have a piece of code that works, but I still get an error message... I'm using Inventors iLogic, no other coding or so.

I know Inventors iLogic is based of VB.NET, but I don't know how the build-in coding of iLogic and VB.NET coding is exactly the same.

 

Currently, my problem is this piece of code:

ThisApplication.ActiveDocument.PartComponentDefinition.ClearAppearanceOverrides

The Error message I get is this:

 Public member 'PartComponentDefinition' on type '_DocumentClass' not found.

 

Now, the code I have is that once I select the "Default" appearance in a multi-value Parameter, the code should run and if it's default appearance, it should remove all appearance overrides and be the default appearance value of the material used.

It does work and does reset the apprearance to the materials default value. Yet, I get and error message.

 

More info bellow:

CDuPlessisTQEZQ_0-1736417494305.pngCDuPlessisTQEZQ_1-1736417528710.png

Full code list:

'This code is to update the Cut Size, be it SHS or RHS
If RH_HGTH = RH_WDTH Or RH_WDTH = RH_HGTH Then
	iProperties.Value("Project", "Description") = RH_WDTH & " X " & RH_WDTH & " X " & RH_WTHK & " THK SHS X " & RH_LGTH & " LG"
Else 
	iProperties.Value("Project", "Description") = RH_WDTH & " X " & RH_HGTH & " X " & RH_WTHK & " THK RHS X " & RH_LGTH & " LG"
End If

'This code is to change the material of the HS section
Parameter.UpdateAfterChange = True
If PART_MATERIAL = "STAINLESS - 304" Then
	iProperties.Material = "S/S 304"
Else If PART_MATERIAL = "STAINLESS - 304 2B" Then
	iProperties.Material = "S/S 304 2B"
Else If PART_MATERIAL = "STAINLESS - 304 SATIN" Then
	iProperties.Material = "S/S 304 SATIN"
Else If PART_MATERIAL = "MILD STEEL" Then
	iProperties.Material = "STEEL MILD"
Else If PART_MATERIAL = "GENERIC" Then
	iProperties.Material = "GENERIC"
End If

'This code is to change the appearance of the part
Dim sName As String = ""
Select Case Parameter("PART_APPEARANCE")
	Case "POLISHED"
		sName = "Semi-Polished"
	Case "TRANSPARENT"
		sName = "Clear"
	Case "RED"
		sName = "Orange-Red"
	Case "BLUE"
		sName = "Blue - Wall Paint - Glossy"
	Case "GREEN"
		sName = "Dark Green"
	Case "BLACK"
		sName = "Anodized - Black"
	Case "YELLOW"
		sName = "Yellow"
	Case "VIOLET"
		sName = "Violet"
	Case "DEFAULT"
		' Get the current material of the part
		'Dim oMaterial As Material = ThisApplication.ActiveDocument.ComponentDefinition.Material
		
		' Reset the appearance to the default for the current material
		'ThisApplication.ActiveDocument.ComponentDefinition.Appearance = oMaterial.Appearance
		
		ThisApplication.ActiveDocument.PartComponentDefinition.ClearAppearanceOverrides

		'sName = "Default"
				
End Select
iProperties.PartColor = sName
0 Likes
7,716 Views
6 Replies
Replies (6)
Message 2 of 7

marcin_otręba
Advisor
Advisor

hi,

 

change 

ThisApplication.ActiveDocument.PartComponentDefinition.ClearAppearanceOverrides

to

 

ThisApplication.ActiveDocument.ComponentDefinition.ClearAppearanceOverrides

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

Message 3 of 7

Michael.Navara
Advisor
Advisor

Hi @CDuPlessisTQEZQ 

This is because the line should be:

ThisApplication.ActiveDocument.ComponentDefinition.ClearAppearanceOverrides

 

Message 4 of 7

CDuPlessisTQEZQ
Enthusiast
Enthusiast
Still getting an error. The part does revert back to the materiel's default appearance, but I now get this error:
The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

0 Likes
Message 5 of 7

Michael.Navara
Advisor
Advisor

In case "DEFAULT" you try to set iProperties.PartColor = sName where sName is empty string which is not valid value.

0 Likes
Message 6 of 7

CDuPlessisTQEZQ
Enthusiast
Enthusiast

sName currently as per the code is greyed out with ' symbol and not running that piece of the code. the only code running in the default case is this:

ThisApplication.ActiveDocument.PartComponentDefinition.ClearAppearanceOverrides
0 Likes
Message 7 of 7

WCrihfield
Mentor
Mentor

Just dropping in an extra tip...

When you want to set a model document's appearance back to its 'default' (the appearance specified by its 'active' material), using the ClearAppearanceOverrides method can definitely be useful, but is more for when you have been assigning different appearances to different faces, bodies, features, and such independently, because it will go through all those types of entities, setting them back.  However, if you have not been setting all those individual entities to different appearances, and have just changed the overall appearance of the whole part, then there is a simpler way to set that main, document level appearance back to its default, which does not require digging down into the ComponentDefinition or even calling a method.  You can simply set the value of the PartDocument.ActiveAppearance property using the keyword 'Nothing' (not an empty String, or variable without a value).  That will effectively remove the document level appearance override, and set it back to the appearance defined by the active material.

 

Another similar tactic, but with an extra step, and property access, would be to set the following:

oPDoc.ActiveAppearance = oPDoc.ActiveMaterial.AppearanceAsset

or, you can use two lines of code for that step, to maintain IntelliSence object Type recognition:

Dim oActiveMaterial As MaterialAsset = oPDoc.ActiveMaterial
oPDoc.ActiveAppearance = oActiveMaterial.AppearanceAsset

(...where the variable 'oPDoc' in those example codes represents the PartDocument object.)

Wesley Crihfield

EESignature

(Not an Autodesk Employee)