Change iproperty weld material

Change iproperty weld material

Cadkunde.nl
Collaborator Collaborator
2,388 Views
8 Replies
Message 1 of 9

Change iproperty weld material

Cadkunde.nl
Collaborator
Collaborator

You can get iproperty "weld Material" in a weldment assembly

which is also discussed here:
https://forums.autodesk.com/t5/inventor-customization/ilogic-read-weldment-material-name/td-p/589196...

 

But I got a form that allows engineers to easily manipulate all iproperties.

In case of a weldment assembly we also want them to chance ' material'  of the assembly from that form.

 

So if I use this:

 

oDoc.PropertySets.Item("Design Tracking Properties").Item("Weld Material").Value = "Steel, Mild"

When i go to: Welds -> iProperties -> Physical -> Material, I still see the old material.

 

But when i open my form again, which on load get:

Me.combobox.selectedItem = oDoc.PropertySets.Item("Design Tracking Properties").Item("Weld Material").Value

 

The value is changed to Steel mild (just an example)

 

So apparently the iProperty("Weld material") did change, but not if you look at Welds -> iProperties -> Physical -> Material.

 

When i change the material manually in Welds -> iProperties -> Physical -> Material, my form responds to it as well on load.

 

This behaviour is different from when you change iproperty material in a part document.

 

Am I doing something wrong or did I stumble upon a bug?

 

You can test this behaviour with this ilogic script:

DTP_PropertySet = ThisDoc.Document.PropertySets.Item("Design Tracking Properties")
oWeldMatl = DTP_PropertySet.Item("Weld Material").Value
MessageBox.Show("Currently:" & oWeldMatl, "iLogic")

DTP_PropertySet.Item("Weld Material").Value = "Steel, Mild"
MsgBox("Now changed to: " & DTP_PropertySet.Item("Weld Material").Value)

Using Inventor 2018.3.8

0 Likes
Accepted solutions (1)
2,389 Views
8 Replies
Replies (8)
Message 2 of 9

chandra.shekar.g
Autodesk Support
Autodesk Support

@Cadkunde.nl,

 

Please provide a non-confidential weldment assembly files to investigate.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 9

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Cadkunde.nl 

I'd guess that in order to change the actual material, it isn't enough to change the iProperty. I believe you'll have to assign the material asset to the WeldmentComponentDefinition.WeldBeadMaterial.

 

See iLogic code below. I find the material in the asset library "Autodesk Material Library", copies it to the documents material assets (if it's not already in there) and then assigns it as WeldBeadMaterial 🙂

 

Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oAsmCompDef As WeldmentComponentDefinition = oAsm.ComponentDefinition
Dim oLibrary As AssetLibrary
oLibrary = ThisApplication.AssetLibraries.Item("Autodesk Material Library")

Dim oMaterial As Asset = oLibrary.MaterialAssets.Item("Steel, Mild")
Try
oMaterial = oMaterial.CopyTo(oAsm)
Catch
oMaterial = oAsm.Assets.Item(oMaterial.DisplayName)
End Try

oAsmCompDef.WeldBeadMaterial = oMaterial
Message 4 of 9

Cadkunde.nl
Collaborator
Collaborator

Thanks,

 

Changing weldbeadmaterial in weldmentcomponentdefinition did the trick!

Message 5 of 9

Cadkunde.nl
Collaborator
Collaborator

@JhoelForshav 

 

Well the code seemed to work at first.

But it crashes whenever i select a material for the second time.

 

I can change material of weldbead to ' Steel, Mild'  then change it to ' Generic' , If i then change it back to ' Steel, Mild'  Inventor crashes.

 

This is the code I currently use:

 

If oAssyDoc.ComponentDefinition.Type = ObjectTypeEnum.kWeldmentComponentDefinitionObject Then
            GlobalFunctions.SetiProperty("Design Tracking Properties", "Weld Material", Me.ComboBox_MatList.SelectedItem)
            Dim oAsmCompDef As WeldmentComponentDefinition = oAssyDoc.ComponentDefinition
            Dim oMaterial As Inventor.Asset = Nothing
            Try
                For Each Asset As Inventor.MaterialAsset In AddinGlobal.InventorApp.ActiveMaterialLibrary.MaterialAssets
                    If Asset.DisplayName = Me.ComboBox_MatList.SelectedItem Then
                        oMaterial = Asset
                        Exit For
                    End If
                Next
            Catch
                MsgBox("Could not find Material Library")
                Exit Sub
            End Try
            Try
                oMaterial = oMaterial.CopyTo(oAssyDoc)
            Catch ex As Exception
                oMaterial = oAssyDoc.Assets.Item(oMaterial.DisplayName)
            End Try
            If Not IsNothing(oMaterial) Then
                If Not oAsmCompDef.WeldBeadMaterial.DisplayName = oMaterial.DisplayName Then
                    oAsmCompDef.WeldBeadMaterial = oMaterial
                End If
            End If
        End If
0 Likes
Message 6 of 9

Cadkunde.nl
Collaborator
Collaborator

My apologies. Found the problem

Dim oMaterial As Inventor.Asset = Nothing

 Should be

Dim oMaterial As Inventor.MaterialAsset = Nothing

 

Time was running out so I jumped to forum too quickly

Message 7 of 9

JhoelForshav
Mentor
Mentor

I began to write this answer before your last post. Saw that it worked out so I'll just edit this reply to this😁

0 Likes
Message 8 of 9

BLA_fpineda
Enthusiast
Enthusiast

Dear @JhoelForshav and @Cadkunde.nl 

Is unacceptable, you check the solution as solved when the solution doesn't work well.

This detracts the quality of the Autodesk Forum, such as a very good site to find solutions according to solve requirements of our jobs.

 

Let me share the correct solution code working perfectly:

 

Dim oAsm As AssemblyDocument = ThisDoc.Document 
Dim oAsmCompDef As WeldmentComponentDefinition = oAsm.ComponentDefinition

 
Dim oLibrary As AssetLibrary
 
oLibrary = ThisApplication.AssetLibraries.Item("MATERIALS BLASAU")
Dim otxt As String = MATERIAL

 
Dim oMaterial As MaterialAsset = oLibrary.MaterialAssets.Item(otxt)
 
oMaterial.CopyTo(oAsm)

oAsmCompDef.WeldBeadMaterial = oAsm.MaterialAssets(otxt)

Logger.Trace(oAsmCompDef.WeldBeadMaterial.Name)​

 

 You can use a parameter multivalue to manage the material, substituting the string "Steel" to the user parameter Material.

 

Also, if the material is from a custom material library, you can substitute the .Item(1) for the name of the custom library like this .Item("NameOfCustomLibrary")

 

I hope that this info help people like me that spent one working day following some solution.

0 Likes
Message 9 of 9

JhoelForshav
Mentor
Mentor

Hi @BLA_fpineda 

First of all; It's totally acceptable that the original poster marks a solution that solved his problem as an accepted solution. I think that goes without saying...

I find this passive aggressive post of yours somewhat disrespectful, since I've volonteered countless hours of my free time to assist other users in this forum with solutions that I'm sure has helped a lot of people throughout the years.

 

Secondly; Please explain why your solution is better than my original one. I might be missing something but looking at my original solution and yours, side by side, it seems to me that you basically just copied mine and now claims that yours is better. To keep the good quality of this forum up, I think you should've provided some sort of explaination to why yours is better. Why does it work better to get the materialasset by name after CopyTo, when CopyTo already returns the copied materialasset?

 

I did some testing now of my original solution and I could change the WeldBeadMaterial back and forward without any issues whatsoever, so whatever problem you have with my solution, I can't replicate it.

 

To summarize, I find your tone here pretty offensive and I think you should keep that in mind for future posts, but I'm also very curious to know in which scenario my original solution fails and yours doesn't.