Autodesk Inventor Customization
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Re: Run ilogic rule in each part from the assembly via external rule?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.Exc lamation) 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
--------------------------------------------------------------------------------------
Re: Run ilogic rule in each part from the assembly via external rule?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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
XP 32-Bit SP3
Re: Run ilogic rule in each part from the assembly via external rule?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.Exc lamation) 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
--------------------------------------------------------------------------------------
Re: Run ilogic rule in each part from the assembly via external rule?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Great, thanks! works a treat. Glad you were able to learn something as well
(Joke)
Really appreciate the help. I am going to study the rule a bit and improve my knowledge.
Cheers,
Guy
XP 32-Bit SP3
Re: Run ilogic rule in each part from the assembly via external rule?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.Exc lamation)
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
--------------------------------------------------------------------------------------
Re: Run ilogic rule in each part from the assembly via external rule?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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
XP 32-Bit SP3
Re: Run ilogic rule in each part from the assembly via external rule?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.Exc lamation)
End If
XP 32-Bit SP3
Re: Run ilogic rule in each part from the assembly via external rule?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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
--------------------------------------------------------------------------------------


