Adding value to part from withing the drawing does not work

Adding value to part from withing the drawing does not work

arkadiusz.budkowski
Participant Participant
418 Views
3 Replies
Message 1 of 4

Adding value to part from withing the drawing does not work

arkadiusz.budkowski
Participant
Participant

Hello,

Does anyone know why this is not working?

Sub Main()
	Dim oDoc As Inventor.DrawingDocument = ThisApplication.ActiveDocument

	Dim oSheet As Sheet = oDoc.ActiveSheet
	
	Dim oPartOnSheet As Inventor.PartDocument = oSheet.DrawingViews(1).ReferencedDocumentDescriptor.ReferencedDocument
	
	Dim userParams As Inventor.UserParameters = oPartOnSheet.ComponentDefinition.Parameters.UserParameters
	
	param = userParams.AddByValue("Uwaga_8", "", UnitsTypeEnum.kTextUnits)
	
	param.IsKey = True
	
End Sub


arkadiuszbudkowski_0-1682669838480.png

 

 
0 Likes
Accepted solutions (1)
419 Views
3 Replies
Replies (3)
Message 2 of 4

A.Acheson
Mentor
Mentor

Hi @arkadiusz.budkowski 

What inventor version are you using? Can you post the "more info" or "więcej informacji"

text of the error message? Also which line does it fail on? Adding the parameter or before or after? Place into the code a message box and step through the code untill you no longer see the message box but get the error message. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 4

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Hi @arkadiusz.budkowski . Your code works fine for me, but I added one check, I could be wrong, but it seems you are trying to create a parameter for components that cannot be modifiable.
 

Sub Main()
	Dim oDoc As Inventor.DrawingDocument = ThisApplication.ActiveDocument
	Dim oSheet As Sheet = oDoc.ActiveSheet	
	Dim oPartOnSheet As Inventor.PartDocument = oSheet.DrawingViews(1).ReferencedDocumentDescriptor.ReferencedDocument
	If oPartOnSheet.IsModifiable Then
		Dim userParams As Inventor.UserParameters = oPartOnSheet.ComponentDefinition.Parameters.UserParameters	
		Dim param as UserParameter = userParams.AddByValue("Uwaga_8", "", UnitsTypeEnum.kTextUnits)	
		param.IsKey = True	
	Else
		MessageBox.Show("Your component does not modifiable.", "Error!",MessageBoxButtons.OK,MessageBoxIcon.Error)
	End If
End Sub

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 4 of 4

arkadiusz.budkowski
Participant
Participant
I just now had time to come back to the problem and I don't know why but it started to work. Maybe it was an inventor random problem. I will use the updated code, seems more secure, thanks
0 Likes