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: 

Part Affiliation

29 REPLIES 29
SOLVED
Reply
Message 1 of 30
autodesk0343ART
1716 Views, 29 Replies

Part Affiliation

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

29 REPLIES 29
Message 2 of 30

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

EESignature

(Not an Autodesk Employee)

Message 3 of 30

dzięki za odpowiedź

autodesk0343ART_0-1710781687818.png

 

 

Message 4 of 30

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

Message 5 of 30

autodesk0343ART_0-1710782859290.png

 

Message 6 of 30

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

EESignature

(Not an Autodesk Employee)

Message 7 of 30

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 

Message 8 of 30

The custom property string might be 255 character max.

So it can keep track of about 40-50 assemblies.

Message 9 of 30

that's good enough for me
Message 10 of 30

I have a couple questions.

  • If a part is used in Assembly C, then Assembly C is used in Assembly B, then Assembly B is used in Assembly A, but that part is not used directly within either Assembly B or Assembly A, then do you want Assembly B and Assembly A included in the "Zeichung-Name" property's value of that part?...or maybe only Assembly C (where it it directly used)?
  • Do you want to modify the "Zeichung-Name" property's value in any assemblies?
    • If so then:  If Assembly C is used in Assembly B, and Assembly B is used in Assembly A, then do you want to modify the value of that property in Assembly C to include Assembly B and Assembly A?...or maybe only Assembly B (where it is directly used in)?
  • In general, I understand that if Part X is used 'directly' within 2 different assemblies, then those two assemblies should be recorded within the "Zeichung-Name" property value of Part X.
    • But what I am not sure about is if any other parent level assemblies (that Part X is not 'directly' included in) should be in that "Zeichung-Name" property value of Part X.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 11 of 30

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

Message 12 of 30

First of all, I complete the column "Art.No." for assemblies and subassemblies
then I would like the information from the "Art.Nr" column using the ilogic rule to go into the "Zeichung-Name" column only where it is directly used.
To quote your sentence "if Part X is used 'directly' within 2 different assemblies, then those two assemblies should be recorded within the "Zeichung-Name" property value of Part X" - the answer is "YES"
Message 13 of 30

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

EESignature

(Not an Autodesk Employee)

Message 14 of 30

Thanks for the rule. I ran it unfortunately nothing worked. No message appeared.
Message 15 of 30

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

EESignature

(Not an Autodesk Employee)

Message 16 of 30

Attached is a text file for another code you can try, if those edits to not work.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 17 of 30

It works. The only problem was that it should be "Zaichnung-Name" and not "Zeichung-Name. I corrected the expression and everything works. Thank you very much
Message 18 of 30

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

Message 19 of 30

I notice now that the only thing missing is the designation for the items from the top-level assembly
autodesk0343ART_0-1711055934181.png

 

Message 20 of 30

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

EESignature

(Not an Autodesk Employee)

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report