Change Material with vb.net doesen't work

Anonymous

Change Material with vb.net doesen't work

Anonymous
Not applicable

Hi all,

I'm trying to set automaticly the Material in a mirrored sheetmetalpart. I whrote a VBA-code like:

...

Dim orefMat As String
orefMat = orefdoc.ComponentDefinition.Material.Name
Dim oMaterial As Material
Set oMaterial = odoc.Materials.Item(orefMat)
ocompdef.Material = oMaterial

 

this code worked. Now the next step is coding in vb.net and VisualStudio 2017.

I've tried the same method "ocompdef.Material = oMaterial" but in VS this doesen't work. In debugging-mode I got the message: Member not not found.

 

Thanks for helping

Greatings

Steffen

 

0 Likes
Reply
Accepted solutions (1)
714 Views
3 Replies
Replies (3)

HideoYamada
Advisor
Advisor

Hello Steffen,

 

Use Material Assets instead of Materials.

 

This code works in VBA and will work VB.net.

Sub test()
    Dim partDoc As PartDocument
    Dim refDoc As PartDocument
    
    Set partDoc = ThisApplication.ActiveDocument
    Set refDoc = partDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents(1).ReferencedDocumentDescriptor.ReferencedDocument
        
    Dim newMaterialAsset As MaterialAsset
    
    ' This line will fail when the material asset already exists in partDoc.
    Set newMaterialAsset = refDoc.ActiveMaterial.CopyTo(partDoc)
    
    partDoc.ActiveMaterial = newMaterialAsset
End Sub

Open the part document which contains the derived part (mirror derived part), and run this.

 

Best regards,

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes

bradeneuropeArthur
Mentor
Mentor
Accepted solution

Hi,

 

Try this:

 Dim oInvActPartDoc As Inventor.PartDocument '= Nothing
        oInvActPartDoc = m_InventorApplication.ActiveDocument
        If Not oInvActPartDoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then
            Exit Sub
        End If
		
		Dim orefMat As String
			orefMat = orefdoc.ComponentDefinition.Material.Name

        If Not oInvActPartDoc.ComponentDefinition.Material.Name = oInvActPartDoc.Materials.Item(orefMat).Name Then
            oInvActPartDoc.ComponentDefinition.Material = oInvActPartDoc.Materials.Item(orefMat)
        End If

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes

Anonymous
Not applicable

Thanks, I found the error🤐

 

Many thanks for the quick response.

 

Greatings

Steffen

0 Likes