Can you store occurence data in assembly?

Can you store occurence data in assembly?

viktorkulik
Contributor Contributor
462 Views
4 Replies
Message 1 of 5

Can you store occurence data in assembly?

viktorkulik
Contributor
Contributor

Is there a property or a method for saving some data that is related to a specific occurence in the assembly? Something like XDATA in autocad, but I don't want to save this information to the part, but to the occurence in the assembly.

 

Thanks.

0 Likes
Accepted solutions (1)
463 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

You can use Attributes.

ComponentOccurrence.AttributeSets Property 

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you have time, please... Vote For My IDEAS 💡or you can Explore My CONTRIBUTIONS

Inventor 2021 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

viktorkulik
Contributor
Contributor

Thanks, but that appears to be storing data on the parts, not on occurrence. If i have 5 occurences of the same part, they report the same attributeset, whereas I want to be able to write distinct data about each occurence. 

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor
Accepted solution

It's all in how you set it up.

Here's an example iLogic rule you can test with.

 

Sub Main
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("An Assembly Document must be active for this rule to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
	Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisAssembly.Document
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oCM As CommandManager = ThisApplication.CommandManager
'get two components to test on
Dim oComp1 As ComponentOccurrence = oCM.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select a 'top level' component.")
Dim oComp2 As ComponentOccurrence = oCM.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select a 'top level' component.")

'attempt to create the attribute on each one (Value should be different for each one, in order to tell them apart later)
TryAddAttribute(oComp1, "MySet", "ID", ValueTypeEnum.kStringType, "Comp One")
TryAddAttribute(oComp2, "MySet", "ID", ValueTypeEnum.kStringType, "Comp Two")

'now retrieve the components, based only on the different attribute values
Dim oCol1 As ObjectCollection = oADoc.AttributeManager.FindObjects("MySet", "ID", "Comp One")
Dim oComp1Returned As ComponentOccurrence = oCol1.Item(1)
Dim oCol2 As ObjectCollection = oADoc.AttributeManager.FindObjects("MySet", "ID", "Comp Two")
Dim oComp2Returned As ComponentOccurrence = oCol2.Item(1)
MsgBox("oCol1.Count = " & oCol1.Count & " and oComp1Returned.Name = " & oComp1Returned.Name, , "")
MsgBox("oCol2.Count = " & oCol2.Count & " and oComp2Returned.Name = " & oComp2Returned.Name, , "")
End Sub

Sub TryAddAttribute(oOcc As ComponentOccurrence, oSetName As String, oName As String, oValueType As ValueTypeEnum, oValue As Object)
	Dim oComp As ComponentOccurrence = oOcc
	Dim oSet As AttributeSet
	Dim oAtt As Attribute
	If oComp.AttributeSets.Count = 0 Then
		'there are no sets, so create the set, and the attribute
		oSet = oComp.AttributeSets.Add(oSetName, False)
		oAtt = oSet.Add(oName, oValueType, oValue)
		Exit Sub
	End If
	'There is more than one AttributeSet attached to it so check for 'this' set
	If oComp.AttributeSets.NameIsUsed(oSetName) Then
		'the set already exists so get it
		oSet = oComp.AttributeSets.Item(oSetName)
	Else
		'that set wasn't found, so create it, then create the attribute
		oSet = oComp.AttributeSets.Add(oSetName, False)
		oAtt = oSet.Add(oName, oValueType, oValue)
		Exit Sub
	End If
	'set was found, so check for the attribute
	If oSet.NameIsUsed(oName) Then
		'an attribute with that name was found so get it
		oAtt = oSet.Item(oName)
	Else
		'that attribute wasn't found, so create it
		oAtt = oSet.Add(oName, oValueType, oValue)
		Exit Sub
	End If
	'check the 'ValueType' of the existing attribute
	If oAtt.ValueType = oValueType Then
		If oAtt.Value = oValue Then
			MsgBox("That exact attribute already exists.  Exiting.", , "")
			Exit Sub
		Else
			'An attribute by that name and type already exist, but it has a different value
			MsgBox("An Attribute with that 'Name' and 'ValueType' already exists, but it has a different 'value'.", , "")
			Exit Sub
		End If
	Else
		'an attribute by that name was found, but it has a different ValueType, so let user know
		MsgBox("There is an existing Attribute by that name, but it has a different 'ValueType'." & vbCrLf & _
		"Moving on, without changing it and without creating a new one.", , "")
		Exit Sub
	End If
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 5 of 5

viktorkulik
Contributor
Contributor

Ah, the CopyWithOwner property on the AttributeSet?

AttributeSets.Add(oSetName, False)

0 Likes