Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

RUN EXTERNAL RULE TO PARTS IN AN ASSEMBLY

9 REPLIES 9
Reply
Message 1 of 10
ZTM7793
1416 Views, 9 Replies

RUN EXTERNAL RULE TO PARTS IN AN ASSEMBLY

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

 

 

9 REPLIES 9
Message 2 of 10
GosponZ
in reply to: ZTM7793

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.

Message 3 of 10
ZTM7793
in reply to: GosponZ

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.

Message 4 of 10
GosponZ
in reply to: ZTM7793

Once you set in template you ready to go

Message 5 of 10
ZTM7793
in reply to: GosponZ

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.

Message 6 of 10
ZTM7793
in reply to: ZTM7793

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?

Message 7 of 10
tgrady
in reply to: ZTM7793

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.

Message 8 of 10
mrattray
in reply to: ZTM7793

There are threads on this board that have great information about how to code adding an event trigger via the rule itself.
The key is you will have to create an internal rule (via automation) that simply fires your external rule, as there is no way to add an external rule to the event triggers list directly.
It will take some development work to get it exactly as you want, but should be the bee's knees once you get it right.
Mike (not Matt) Rattray

Message 9 of 10
tony.yates
in reply to: tgrady

Hi Will you please post the entire code.

 

Thanks

Message 10 of 10
tgrady
in reply to: tony.yates

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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report