Hello
I am after help on some ilogic code if any body has any snippets they could share
1. Is there a way of searching an assembly with ilogic to find all .ipt with a certain type of material then if found insert a formula into the description field i;e, =<G_L> x <G_W> x <G_T>
2. Same As above but with a tweak i want to find materials again but i want to turn visibility on/off as this would help in the aid of creating view reps.
3. Find all .ipt within an assembly and if part number does not equal file name without .ext then add part number to parts
Regards
Dave
Solved! Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Hi dclunie,
I borrowed some code created by guyh and MegaJerk at this link:
and put together the following ilogic snippet to do what you're after, in this case checking for all parts using the mat'l steel.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
'kUnknownDocumentObject = 12289
'kPartDocumentObject = 12290
'kAssemblyDocumentObject = 12291
'kDrawingDocumentObject = 12292
'kPresentationDocumentObject = 12293
'kDesignElementDocumentObject = 12294
'kForeignModelDocumentObject = 12295
'kSATFileDocumentObject = 12296
'kNoDocument = 12297
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.Material(docFName) = "Steel" then
iProperties.Value(docFName, "Project", "Description")= "=<G_L> x <G_W> x <G_T>"
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
Hi dclunie,
I realized I forgot to address items 2 & 3 of your request. Here's a revised version that takes care of all 3 requests. It's not the most tidy, but it works.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
''kUnknownDocumentObject = 12289 'kPartDocumentObject = 12290 'kAssemblyDocumentObject = 12291 'kDrawingDocumentObject = 12292 'kPresentationDocumentObject = 12293 'kDesignElementDocumentObject = 12294 'kForeignModelDocumentObject = 12295 'kSATFileDocumentObject = 12296 'kNoDocument = 12297 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) 'select for part files with specified material If iProperties.Material(docFName) = "Steel" then 'set description iProperties.Value(docFName, "Project", "Description")= "=<G_L> x <G_W> x <G_T>" 'set part number to file name iProperties.Value(docFName, "Project", "Part Number") = Left(docFName, InstrRev(docFName, ".") - 1) Dim oCompDef As Inventor.ComponentDefinition = openDoc.ComponentDefinition Dim oCompOcc As Inventor.ComponentOccurrence For each oCompOcc in oCompDef.Occurrences voCompOcc = Component.InventorComponent(oCompOcc.Name) If iProperties.Material(docFName) = "Steel" Then voCompOcc.Visible = False End If Next 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
Hi Curtis
Thank you for your quick response too my post however ,I have tried to run code but getting error messages as I am very new to ilogic code I am unable to fix attached is jpg of error box ,if I comment problem area there is no error box but code does not change anything on assembly that it has run on.
Would the code need to react any differently if running on frame generator assemblies
I have placed code from my external rule for verification that it is correct
Regards
Dave
''kUnknownDocumentObject = 12289 'kPartDocumentObject = 12290 'kAssemblyDocumentObject = 12291 'kDrawingDocumentObject = 12292 'kPresentationDocumentObject = 12293 'kDesignElementDocumentObject = 12294 'kForeignModelDocumentObject = 12295 'kSATFileDocumentObject = 12296 'kNoDocument = 12297 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) 'select for part files with specified material If iProperties.Material(docFName) = "Steel" Then 'set description iProperties.Value(docFName, "Project", "Description")= "=<G_L> x <G_W> x <G_T>" 'set part number to file name iProperties.Value(docFName, "Project", "Part Number") = Left(docFName, InStrRev(docFName, ".") - 1) Dim oCompDef As Inventor.ComponentDefinition = openDoc.ComponentDefinition Dim oCompOcc As Inventor.ComponentOccurrence For Each oCompOcc in oCompDef.Occurrences voCompOcc = Component.InventorComponent(oCompOcc.Name) If iProperties.Material(docFName) = "Steel" Then voCompOcc.Visible = False End If Next 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
Regards
Dave
Hi dclunie,
The error you're seeing is due to an improper syntax in the message box line. You can just replace it with this line and it wll be fine:
MessageBox.Show("You must have a valid Assembly document open before using this code!", "File Type Mismatch!")
Remember to change your parts to use Steel for the material or change the code to look for a matrial you're using to see this work.
Also just noticed that the part dealing with visiblity is not handeling subassembly structures properly, so it would need to be looked at to get to work better.
Here's the modified rule fixing the message box line and removing the visibility code.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
''kUnknownDocumentObject = 12289 'kPartDocumentObject = 12290 'kAssemblyDocumentObject = 12291 'kDrawingDocumentObject = 12292 'kPresentationDocumentObject = 12293 'kDesignElementDocumentObject = 12294 'kForeignModelDocumentObject = 12295 'kSATFileDocumentObject = 12296 'kNoDocument = 12297 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) 'select for part files with specified material If iProperties.Material(docFName) = "Steel" Then 'set description iProperties.Value(docFName, "Project", "Description")= "=<G_L> x <G_W> x <G_T>" 'set part number to file name iProperties.Value(docFName, "Project", "Part Number") = Left(docFName, InStrRev(docFName, ".") - 1) 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
HI Curtis
That code works a treat and really fast thank you , sorry to ask again is there a way to look for different material within the same code and do the same operation to as follows
then find another
Just to explain why I need this code is all related to frame generator ,I use frame generator to build Upto 8000 part holiday homes and we use a formula within the description of all parts attached vie frame member and in some occasions or description formula gets wiped out and is no longer linked to exported parameters so the description fix above will fix this issue.
As one of the new features in frame gen where it names files for you and you have to un-checking the File Naming checkbox when create parts ,this is creating an issue for us as sometimes it is not unchecked and so part name does not equal file name,so the second part of code fixes this issue for me thank you.
The code to turn visibility off would work in same way as required for material but in the instance off adding to description we now require it to be invisible for view rep purpose workflow as follows.
if have set this search up in the find command box in inventor and it works but is quite slow on large assemblies
Regards
D clunie
Thanks for all yur help on this code
Hi dclunie,
So I've taken what you've said above literally and created a radio button input to allow the user to select Either Steel or Timber as a material, and then apply the description and part number to those parts that are the selected material. But as it is currently written there really isn't a need to choose between the two because they are getting the same treatment. If the steel parts were to get "=<G_L> x <G_W> x <G_T>" for the description and the timber parts were to get "=<G_W> x <G_L> x <G_T>" for the description then it makes sense to choose between the two.
Here the user is asked to select on or the other materials, but as I mentioned the actual formating of the iProperties is the same, but you could modify that if needed:
'Prompt user to choose from options
Dim booleanParam as Object
booleanParam = InputRadioBox("Select a Material", _
"Steel", "Timber", True, Title := "iLogic")
'Define the open document
Dim openDoc As Document
openDoc = ThisDoc.Document
Dim docFile As Document
'kAssemblyDocumentObject = 12291
If openDoc.DocumentType = 12291 Then
'Iterate though the part files in the assembly
For Each docFile In openDoc.AllReferencedDocuments
'kPartDocumentObject = 12290
If docFile.DocumentType = 12290 Then
'format file name
Dim FNamePos As Long
FNamePos = InStrRev(docFile.FullFileName, "\", -1)
Dim docFName As String
docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos)
'set description and part number for steel parts
If booleanParam = True Then
'select for part files with specified material
If iProperties.Material(docFName) = "Steel" Then
'set description
iProperties.Value(docFName, "Project", "Description") _
= "=<G_L> x <G_W> x <G_T>"
'set part number to file name
iProperties.Value(docFName, "Project", "Part Number") _
= Left(docFName, InStrRev(docFName, ".") - 1)
End If
Else
'set description and part number for timber parts
booleanParam = False
'select for part files with specified material
If iProperties.Material(docFName) = "Timber" Then
'set description
iProperties.Value(docFName, "Project", "Description") _
= "=<G_L> x <G_W> x <G_T>"
'set part number to file name
iProperties.Value(docFName, "Project", "Part Number") _
= Left(docFName, InStrRev(docFName, ".") - 1)
End if
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
Here is another version, that checks to see if the material is either Steel or Wood and and applies the formatting to all parts having one or the other of those materials:
'Define the open document
Dim openDoc As Document
openDoc = ThisDoc.Document
Dim docFile As Document
'kAssemblyDocumentObject = 12291
If openDoc.DocumentType = 12291 Then
'Iterate though the part files in the assembly
For Each docFile In openDoc.AllReferencedDocuments
'kPartDocumentObject = 12290
If docFile.DocumentType = 12290 Then
'format file name
Dim FNamePos As Long
FNamePos = InStrRev(docFile.FullFileName, "\", -1)
Dim docFName As String
docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos)
'select for part files with specified material
If iProperties.Material(docFName) = "Steel" OR _
iProperties.Material(docFName) = "Timber" Then
'set description
iProperties.Value(docFName, "Project", "Description") _
= "=<G_L> x <G_W> x <G_T>"
'set part number to file name
iProperties.Value(docFName, "Project", "Part Number") _
= Left(docFName, InStrRev(docFName, ".") - 1)
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
I'll try to get back to the visibility, view rep part of this later (it might be a few days).
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Hi Curtis
Thanks that code works great just what I needed we have multiple material components in our assemblies and now I can push all various descriptions to each of selected components ensuring our boms are nice and clean .
As you mentioned about the visibility it will need to find in the exact way but not altering any iproperties just find all ipts that match certain materials then visibility = off.
There is no rush for this one you have done quite a bit for me already ,many thanks it's good to know that people are out there willing to share there knowledge to help others .
Hi dclunie,
See this link for the View Representation rule:
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com