iLogic "Generic" Material Warning

iLogic "Generic" Material Warning

Formsprag
Advocate Advocate
1,476 Views
15 Replies
Message 1 of 16

iLogic "Generic" Material Warning

Formsprag
Advocate
Advocate

Is there a way to use iLogic to search all components in an assembly and it's sub-assemblies for the material property being set to "Generic"? The result of the search would give user's a list of "Part Number(s)" that would need to have the "Material" property changed from "Generic" before file could be saved.

 

Inventor 2020.2.1

0 Likes
Accepted solutions (2)
1,477 Views
15 Replies
Replies (15)
Message 2 of 16

JelteDeJong
Mentor
Mentor

try this iLogic rule:

Dim mainDoc As AssemblyDocument = ThisDoc.Document
Dim nl As String = System.Environment.NewLine
Dim msg As String = "Doc's with Generic material: " + nl
For Each refDoc As Document In mainDoc.AllReferencedDocuments
    If (refDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject) Then
        Dim doc As PartDocument = refDoc
        If (doc.ActiveMaterial.DisplayName.Equals("Generic")) Then
            Dim propSet As PropertySet = doc.PropertySets.Item("Design Tracking Properties")
            Dim partNumiProp As [Property] = propSet.Item("Part Number")
            msg = msg + partNumiProp.Value + nl
        End If
    End If
Next
MsgBox(msg)

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 16

JhoelForshav
Mentor
Mentor

Hi,

Since AllReferencedDocuments also includes any derived documents I'd recommend traversing the Assembly occurrences instead.

Something like this:

 

Class ThisRule
Dim oList As List(Of String)
Sub Main
If ThisDoc.Document.DocumentType <> kAssemblyDocumentObject
	MsgBox("Rule can only run in Assembly document")
	Exit Sub
End If
oList = New List(Of String)
Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oReturnString As String
Dim oPartNum As String
FindGenericMaterial(oAsm)
For Each oNumber As String In oList
	If oReturnString = "" Then
	oReturnString = oNumber
	Else
	oReturnString = oReturnString & vbCrLf & oNumber
	End If
Next
If oReturnString <> ""
	MsgBox("Parts with generic material:" & vbCrLf & oReturnString)
Else
	MsgBox("No Parts with generic material")
End If
End Sub
Sub FindGenericMaterial(oAsm As AssemblyDocument)
Dim oPartNum As String
Dim oDoc As Document
For Each oOcc As ComponentOccurrence In oAsm.ComponentDefinition.Occurrences
 oDoc = oOcc.Definition.Document
	If oDoc.DocumentType = kPartDocumentObject AndAlso oDoc.ComponentDefinition.Material.Name = "Generic"
		oPartNum = oDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
		If oList.Contains(oPartNum) = False Then oList.Add(oPartNum)
	ElseIf oDoc.DocumentType = kAssemblyDocumentObject
		FindGenericMaterial(oDoc)
	End If
Next
End Sub
End Class

 

 

0 Likes
Message 4 of 16

JelteDeJong
Mentor
Mentor

The point of this rule is to find all documents where the material was not set correct.  In this case i would think its a good thing that also derived documents are found. 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 5 of 16

JhoelForshav
Mentor
Mentor

I'm not so sure about that. Definitley depends on how you work with Inventor. You could have parts that have no other purpuse than to provide other parts with parameters, sketches etc, and therefore not need to have a material. Also I think it might be confusing when the rule gives a warning about a part that isn't even in the assembly.

 

But you might be right, maybe it's a bonus that derived parts are included.

 

I just thought I'd give the suggestion to traverse the assembly instead, because of how @Formsprag formulated the question:

"Is there a way to use iLogic to search all components in an assembly and it's sub-assemblies for the material property being set to "Generic"?"

0 Likes
Message 6 of 16

Formsprag
Advocate
Advocate

Yes, derived components is where most of the users fail to assign the material property so I think this would be the best approach. I ran both sets of iLogic, JelteDeJong's code worked with no problems it even picked up derived components with the material property set to "Generic". 

 

jhoel.forshav your code shuts Inventor down, the code crashes the program every time. 

 

2020-04-07_7-10-50.jpg

 

Thanks

 

0 Likes
Message 7 of 16

JhoelForshav
Mentor
Mentor

That's strange... Runs without any problem for me.

Since you want it to check derived components there really isn't any need to investigate this further. 

The solution that @JelteDeJong gave is far better and faster than traversing the occurrences in that case.

0 Likes
Message 8 of 16

Formsprag
Advocate
Advocate

Can you make the rule not run if "Material" is anything other than "Generic"?

0 Likes
Message 9 of 16

JhoelForshav
Mentor
Mentor
Accepted solution

@Formsprag 

I assume you mean that you dont want any messagebox if there are no documents with generic material?

Like this maybe?

 

Dim mainDoc As AssemblyDocument = ThisDoc.Document
Dim nl As String = System.Environment.NewLine
Dim msg As String = "Doc's with Generic material: " + nl
Dim viewMsg As Boolean = False
For Each refDoc As Document In mainDoc.AllReferencedDocuments
If (refDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject) Then
Dim doc As PartDocument = refDoc
If (doc.ActiveMaterial.DisplayName.Equals("Generic")) Then
Dim propSet As PropertySet = doc.PropertySets.Item("Design Tracking Properties")
Dim partNumiProp As [Property] = propSet.Item("Part Number")
msg = msg + partNumiProp.Value + nl
viewMsg = True
End If
End If
Next
If viewMsg = True Then MsgBox(msg)

0 Likes
Message 10 of 16

Formsprag
Advocate
Advocate

That worked perfect!

 

I feel like this should be an easy rule to edit so it will work for standalone parts but I can't get it to respond as a standalone part. What am I missing?

0 Likes
Message 11 of 16

JhoelForshav
Mentor
Mentor

Do you mean that you want to be able to run the rule inside of a part document and have it warn you if the document has generic material?

0 Likes
Message 12 of 16

Formsprag
Advocate
Advocate

Yes, I edited the rule for a part document but it doesn't give me anything. 

0 Likes
Message 13 of 16

JhoelForshav
Mentor
Mentor
Accepted solution

You can run this from within a part document. It also takes care of derived documents.

 

Dim nl As String = System.Environment.NewLine
Dim msg As String = "Doc's with Generic material: " + nl
Dim viewMsg As Boolean = False

Dim doc As PartDocument = ThisDoc.Document
If (doc.ActiveMaterial.DisplayName.Equals("Generic")) Then
Dim propSet As PropertySet = doc.PropertySets.Item("Design Tracking Properties")
Dim partNumiProp As [Property] = propSet.Item("Part Number")
msg = msg + partNumiProp.Value + nl
viewMsg = True
End If
For Each oDerComp As DerivedPartComponent In doc.ComponentDefinition.ReferenceComponents.DerivedPartComponents
Dim oRefDoc As Document = oDerComp.ReferencedDocumentDescriptor.ReferencedDocument
If (oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject) Then
If (oRefDoc.ActiveMaterial.DisplayName.Equals("Generic")) Then
Dim propSet As PropertySet = oRefDoc.PropertySets.Item("Design Tracking Properties")
Dim partNumiProp As [Property] = propSet.Item("Part Number")
msg = msg + partNumiProp.Value + nl
viewMsg = True
End If
End If
Next
If viewMsg = True Then MsgBox(msg)

 

 

Edit: This does the same thing but looks better.

 

Class ThisRule
Dim nl As String = System.Environment.NewLine
Dim msg As String = "Doc's with Generic material: " + nl
Dim viewMsg As Boolean = False
Sub Main
Dim doc As PartDocument = ThisDoc.Document
GetGenericMaterial(doc)
For Each oDerComp As DerivedPartComponent In doc.ComponentDefinition.ReferenceComponents.DerivedPartComponents
Dim oRefDoc As Document = oDerComp.ReferencedDocumentDescriptor.ReferencedDocument
If (oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject) Then
GetGenericMaterial(oRefDoc)
End If
Next
If viewMsg = True Then MsgBox(msg)
End Sub
Sub GetGenericMaterial(doc As PartDocument)
If (doc.ActiveMaterial.DisplayName.Equals("Generic")) Then
Dim propSet As PropertySet = doc.PropertySets.Item("Design Tracking Properties")
Dim partNumiProp As [Property] = propSet.Item("Part Number")
msg = msg + partNumiProp.Value + nl
viewMsg = True
End If
End Sub
End Class

 

0 Likes
Message 14 of 16

Formsprag
Advocate
Advocate

Both work PERFECT! 

 

Thanks

Message 15 of 16

laurensguijt138
Participant
Participant

Hello,

 

I'm trying to implement this warning into my PDF preview code. However I'm not able to check the referenced part material, or the iproperties material value of the drawing. Could someone help me with adding generic warning to my existing code ?
This is my current preview code:

'Update date
oTime = Now.ToShortDateString
iProperties.Value("Project", "Creation Date") = oTime
iLogicVb.UpdateWhenDone = True

temp_folder = System.IO.Path.GetTempPath()

'Update checked by user
oNAME = ThisApplication.GeneralOptions.UserName
iProperties.Value("Status", "Checked by") = oNAME

'Declare
oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension
oRevNum = iProperties.Value("Project", "Revision Number")
oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oDocument = ThisApplication.ActiveDocument
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

'2D of 3D bestand
If ThisDoc.Document.DocumentType <> kDrawingDocumentObject Then

'3D bestand error
MessageBox.Show("Het is niet mogelijk een 3D Bestand als PDF te openen", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

'2D bestand
Else
	
'------------------------------------------------------------------------
'PDF settings
oOptions.Value("All_Color_AS_Color") = 0
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets

'2D bestand naar PDF folder zoeken
oFolder = Left(oPath, InStrRev(oPath, "\")) & "PDF"

 'PDF naam definieren 
oDataMedium.FileName = temp_folder & "\" & oFileName & _
"" & "" & ".pdf"

'PDF opslaan
Try
	'probeer PDF op te slaan 
	oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
	 
	'Open PDF with default program
	ThisDoc.Launch(oDataMedium.FileName)

Catch
	'Als opslaan niet lukt, geef error
	MessageBox.Show("ERROR met PDF weergeven", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)

End Try
End If

 

 

0 Likes
Message 16 of 16

WCrihfield
Mentor
Mentor

Hi @laurensguijt138.  Here is an updated version of your code in which I included a warning about the referenced part's active material is set to "Generic", if that is the case.

If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Return
Dim oDDoc As DrawingDocument = ThisDoc.Document
Dim oModel As Document = ThisDoc.ModelDocument
If oModel.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
	Dim oPDoc As PartDocument = oModel
	If oPDoc.ActiveMaterial.DisplayName = "Generic" Then
		MessageBox.Show("Active Material of referenced part is 'Generic'!", "Generic Material")
	End If
End If
'Update date
oDDoc.PropertySets.Item(3).Item(1).Value = Now 'Creation Date
iLogicVb.UpdateWhenDone = True
Dim temp_folder As String = System.IO.Path.GetTempPath()
'Update checked by user
oDDoc.PropertySets.Item(3).Item(5).Value = ThisApplication.GeneralOptions.UserName
'Declare
Dim sPath As String = System.IO.Path.GetDirectoryName(oDDoc.FullFileName)
Dim sFileName As String = System.IO.Path.GetFileNameWithoutExtension(oDDoc.FullFileName)
Dim sRevNum As String = oDDoc.PropertySets.Item(1).Item(7).Value 'Revision Number
Dim oPDFAddIn As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
Dim oDataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium
'------------------------------------------------------------------------
'PDF settings
oOptions.Value("All_Color_AS_Color") = 0
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets

'2D bestand naar PDF folder zoeken
Dim oFolder As String = Left(sPath, InStrRev(sPath, "\")) & "PDF"

 'PDF naam definieren 
oDataMedium.FileName = temp_folder & "\" & sFileName & _
"" & "" & ".pdf"

'PDF opslaan
Try
	'probeer PDF op te slaan 
	oPDFAddIn.SaveCopyAs(oDDoc, oContext, oOptions, oDataMedium)
	'Open PDF with default program
	ThisDoc.Launch(oDataMedium.FileName)
Catch
	'Als opslaan niet lukt, geef error
	MessageBox.Show("ERROR met PDF weergeven", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes