a code to identify by material category

a code to identify by material category

Anonymous
Not applicable
2,119 Views
15 Replies
Message 1 of 16

a code to identify by material category

Anonymous
Not applicable

I need help in order to work this bit out. In our company we have a practice of identifying any metal order with a code S0001. We have recently shifted to Inventor from AutoCAD and desire this feature to be automated when generating a BOM. Basically we need a rule that can put  code against components which use metal as their material category. So say for Example we have a metal post in our assembly then when we are generating the BOM it should automatically identify the metal material and give it a code of S0001. Is it possible? if yes then how. Can someone please help me with this? Thanks in advance

0 Likes
2,120 Views
15 Replies
Replies (15)
Message 2 of 16

philip1009
Advisor
Advisor

First I'll let you know that coding questions like this are better suited for the Inventor Customization forum and don't be surprised if an Admin moves this post to that forum.

 

There are many ways that this can be accomplished.  I think the best way is for you to make a Form that allows you to type in whatever information you need for the part file such as part number and make some selections from a drop down menu for material, then have an iLogic rule make changes to iProperties and Material changes based on selections in that Form.

 

Here's a youtube video talking about the solution I'm suggesting: https://www.youtube.com/watch?v=xGx8hXKaYu8

Message 3 of 16

jtylerbc
Mentor
Mentor

@Anonymous,

 

"Metal" sounds rather vague.  Do you actually use the same "S0001" code for all metals, whether that means cast iron, steel, gold, titanium, and so on?  Or do different materials get different codes?

 

As @philip1009 mentioned, this is possible through iLogic.  Essentially, you would develop a rule that looks at the name of the material of the part, and then uses If/Then logic to determine the desired code.  You would then set up a trigger so that the rule runs automatically if the material is changed.

 

This is not terribly difficult, and I think is actually a pretty good simple example of the types of things you can automate with iLogic without really knowing that much about programming.  Once you get into doing it, you will likely find many things you can automate with simple code to make your work a little easier and save a little time.

 

Below is an extremely simplified example, just to give you an idea of what the code for something like this would look like.  In this example, I assume that "S0001" is the code for Steel, "S0002" is the code for "Glass", and that any other material is considered non-standard and will get the code "XXXXX".  It writes the code to a custom iProperty called "Material Code".  Obviously, the more materials and codes are involved, the longer this would get, but it would essentially still be this idea, just with more "ElseIf" statements.

 

Material = iProperties.Material

If Material = "Steel" Then
	iProperties.Value("Custom", "Material Code") = "S0001"
	
ElseIf Material = "Glass" Then
	iProperties.Value("Custom", "Material Code") = "S0002"
	
Else
	iProperties.Value("Custom", "Material Code") = "XXXXX"

End If
Message 4 of 16

Anonymous
Not applicable

Hi. Thank you very much for your prompt reply. I will try working this in. If I still have an issue will write back. I will make sure that I post my questions in the correct forum next time. thank you very much for the help 🙂

0 Likes
Message 5 of 16

Anonymous
Not applicable

thank you very much for your timely help. I will try this form. If I still have issues will write back. Thank you once again 🙂

0 Likes
Message 6 of 16

Anonymous
Not applicable

Hi      ... your illogic rule works really well, thanks for this.  However I have an issue here. This works with the material name only for eg, steel, iron, etc... I need something that can work with material category instead, like metal, glass, mirror, plastic, stone, etc. The reason for doing this is that the metal components to be custom made always have an order which is always generated as a part number S0001. This is also the case with some other common materials like a glass of a certain thickness which has its own part number irrespective of the length and width and stones of certain types. This is why I need to identify the code based on material category and not material type. Can you please help me with this?

 

thanks              

0 Likes
Message 7 of 16

jtylerbc
Mentor
Mentor

@Anonymous,

 

So far, I haven't been able to find a way to do that.  That doesn't necessarily mean it's not possible.  It just means that if it is possible, I don't know how to do it.

 

The closest I came to finding something that seems like it might be the right direction would be:

ThisDoc.Document.ComponentDefinition.Material.Type

This seems reasonable, based on the structure of other items in the Rule Editor's Snippets browser under Material Material Properties.  However, this returns a number, not a text name, and the number seems to have the same value of "50362368" regardless of what material is selected.  I'm not sure what it's intended to mean, but it obviously isn't what you're looking for if steel, glass, and leather all return the same value.

 

Message 8 of 16

lmc.engineering
Advocate
Advocate

Hi @Anonymous

 

We just need to access the material category using the following:

 

SyntaxEditor Code Snippet

Dim oDoc As Inventor.PartDocument = ThisDoc.Document
MaterialCat = oDoc.ActiveMaterial.CategoryName

So to make use of this, place the following in each part file and mod as needed:

 

SyntaxEditor Code Snippet

Dim oDoc As Inventor.PartDocument = ThisDoc.Document
MaterialCat = oDoc.ActiveMaterial.CategoryName

If MaterialCat = "Metal" Then
	iProperties.Value("Custom", "Material Code") = "S0001"
	
ElseIf MaterialCat = "Glass" Then
	iProperties.Value("Custom", "Material Code") = "S0002"	
Else
	iProperties.Value("Custom", "Material Code") = "XXXXX"
End If

 Regards

Message 9 of 16

jtylerbc
Mentor
Mentor

@lmc.engineering, I believe you've got it.  I just couldn't quite figure out how to get there.  I assumed it would be under ComponentDefinition.Material like many of the other material properties are, but this one doesn't seem to be available through that path.

Message 10 of 16

lmc.engineering
Advocate
Advocate

It's wasn't the most straight forward path to finding the correct handle. Originally I thought it might be under the MaterialAsset.CatagoryName, however I couldn't get a handle on it that way.  I believe the above is the easiest way based on setting this from the part file. If We drilled down from an assembly to set iProperties, MaterialAsset might just be the way forward.

Message 11 of 16

Anonymous
Not applicable

hi,

   yes, this one works perfectly fine... thanks a lot for it. However is there any possibility for us to have this rule applied in our multibody ipt file and then when we make components this rule automatically runs for all the part files generated from the multi body ipt? At the moment we need to open each part file and run the rule so it applies to all parts. Or better if we can run this rule in the assembly file... is this possible? Please advise

0 Likes
Message 12 of 16

Anonymous
Not applicable

thank you for the response and thank you for the thoughtful help

0 Likes
Message 13 of 16

Anonymous
Not applicable

yes @jtylerbc, @lmc.engineering code is working really well in all individual part files.. thanks both for the help

0 Likes
Message 14 of 16

lmc.engineering
Advocate
Advocate

Hi @Anonymous

 

So I've not had a chance to properly test this, but I believe this will work for you.

 

This script will run from a top level assembly, drill down to each part file, check the material catagory then update the iProperties. You can change your filtered categories in the 'FilterMaterialCat' Function.

 

SyntaxEditor Code Snippet

Sub Main()
Dim openDoc As AssemblyDocument
openDoc = ThisDoc.Document
Dim docFile As Document
For Each docFile In openDoc.AllReferencedDocuments
	On Error Resume Next
	If docFile.DocumentType = 12290 Then
	MaterialCat = docFile.ActiveMaterial.CategoryName
	FilterMaterialCat(MaterialCat)
	'MessageBox.Show(MaterialCat, "Title")
	InventorVb.DocumentUpdate()
	End If
Next
End Sub

Function FilterMaterialCat(MaterialCat As String)
	If MaterialCat = "Metal" Then
		iProperties.Value("Custom", "Material Code") = "S0001"
	ElseIf MaterialCat = "Plastic" Then
		iProperties.Value("Custom", "Material Code") = "S0002"	
	Else
		iProperties.Value("Custom", "Material Code") = "XXXXX"
	End If
End Function

 

0 Likes
Message 15 of 16

jtylerbc
Mentor
Mentor

@Anonymous wrote:

hi,

   yes, this one works perfectly fine... thanks a lot for it. However is there any possibility for us to have this rule applied in our multibody ipt file and then when we make components this rule automatically runs for all the part files generated from the multi body ipt? At the moment we need to open each part file and run the rule so it applies to all parts. Or better if we can run this rule in the assembly file... is this possible? Please advise


 

It looks like @lmc.engineering has come up with a way for you to do what you asked for here.  Another way to approach it would be to put the part-level code into the template file that you use when you generate the individual parts from the multisolid.  Set it with one or more triggers so the rule runs automatically.  I would think that "Material Change" would be a logical trigger for this one.  Once that's done, you'll never have to run it yourself manually - it will just happen. 

 

The assembly version of the code would still have a place in this setup - it could be used as an External Rule to fix models that were created before the part-level rule was added to the template.

 

Also, I would point out that all the example code (including both what I posted and @lmc.engineering's version) includes the "S0002" and "XXXXX" codes.  I don't believe you ever mentioned those - they were something I added as part of my original example.  If they don't reflect what you actually want, you'll need to remove or revise those lines of code from the version you actually use (if you haven't already).

0 Likes
Message 16 of 16

Anonymous
Not applicable

hello, yes I did remove them and replaced with the other categories. many thanks

0 Likes