Hi,
I need an ilogic rule that will overwrite in custom iproperty the information in which subassembly / assembly the part occurs. Example:
Assembly1 - custom iproperty name "Article Name" = "ASS1"
Assembly2 - custom iproperty name "Article Name" = "ASS2"
Assembly3 - custom iproperty name "Article Name" = "ASS3"
Assembly4 - custom iproperty name "Article Name" = "ASS4"
Pipe.ipt occurs in Assembly1 and Assembly3 in this case:
Pipe.ipt custom iproperty "Affiliation = ASS1_ASS3"
Thanks to this I know that the part "Pipe.ipt" occurs in ASS1 and ASS3 assemblies and the production workers know where to use this part
I am very much asking for help
Solved! Go to Solution.
Solved by WCrihfield. Go to Solution.
Solved by WCrihfield. Go to Solution.
Hi @autodesk0343ART. It is usually not a good idea to write assembly level data down into the parts that get included within that assembly, for various reasons. For example, if that part might possibly get used in any other assemblies at a later date, then you write data from that assembly down into this part to change that information, then it will not be accurate for the this assembly anymore. One of the most common requests I see is folks wanting to write assembly quantity data into the part. Well, if that part gets used in 20 other assemblies later, and they all write their assembly quantity data to it also, then that quantity data will be overwritten each time, making it not accurate or correct for the previous assembly at that point. However, if you are in the practice of copying whole assemblies with all their parts to other folders, then renaming all the files, where you will only ever use a part in the one assembly, then writing assembly level data back down into the parts may not be a problem. Just something to keep in mind though.
If you still want to do this though, then are your assemblies literally called "Assembly1", or if not, then what part of the assembly's name do you want to record that way (its file name without file extension, or its Part Number iProperty value, or something else)?
Wesley Crihfield
(Not an Autodesk Employee)
Each assembly has a custom iproperty "Art.Nr" filled in manually by me.
Each part has a custom iproperty "Zeichung-Name" and into this column would be copied values from the "Art.Nr" assembly.
as shown in the above screenshot. In case a part appears in more than one assembly, the value would appear after the "_" sign, example: IT k1_IT k2
OK. Thanks for the clarification. This does sound possible. I will look into an iLogic rule to do this task as time permits, while keeping up with my other stuff at work.
Wesley Crihfield
(Not an Autodesk Employee)
Thank you for your willingness to help and good luck. Should you have any questions or need additional information, please feel free to contact me
The custom property string might be 255 character max.
So it can keep track of about 40-50 assemblies.
I have a couple questions.
Wesley Crihfield
(Not an Autodesk Employee)
only Assembly C, I just need that level of assembly
exactly if a part appears in two different assemblies it should appear in "Zeichung-name" separated by "_" sign
Hi @autodesk0343ART. I have an iLogic rule for you to try out. But keep in mind that I have not tested this yet, so be cautious and check things out to make sure it is working correctly. And if it shows an error message, try to capture what it says (in both tabs), so you can show us what it said, because that might help us figure out where the problem is or how to fix it.
Sub Main
Dim oADoc As AssemblyDocument = TryCast(ThisDoc.Document, AssemblyDocument)
If oADoc Is Nothing Then Return
Dim oRefDocs As DocumentsEnumerator = oADoc.AllReferencedDocuments
If oRefDocs.Count = 0 Then Return
Dim oOccs As ComponentOccurrences = oADoc.ComponentDefinition.Occurrences
If oOccs.Count = 0 Then Return
'start a transaction (records multiple actions into one item in the UNDO list)
Dim oTrans As Inventor.Transaction
oTrans = ThisApplication.TransactionManager.StartTransaction(oADoc, "Part Affiliation - iLogic")
oDict = New Dictionary(Of Inventor.Document, List(Of String)) 'initiate a value to the shared variable
'<<< iterate all referenced documents and the components referencing them, and fill-in Dictionary entries >>>
For Each oRefDoc As Inventor.Document In oRefDocs
Dim oRefOccs As ComponentOccurrencesEnumerator = Nothing
Try : oRefOccs = oOccs.AllReferencedOccurrences(oRefDoc) : Catch : End Try
If oRefOccs Is Nothing OrElse oRefOccs.Count = 0 Then Continue For
For Each oRefOcc As ComponentOccurrence In oRefOccs
Dim oParentOcc As ComponentOccurrence = oRefOcc.ParentOccurrence
If oParentOcc Is Nothing Then Continue For
Dim oParentOccDoc As Document = oParentOcc.Definition.Document
Dim oCProps As Inventor.PropertySet = oParentOccDoc.PropertySets.Item(4)
Dim oArtNr_Prop As Inventor.Property = Nothing
Try : oArtNr_Prop = oCProps.Item("Art.Nr") : Catch : End Try
If oArtNr_Prop Is Nothing Then Return
Dim sArtNr As String = oArtNr_Prop.Value
If sArtNr = "" Then Continue For
If oDict.ContainsKey(oRefDoc) Then
If Not oDict.Item(oRefDoc).Contains(sArtNr) Then
oDict.Item(oRefDoc).Add(sArtNr)
End If
Else
oDict.Add(oRefDoc, New List(Of String) From {sArtNr})
End If
Next 'oRefOcc
Next 'oRefDoc
'<<< iterate Dictionary entries (if any), and write values to referenced documents
If oDict.Count = 0 Then
oTrans.Abort
Return
End If
For Each oEntry As KeyValuePair(Of Inventor.Document, List(Of String)) In oDict
Dim oValues As List(Of String) = oEntry.Value
If oValues Is Nothing OrElse oValues.Count = 0 Then Continue For
Dim oCProps As Inventor.PropertySet = oEntry.Key.PropertySets.Item(4)
Dim oZeichungName_Prop As Inventor.Property = Nothing
Try : oZeichungName_Prop = oCProps.Item("Zeichung-Name") : Catch : End Try
If oZeichungName_Prop Is Nothing Then Return
Dim sZeichungName As String = ""
For Each sValue In oValues
If sZeichungName = "" Then
sZeichungName = sValue
Else
sZeichungName = sZeichungName & "_" & sValue
End If
Next 'sValue
Try : oZeichungName_Prop.Value = sZeichungName : Catch : End Try
Next 'oEntry
If oADoc.RequiresUpdate Then oADoc.Update2(True)
oTrans.End 'end the transaction recording all these actions into one UNDO
MsgBox("This rule's work has finished.", vbInformation, "Job Is Done!")
'If oADoc.Dirty Then oADoc.Save2(True)
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield
(Not an Autodesk Employee)
Hi @autodesk0343ART. In the code I posted earlier, within a couple of the loops, I use the keyword "Return", when I should have used the key phrase "Continue For" instead. (Line 24 and Line 47 primarily) There may have been something else wrong with it too, but those are the main ones I saw. Try changing those, and let me know how that works. I have something else almost ready to post here, but found a mistake just before I was about to post it here, and it is the end of my work day, so I will fix it tomorrow, then check back in.
Wesley Crihfield
(Not an Autodesk Employee)
Attached is a text file for another code you can try, if those edits to not work.
Wesley Crihfield
(Not an Autodesk Employee)
Sub Main
Dim oADoc As AssemblyDocument = TryCast(ThisDoc.Document, AssemblyDocument)
If oADoc Is Nothing Then Return
Dim oRefDocs As DocumentsEnumerator = oADoc.AllReferencedDocuments
If oRefDocs.Count = 0 Then Return
Dim oOccs As ComponentOccurrences = oADoc.ComponentDefinition.Occurrences
If oOccs.Count = 0 Then Return
'start a transaction (records multiple actions into one item in the UNDO list)
Dim oTrans As Inventor.Transaction
oTrans = ThisApplication.TransactionManager.StartTransaction(oADoc, "Part Affiliation - iLogic")
oDict = New Dictionary(Of Inventor.Document, List(Of String)) 'initiate a value to the shared variable
'<<< iterate all referenced documents and the components referencing them, and fill-in Dictionary entries >>>
For Each oRefDoc As Inventor.Document In oRefDocs
Dim oRefOccs As ComponentOccurrencesEnumerator = Nothing
Try : oRefOccs = oOccs.AllReferencedOccurrences(oRefDoc) : Catch : End Try
If oRefOccs Is Nothing OrElse oRefOccs.Count = 0 Then Continue For
For Each oRefOcc As ComponentOccurrence In oRefOccs
Dim oParentOcc As ComponentOccurrence = oRefOcc.ParentOccurrence
If oParentOcc Is Nothing Then Continue For
Dim oParentOccDoc As Document = oParentOcc.Definition.Document
Dim oCProps As Inventor.PropertySet = oParentOccDoc.PropertySets.Item(4)
Dim oArtNr_Prop As Inventor.Property = Nothing
Try : oArtNr_Prop = oCProps.Item("Art.Nr") : Catch : End Try
If oArtNr_Prop Is Nothing Then Continue For
Dim sArtNr As String = oArtNr_Prop.Value
If sArtNr = "" Then Continue For
If oDict.ContainsKey(oRefDoc) Then
If Not oDict.Item(oRefDoc).Contains(sArtNr) Then
oDict.Item(oRefDoc).Add(sArtNr)
End If
Else
oDict.Add(oRefDoc, New List(Of String) From {sArtNr})
End If
Next 'oRefOcc
Next 'oRefDoc
'<<< iterate Dictionary entries (if any), and write values to referenced documents
If oDict.Count = 0 Then
oTrans.Abort
Return
End If
For Each oEntry As KeyValuePair(Of Inventor.Document, List(Of String)) In oDict
Dim oValues As List(Of String) = oEntry.Value
If oValues Is Nothing OrElse oValues.Count = 0 Then Continue For
Dim oCProps As Inventor.PropertySet = oEntry.Key.PropertySets.Item(4)
Dim oZeichungName_Prop As Inventor.Property = Nothing
Try : oZeichungName_Prop = oCProps.Item("Zeichnung-Name") : Catch : End Try
If oZeichungName_Prop Is Nothing Then Continue For
Dim sZeichnungName As String = ""
For Each sValue In oValues
If sZeichnungName = "" Then
sZeichnungName = sValue
Else
sZeichnungName = sZeichnungName & "_" & sValue
End If
Next 'sValue
Try : oZeichungName_Prop.Value = sZeichnungName : Catch : End Try
Next 'oEntry
If oADoc.RequiresUpdate Then oADoc.Update2(True)
oTrans.End 'end the transaction recording all these actions into one UNDO
MsgBox("This rule's work has finished.", vbInformation, "Job Is Done!")
'If oADoc.Dirty Then oADoc.Save2(True)
End Sub
I notice now that the only thing missing is the designation for the items from the top-level assembly
Hi @autodesk0343ART. I edited the earlier code I posted here (the one with the Dictionary), to fix the 'Return / Continue For' mix-up, correct the spelling of the custom iProperty name, and fix the issue with the top level components not getting the necessary information written to them, and to 'clear' the destination custom iProperty's value, before writing the new one to it. Since this change forces me to retrieve custom iProperty value from the main assembly, and from other referenced documents, I transferred that value retrieval routine out into a separate Function, so I can just call it to run from two different places, without having duplicate code in two different places, even though I still needed similar code again in a third location (while iterating the Dictionary entries), but in that situation, I needed direct access to the Property object, to set its value.
See attached text file for the updated code.
Wesley Crihfield
(Not an Autodesk Employee)
Can't find what you're looking for? Ask the community or share your knowledge.