Inventor Vb.Net "AddIn" - Syntax Error

Inventor Vb.Net "AddIn" - Syntax Error

isocam
Collaborator Collaborator
215 Views
2 Replies
Message 1 of 3

Inventor Vb.Net "AddIn" - Syntax Error

isocam
Collaborator
Collaborator

Can anybody help?

 

I have the following code that is part of a larger Vb.Net "Addin".

 

Sub SetPartMaterialProperty(PartMaterial)
       Dim oMaterial As Material

       oMaterial = m_inventorApplication.Activedocument.PropertySets.Item(PartMaterial)

       m_inventorApplication.Activedocument.ComponentDefinition.Material = oMaterial
End Sub

 

I am trying to automatically set the material of an Inventor part, by specifying the part material, but I cannot get it to work.

 

(For example, set the part material to "Brass, Soft Yellow")

 

Can anybody update the above sub-routine for me so that it works correctly?

 

Many thanks in advance!

 

Darren

0 Likes
216 Views
2 Replies
Replies (2)
Message 2 of 3

lmc.engineering
Advocate
Advocate

Hi @isocam 

 

you can make use of the Materal.Name property here, as below:

 

Sub SetPartMaterialProperty(PartMaterial As String)
	Dim activeDoc As Document = m_inventorApplication.ActiveDocument
	If TypeOf activeDoc Is PartDocument Then
		Dim Doc As PartDocument = CType(activeDoc, PartDocument)
		Dim def As PartComponentDefinition = Doc.ComponentDefinition
		Try
			def.Material.Name = PartMaterial
		Catch ex As Exception
			Console.WriteLine("Cannot find the material '" & PartMaterial & "'")
		End Try
	Else
		Console.WriteLine("Active document is not a part")
		Return
	End If
End Sub
0 Likes
Message 3 of 3

lmc.engineering
Advocate
Advocate

I should also add, you can also do it like this, which ensures the appearance updates to the default for that material:

Swap this;

def.Material.Name = PartMaterial

with;

def.Material = Doc.Materials.Item(PartMaterial)

 

0 Likes