Change a customer Iproperties

Change a customer Iproperties

kernal088
Explorer Explorer
372 Views
5 Replies
Message 1 of 6

Change a customer Iproperties

kernal088
Explorer
Explorer

Hi, I am using frame generator and using the attached code to change some properties

but I would like to also change a Custom Iproperties at the same time

 

 

Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oTransaction As Transaction = ThisApplication.TransactionManager.StartTransaction(oAsm, "FG base unit to each") 'Make this a single transaction
For Each oDoc As Document In oAsm.AllReferencedDocuments 'Traverse all referenced documents
If oDoc.DocumentInterests.HasInterest("{AC211AE0-A7A5-4589-916D-81C529DA6D17}") _'Frame generator component
AndAlso oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject _'Part
AndAlso oDoc.IsModifiable _ 'Modifiable (not reference skeleton)
AndAlso oAsm.ComponentDefinition.Occurrences.AllReferencedOccurrences(oDoc).Count > 0 'Exists in assembly (not derived base component)
oDoc.ComponentDefinition.BOMQuantity.SetBaseQuantity(BOMQuantityTypeEnum.kEachBOMQuantity)
End If
Next
oTransaction.End 'End the trasaction

 

Thank you Ron

 

0 Likes
373 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

Hi @kernal088.  It doesn't look like you are currently accessing or editing any iProperties within your posted code.  However, here is a little tip on accessing the 'custom' iProperties of the referenced document.

Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oTransaction As Transaction = ThisApplication.TransactionManager.StartTransaction(oAsm, "FG base unit to each") 'Make this a single transaction
For Each oDoc As Document In oAsm.AllReferencedDocuments 'Traverse all referenced documents
	If oDoc.DocumentInterests.HasInterest("{AC211AE0-A7A5-4589-916D-81C529DA6D17}") _'Frame generator component
		AndAlso oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject _'Part
		AndAlso oDoc.IsModifiable _ 'Modifiable (not reference skeleton)
		AndAlso oAsm.ComponentDefinition.Occurrences.AllReferencedOccurrences(oDoc).Count > 0 'Exists in assembly (not derived base component)
		oDoc.ComponentDefinition.BOMQuantity.SetBaseQuantity(BOMQuantityTypeEnum.kEachBOMQuantity)
		Dim oCustomPropSet As PropertySet = oDoc.PropertySets.Item(4)
		Try
			'the custom iProperty may not exist
			oCustomPropSet.Item("MyProperty").Value = "MyValue"
		Catch
			'it failed to get that custom iProperty
			'you could create the needed custom iProperty here if needed
			MsgBox("Custom iProperty not found.", , "")
		End Try
	End If
Next
oTransaction.End 'End the trasaction

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 want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

kernal088
Explorer
Explorer
Thank you
But did not work for me

0 Likes
Message 4 of 6

WCrihfield
Mentor
Mentor

Did nothing happen?  Did the message within the Catch section show?  Did an error message show.  If an error message showed, then can you maybe attach a screen captured image of the data within both tabs of that error message, so I can attempt to interpret the problem.

Did you change the name of the custom iProperty in that line of code, because that was just an example, and I have no idea what your custom iProperty's name is.  The Value I was giving that custom iProperty in the code is also just an example, and I have no idea what value you may be looking for or want to set/change it to.  Within the Try portion of the Try...Catch block, replace "MyProperty" with the name of the custom iProperty you are looking for.  Then replace "MyValue" with the value you want to give it.  By default there are no 'custom' iProperties in the 'custom' iProperty set.  And if it is possible that the custom iProperty doesn't exist in any of these other documents, it will throw an exception (error) when you try to access that non-existing custom iProperty.  That's why I have that line within a Try...Catch block, to avoid that potential error from stopping the main flow of the rule, while letting you know about any failures with a message.  The custom iProperty set's official name is "Inventor User Defined Properties", and it is always Item(4) of every document's PropertySets, and oDoc.PropertySets.Item("Inventor User Defined Properties") also gets that property set by name.  But there is no guarantee that any of the Item(s) within that PropertySet are going to be there, unless you've specifically created them within all the documents you are attempting to access.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 6

kernal088
Explorer
Explorer

Ok, I updated the Code but my custom USER PARAMETERS will not change to what I need

I do not get an error msg

 

Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oTransaction As Transaction = ThisApplication.TransactionManager.StartTransaction(oAsm, "FG base unit to each") 'Make this a single transaction
For Each oDoc As Document In oAsm.AllReferencedDocuments 'Traverse all referenced documents
	If oDoc.DocumentInterests.HasInterest("{AC211AE0-A7A5-4589-916D-81C529DA6D17}") _'Frame generator component
		AndAlso oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject _'Part
		AndAlso oDoc.IsModifiable _	'Modifiable (not reference skeleton)
		AndAlso oAsm.ComponentDefinition.Occurrences.AllReferencedOccurrences(oDoc).Count > 0 'Exists in assembly (not derived base component)
		PL_LENGTH = G_L	
		oDoc.ComponentDefinition.BOMQuantity.SetBaseQuantity(BOMQuantityTypeEnum.kEachBOMQuantity)

		
		Dim oCustomPropSet As PropertySet = oDoc.PropertySets.Item(4)

		Try
			'the custom iProperty may not exist
			oCustomPropSet.Item("PL_LENGTH").Value = "MyValue"
		Catch
			'it failed to get that custom iProperty
			'you could create the needed custom iProperty here if needed
			MsgBox("Custom iProperty not found.", , "")
		End Try
	End If
Next
oTransaction.End 'End the trasaction
0 Likes
Message 6 of 6

WCrihfield
Mentor
Mentor

Now I'm further confused.  This post is labeled "Change a customer iProperties", and in your first post you mentioned "properties" & "Custom Iproperties", so I was assuming you were trying to find/check/edit one or more iProperties.  But then in your last post you are talking about "custom USER PARAMETERS".  Which is it, iProperties or user parameters?  They are two different things, and are accessed & worked with differently from each other.  In your last post, you included the line "PL_LENGTH = G_L".  This looks to me like "PL_LENGTH" and "G_L" were both local parameters, and you were attempting to assign the value of "G_L" as the value of "PL_LENGTH".  If that true then the fallowing code should help you achieve that goal.  You will notice that I am now accessing the parameters of the referenced document, instead of its iProperties, and now that I have the correct name of those parameters involved, the code might have a change at success.  You will also notice that I added a line in there to save the referenced document after those changes, so that any edits made won't be lost.

Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oTransaction As Transaction = ThisApplication.TransactionManager.StartTransaction(oAsm, "FG base unit to each") 'Make this a single transaction
For Each oDoc As Document In oAsm.AllReferencedDocuments 'Traverse all referenced documents
	If oDoc.DocumentInterests.HasInterest("{AC211AE0-A7A5-4589-916D-81C529DA6D17}") _'Frame generator component
		AndAlso oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject _'Part
		AndAlso oDoc.IsModifiable _	'Modifiable (not reference skeleton)
		AndAlso oAsm.ComponentDefinition.Occurrences.AllReferencedOccurrences(oDoc).Count > 0 Then 'Exists in assembly (not derived base component)
		Dim oPDoc As PartDocument = oDoc
		Dim oParams As Inventor.Parameters = oPDoc.ComponentDefinition.Parameters
		Try
			oParams.Item("PL_LENGTH").Value = oParams.Item("G_L").Value
		Catch oEx As Exception
'			MsgBox("Failed to change 'PL_LENGTH' parameter value." & vbCrLf & _
'			oEx.Message & vbCrLf & oEx.StackTrace, , "")
		End Try
		oPDoc.ComponentDefinition.BOMQuantity.SetBaseQuantity(BOMQuantityTypeEnum.kEachBOMQuantity)
		oPDoc.Save2(False)
	End If
Next
oTransaction.End 'End the trasaction

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes