I have an external iLogic rule that I use to measure parts and create custom iProperies for BOM uses. Instead of having to open each part individually and running the rule, I would like to be able to run the External rule to all parts in an assembly. Attached is my rule....crude, but does what I need it to do
On part level trigger your rule before save document and you ll be ready to go. In assembly you just save file open bom and you ll see your dimensions. See att picture.
Is there a way to apply one external rule to all of the parts in an assembly from the assembly level? It would be a pain to have to set a trigger for each part one at a time.
Alot of the things I build in Inventor are built from structural steel. Most assemblies consist of a lot of content center parts. I'm mostly looking for code that will apply this rule to all parts in the assembly. The way I have inventor set up it would be difficult to create a custom content center library.
Thanks for the help.
Ok so I got the code working by editing the part template and triggering the rule. The only thing I can not figure out how to do is get the rule to run on content center parts. Is there another part template for content center parts somewhere?
To answer your first question, there is a way to have an assembly open and then modify each part in the assembly. You can either access the properties of the each part document using code like below, which will modify the part number of all sub-assemblies to match the file name, minus the extension.
'Define the open document Dim openDoc As Document openDoc = ThisDoc.Document Dim docFile As Document ''format file name ' FNamePos = InStrRev(docFile.FullFileName, "\", -1) ' 'Dim docFName As String ' 'returns file name with extension 'docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos) ''returns the number of characters in the file name 'nameLen = Len(docFName) ''trims off the file extension (last 4 characters) 'nameNoExtension = Left(docFName,nameLen-4) 'kAssemblyDocumentObject = 12291 If openDoc.DocumentType = 12291 Then 'Iterate though the assembly files in the assembly For Each docFile In openDoc.AllReferencedDocuments 'kPartDocumentObject = 12290 If docFile.DocumentType = 12291 Then 'format file name 'Dim FNamePos As Long FNamePos = InStrRev(docFile.FullFileName, "\", -1) 'Dim docFName As String 'returns file name with extension docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos) 'returns the number of characters in the file name nameLen = Len(docFName) 'trims off the file extension (last 4 characters) nameNoExtension = Left(docFName,nameLen-4) 'set part number to file name (without extension) If iProperties.Value(docFName,"Project", "Part Number") <> nameNoExtension Then iProperties.Value(docFName,"Project", "Part Number") = nameNoExtension Else End If 'check for empty Rev # If iProperties.Value(docFName,"Project", "Revision Number") = "" Then iProperties.Value(docFName,"Project", "Revision Number") = 1 Else End If End If Next Else MessageBox.Show("You must have a valid Assembly document open before using this code!", "File Type Mismatch!") End If
The other, more brute force way of doing that is to follow the same work flow that a person would follow and to mak each part active and then do what changes you need to do.
Dim docFile As Document If openDoc.DocumentType = 12291 Then For Each docFile In openDoc.AllReferencedDocuments If docFile.DocumentType = 12290 Then Dim assemblyDoc As AssemblyDocument assemblyDoc = openDoc Dim assemblyDef As AssemblyComponentDefinition assemblyDef = assemblyDoc.ComponentDefinition Dim partDoc As PartDocument partDoc = ThisApplication.Documents.Open(docFile.FullFileName, False) Dim FNamePos As Long FNamePos = InStrRev(docFile.FullFileName, "\", -1) Dim docFName As String docFName = Mid(docFile.FullFileName, FNamePos + 1, Len(docFile.FullFileName) - FNamePos) 'This line here actually makes the part the active part in Inventor ThisDoc.Launch(docFile.FullFileName) Check = iProperties.Mass(docFName) 'MessageBox.Show(Check) 'This checks to see if each part has mass (actually exists) If Check > 0.01 Then 'MessageBox.Show("File recognized as existing.") 'This runs the commands that DXF's each part file Main2() doc=docfile doc.Close(True) Else 'MessageBox.Show("File recognized as not existing.") doc=docfile doc.Close(True) End If End If Next Else MessageBox.Show("You must have a valid Assembly document open before using this code!", "File Type Mismatch!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation) End If MessageBox.Show("DXF-ing Complete. Now closing Assembly.") openDoc = ThisDoc.Document doc = openDoc doc.Close(True) End Sub
The above code will go through and make each part active, execute whatever commands are in the sub Main2, and then go back to the assembly and move onto the next part. This code is much more time consuming but you can see what the code is doing as it goes. This is a portion of a larger code I wrote that exports each face of a part in an assembly as a DXF for CNC cutting. I can post up the entire code if you want to see everything.
Hello,
Here is the entire code that I pulled those sections from I believe. I don't think the code has changed since I originally posted it. I havn't used this rule recently but it should still work fine. If you have any questions or problems with it let me know.