Inventor Customization

Inventor Customization

Reply
Valued Mentor
MegaJerk
Posts: 281
Registered: ‎01-26-2011
Message 11 of 18 (1,943 Views)

Re: Run ilogic rule in each part from the assembly via external rule?

12-08-2011 09:32 PM in reply to: guyh

Alright. This will go through every part and change the Description to the Custom Iprop without all the nasty errors or messes. 

 

Just make a new rule in your assembly and give it a go. 

 

Dim openDoc As Document
openDoc = ThisDoc.Document

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)
			
			iProperties.Value(docFile.DisplayName, "Project", "Description") = iProperties.Value(docFile.DisplayName, "Custom", "CUSTOM_NAME_HERE")
			Else 
			'''iProperties.Value(docFile.DisplayName, "Project", "Description") = "Assembly" 
			'''Don't really know if you want anything to happen if there is a Sub Assembly that this code comes across. 
			'''If not, you could just take this entire else portion out. 
		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 

 

 

 

 

--------------------------------------------------------------------------------------

If my solution seems to remedy your problem, please press the Accept Solution button, -
as it increases my power levels and will eventually help to elevate me towards outer space.

Check out my iLogic injection tool here : http://goo.gl/ce1Qg
--------------------------------------------------------------------------------------
Distinguished Contributor
guyh
Posts: 373
Registered: ‎12-11-2007
Message 12 of 18 (1,939 Views)

Re: Run ilogic rule in each part from the assembly via external rule?

12-09-2011 01:15 AM in reply to: MegaJerk

Hi,

 

Thanks again.  I tried this on the same assembly and it failed.  I made a new assembly and this also failed.  It failed on the same issue as before.  I have attached the new simple 2 part assembly.  These parts have the description in the custom property so the rule should copy this to the project description.

 

Maybe you can see some issue with these files?

 

cheers,

Guy

 

AutoCADM 2011 SP2
Inventor Pro 2011 SP2
Valued Mentor
MegaJerk
Posts: 281
Registered: ‎01-26-2011
Message 13 of 18 (1,933 Views)

Re: Run ilogic rule in each part from the assembly via external rule?

12-09-2011 05:23 AM in reply to: guyh

I found the problem. The line that used to read: 

 

 

iProperties.Value(docFile.DisplayName, "Project", "Description") = iProperties.Value(docFile.DisplayName, "Custom", "DISPLAY_NAME")

 

Now reads: 

 

iProperties.Value(docFName, "Project", "Description") = iProperties.Value(docFName, "Custom", "DISPLAY_NAME")

 

Because I did not take into consideration that your part names might be balanced, it was attempting to locate the iproperties of an instance it didn’t recognize.

 

If you right click and open your part (from the assembly), you’ll see that the root name is without any file extension. It would call on that DisplayName, but because it is neither a file (as it has no extension), nor is it an instance (because it would need a “:#” behind it to indicate the occurrence), it just freaks out.

 

Needless to say, the code above fixes this by looking at the actual file path of the document and shortening it down to just the file name of the part. That way it should always pull correctly… I hope.

This was actually a lesson for me! Pull from the darn part file name forever!

 

New iLogic Rule is below. 


 

 

Dim openDoc As Document
openDoc = ThisDoc.Document

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)
			
			iProperties.Value(docFName, "Project", "Description") = iProperties.Value(docFName, "Custom", "DISPLAY_NAME")
			Else 
			'''iProperties.Value(docFile.DisplayName, "Project", "Description") = "Assembly" 
			'''Don't really know if you want anything to happen if there is a Sub Assembly that this code comes across. 
			'''If not, you could just take this entire else portion out. 
		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 

 

--------------------------------------------------------------------------------------

If my solution seems to remedy your problem, please press the Accept Solution button, -
as it increases my power levels and will eventually help to elevate me towards outer space.

Check out my iLogic injection tool here : http://goo.gl/ce1Qg
--------------------------------------------------------------------------------------
Distinguished Contributor
guyh
Posts: 373
Registered: ‎12-11-2007
Message 14 of 18 (1,931 Views)

Re: Run ilogic rule in each part from the assembly via external rule?

12-09-2011 07:18 AM in reply to: MegaJerk

Great, thanks!  works a treat.  Glad you were able to learn something as well :smileywink:  (Joke) 

 

Really appreciate the help.  I am going to study the rule a bit and improve my knowledge.

 

Cheers,

Guy

AutoCADM 2011 SP2
Inventor Pro 2011 SP2
Valued Mentor
MegaJerk
Posts: 281
Registered: ‎01-26-2011
Message 15 of 18 (1,929 Views)

Re: Run ilogic rule in each part from the assembly via external rule?

12-09-2011 01:41 PM in reply to: guyh

Improved less awful code : 

 

Dim openDoc As Document
openDoc = ThisDoc.Document

Dim docFile As Document 

If openDoc.DocumentType = 12291 Then

	For Each docFile In openDoc.AllReferencedDocuments
	
		If docFile.DocumentType = 12290 Then

			Dim FNamePos As Long
            FNamePos = InStrRev(docFile.FullFileName, "\", -1)			
            
            Dim docFName As String
            docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos)
		
			iProperties.Value(docFName, "Project", "Description") = iProperties.Value(docFName, "Custom", "DISPLAY_NAME")	
		
		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 

 

--------------------------------------------------------------------------------------

If my solution seems to remedy your problem, please press the Accept Solution button, -
as it increases my power levels and will eventually help to elevate me towards outer space.

Check out my iLogic injection tool here : http://goo.gl/ce1Qg
--------------------------------------------------------------------------------------
Distinguished Contributor
guyh
Posts: 373
Registered: ‎12-11-2007
Message 16 of 18 (1,919 Views)

Re: Run ilogic rule in each part from the assembly via external rule?

12-12-2011 02:08 AM in reply to: MegaJerk

Thanks, I'll give it a try.  I want to try and adapt it a bit to skip parts where the custom property is blank (the old files already have the correct description in the description field.)

 

Cheers,

Guy

AutoCADM 2011 SP2
Inventor Pro 2011 SP2
Distinguished Contributor
guyh
Posts: 373
Registered: ‎12-11-2007
Message 17 of 18 (1,916 Views)

Re: Run ilogic rule in each part from the assembly via external rule?

12-12-2011 03:14 AM in reply to: guyh

Ok so I added a little bit of code.  It seems to work.

 

Dim openDoc As Document
openDoc = ThisDoc.Document

Dim docFile As Document 

If openDoc.DocumentType = 12291 Then

	For Each docFile In openDoc.AllReferencedDocuments
	
		If docFile.DocumentType = 12290 Then
		
		
			Dim FNamePos As Long
            FNamePos = InStrRev(docFile.FullFileName, "\", -1)	
						         
            Dim docFName As String
            docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos)
			
			If iProperties.Value(docFName, "Project", "Description")="" Then
		
			iProperties.Value(docFName, "Project", "Description") = iProperties.Value(docFName, "Custom", "DISPLAY_NAME")	
			
			
			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 

 

AutoCADM 2011 SP2
Inventor Pro 2011 SP2
Valued Mentor
MegaJerk
Posts: 281
Registered: ‎01-26-2011
Message 18 of 18 (1,913 Views)

Re: Run ilogic rule in each part from the assembly via external rule?

12-12-2011 06:16 AM in reply to: guyh

Looks like it's all sorted out then! 

--------------------------------------------------------------------------------------

If my solution seems to remedy your problem, please press the Accept Solution button, -
as it increases my power levels and will eventually help to elevate me towards outer space.

Check out my iLogic injection tool here : http://goo.gl/ce1Qg
--------------------------------------------------------------------------------------
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.