- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
BOM materials changing
Is there any way to change the materials in BOM either preferably in iLogic or in API? it should change material of all the applicable parts in an assembly. eg., Requirement is to replace the all parts with "Steel" to "Aliminium".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Here in VBA. This will change material for all parts also in sub-assemblies. Material has to exist in material library.
Dim oApp As Inventor.Application
Set oApp = ThisApplication
Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument
Dim strMaterialName As String
strMaterialName = "Aluminium"
Dim oOcc As ComponentOccurrence
For Each oOcc In oDoc.ComponentDefinition.Occurrences.AllLeafOccurrences
oOcc.Definition.Material = oDoc.Materials.Item(strMaterialName)
Next
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Some Error comes in the Red line Method 'Material' of object 'PartComponentDefinition' failed
Private Sub CommandButton2_Click()
Dim oApp As Inventor.Application
Set oApp = ThisApplication
Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument
Dim strMaterialName As String
strMaterialName = "1.4307"
Dim oOcc As ComponentOccurrence
For Each oOcc In oDoc.ComponentDefinition.Occurrences.AllLeafOccurrences
oOcc.Definition.Material = oDoc.Materials.Item(strMaterialName)
Next
End Sub
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Is there any alternate preferably in iLogic for changing the materials in an iassembly. It shouldn't replace the materials for all the parts except the applicable parts. For eg, It should replace "Aluminium" in place of "Steel". It shouldn't change the other parts with different materials like "Rubber" etc.,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
You can put there condition if material name is "steel" then change material.
To error you got: Do you have material named 1.4307 on your material library?
You can translate vba to ilogic quite easy, just take "set" off from lines. Also "on error resume next is not supported in ilogic, but you can use try-catch-method instead.
It would be also good to put condition that checks that part is not content center component. Through api material can be chaged to library components also...even though it should not be possible.
I haven't used iassemblies very much so I can't answer to this issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Thanks. As I'm new to this iLogic I don't know how write the condition. this code simply puts the material in all occurrences without caring about its previous material. My requirement is to have a conditional replacement like "Steel" in place of "Aluminium".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Here in VBA. This changes material for each component if material is "Aluminium" to "Steel". You can modify your code from this. This also skips standard content center components.Material will be changed for custom content center components.
Dim oApp As Inventor.Application
Set oApp = ThisApplication
Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument
Dim strMaterialNameToChange As String
strMaterialNameToChange = "Aluminium"
Dim strNewMaterialName As String
strNewMaterialName = "Steel"
Dim oOcc As ComponentOccurrence
For Each oOcc In oDoc.ComponentDefinition.Occurrences.AllLeafOccurrences
If oOcc.Definition.Material.name = strMaterialNameToChange And oOcc.Definition.IsContentMember = False Then
oOcc.Definition.Material = oDoc.Materials.Item(strNewMaterialName)
End If
Next
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
There is a problem in this red line.. It simply closes the Inventor without changing any material.
Dim oApp As Inventor.Application
Set oApp = ThisApplication
Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument
Dim strMaterialNameToChange As String
strMaterialNameToChange = "Aluminium"
Dim strNewMaterialName As String
strNewMaterialName = "Steel"
Dim oOcc As ComponentOccurrence
For Each oOcc In oDoc.ComponentDefinition.Occurrences.AllLeafOccurrences
If oOcc.Definition.Material.name = strMaterialNameToChange And oOcc.Definition.IsContentMember = False Then
oOcc.Definition.Material = oDoc.Materials.Item(strNewMaterialName)
End If
Next
I don't know the exact issue. but, Do I need to include any object library?
Sukpal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
No need for any extra object library.
I have used this kind of loop in many cases and never had problem like that. Is your assembly weldment assembly? Or did you try with other assemblies just in case that there's something wrong with iam you tried??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Excellent code. It's working in other assembly. Many thanks..
One more help needed.
Can it be converted in to iLogic?
I tried the same code(Removing 'Set' Property). but here it gives some error like "End of Statement expected". It would be much better if it works in iLogic as well.
Sukpal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The code below seems to work fine with an assembly file.
Sub Main()
Dim oApp As Inventor.Application
oApp = ThisApplication
If ThisApplication.ActiveDocumentType <> kAssemblyDocumentObject Then
MessageBox.Show("ERROR - Active Document is not an assembly document!","iLogic Error")
Exit Sub
End If
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
MessageBox.Show("ASSEMBLY DOCUMENT!","iLogic Debug")
Dim strMaterialNameToChange As String
strMaterialNameToChange = "Aluminium"
Dim strNewMaterialName As String
strNewMaterialName = "Steel"
Dim oOcc As ComponentOccurrence
For Each oOcc In oDoc.ComponentDefinition.Occurrences.AllLeafOccurrences
If oOcc.Definition.Material.Name = strMaterialNameToChange And oOcc.Definition.IsContentMember = False Then
oOcc.Definition.Material = oDoc.Materials.Item(strNewMaterialName)
End If
Next
End Sub
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Unfortunately it's not working for me. gives the same error in iLogic. "End of statement expected" in the below line.
For Each oOcc In oDoc.ComponentDefinition.Occurrences.AllLeafOccurrences
BR
Sukpal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi Asikainen,
For me it's not working unfortunately. It gives error in all lines now.
previously I had only one error in the below line
"For Each oOcc In oDoc.ComponentDefinition.Occurrences.AllLeafOccurrences" that End of statement expected.
BR
Sukpal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Yes dear Yosso. Inventor 2015 only. But I think I may need to include some object library. Please give some solution.
BR
Sukpal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The iLogic code seems to work w/o issues.
http://adndevblog.typepad.com/manufacturing/2013/07/inventor-2014-api-set-part-material.html
Sub Main()
Dim i As Integer
Dim oApp As Inventor.Application
oApp = ThisApplication
If ThisApplication.ActiveDocumentType <> kAssemblyDocumentObject Then
MessageBox.Show("Active document is NOT an assembly document!","DEBUG ME")
Exit Sub
End If
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
Dim strMaterialNameToChange As String
strMaterialNameToChange = "Aluminum 6061"
Dim strNewMaterialName As String
strNewMaterialName = "Steel, Galvanized" '"Aluminum 6061"
Dim oMat As Asset
' MessageBox.Show("ASSEMBLY DOCUMENT!","iLogic Debug")
Dim oOcc As ComponentOccurrence
Dim oPartDoc As PartDocument
Dim newMat As Asset
For Each oOcc In oDoc.ComponentDefinition.Occurrences.AllLeafOccurrences
oPartDoc = oOcc.Definition.Document
For i = 1 To oPartDoc.Assets.Count
If oPartDoc.Assets.Item(i).DisplayName = strNewMaterialName Then
oMat = oPartDoc.Assets.Item(i)
bMatFound = True
' MessageBox.Show("MATERIAL FOUND!","iLogic Debug")
Exit For
End If
Next i
If oPartDoc.ActiveMaterial.DisplayName = strMaterialNameToChange And oOcc.Definition.IsContentMember = False Then
' MessageBox.Show("IN if/then","iLogic Debug")
oPartDoc.ActiveMaterial = oMat
End If
Next
Call oDoc.BrowserPanes.ActivePane.TopNode.DoSelect
End Sub