cancel
Showing results for 
Search instead for 
Did you mean: 

Not able to modify NXObject.Attributes value (NX9.0)

Pioneer
Pioneer

Hi, 

 

When im trying to change the value of an existing Attribute i'm getting an error

 

Tried following,

string sAttName = "Test";
Part workPart = Session.GetSession().Parts.Work; 
DrawingSheet currentDrawingSheet = workPart.DrawingSheets.CurrentDrawingSheet;

Case 1:
		currentDrawingSheet.SetAttribute("Test", (double)NewValue + 10.0);
Case 2: 
		NXObject.AttributeInformation nxInfo = default(NXObject.AttributeInformation);
		nxInfo.Title = sAttName;
		nxInfo.RealValue = NewValue + 10.0;
		currentDrawingSheet.SetUserAttribute(nxInfo, Update.Option.Later);
Case 3: 
		NXObject[] objects1 = new NXObject[1];
		objects1[0] = (NXObject)currentDrawingSheet;
		AttributePropertiesBuilder attributePropertiesBuilder1;
		attributePropertiesBuilder1 = Session.GetSession().AttributeManager.CreateAttributePropertiesBuilder(workPart, objects1, NXOpen.AttributePropertiesBuilder.OperationType.None);
		attributePropertiesBuilder1.SetAttributeObjects(objects1);
		attributePropertiesBuilder1.Category = "";
		attributePropertiesBuilder1.IsArray = false;
		attributePropertiesBuilder1.Title = sAttName;
		attributePropertiesBuilder1.DataType = NXOpen.AttributePropertiesBaseBuilder.DataTypeOptions.Real;
		attributePropertiesBuilder1.Units = "mm";
		attributePropertiesBuilder1.RealValue = sValue;
		attributePropertiesBuilder1.Commit();
		attributePropertiesBuilder1.Destroy();

In all Cases Im Getting the following error

Attribute_ValueSetting_Error.JPG

 

Can anybody tel me why i cannot able to set the value.

 

Regards,

Maddy

 

 

Windows 7 x64
NX 8.5, NX 9.0. And also NX 7.5
Visual Studio 2010 SP1, 2012 Update 4
7 REPLIES

Re: Not able to modify NXObject.Attributes value (NX9.0)

Pioneer
Pioneer

 

Sorry code in Case 3 is this.

 

                attributePropertiesBuilder1.DataType = NXOpen.AttributePropertiesBaseBuilder.DataTypeOptions.Number;
                attributePropertiesBuilder1.Units = "";
                attributePropertiesBuilder1.NumberValue = (double)(iActualTablePos + 10.0);
Windows 7 x64
NX 8.5, NX 9.0. And also NX 7.5
Visual Studio 2010 SP1, 2012 Update 4

Re: Not able to modify NXObject.Attributes value (NX9.0)

Phenom
Phenom

What is the current definition of the attribute (what type {string, number, boolean, etc} and units, if any)?

Re: Not able to modify NXObject.Attributes value (NX9.0)

Pioneer
Pioneer
It is of real type with only one value and unit is mm
Windows 7 x64
NX 8.5, NX 9.0. And also NX 7.5
Visual Studio 2010 SP1, 2012 Update 4

Re: Not able to modify NXObject.Attributes value (NX9.0)

Phenom
Phenom

So, in essence, your code is trying to remove the units from the attribute, which is not allowed.

Re: Not able to modify NXObject.Attributes value (NX9.0)

Esteemed Contributor
Esteemed Contributor

So it looks like you should be able to:

- keep the units, just set the value

or

- delete the attribute & re-create it without units

 

Ken Akerboom Sr CAx Systems Engr, Moog, Inc.
Production: NX10.0.3.5 MP5 + patch/TC11.2
I'd rather be e-steemed than e-diseaseled


Re: Not able to modify NXObject.Attributes value (NX9.0)

Pioneer
Pioneer

Hi,

 

@cowski

In Case 3 : Even i tried putting mm in units, then also it was giving the same error.

 

Case 1: Also produces the same error.

currentDrawingSheet.SetAttribute("Test", (double)NewValue + 10.0);

 Case 2:Also produces the same error.

NXObject.AttributeInformation nxInfo = default(NXObject.AttributeInformation);
		nxInfo.Title = sAttName;
		nxInfo.RealValue = NewValue + 10.0;
		currentDrawingSheet.SetUserAttribute(nxInfo, Update.Option.Later);

 

 

 

 

@Ken_A

- keep the units, just set the value

     Does not work and it produces the same error.

or

- delete the attribute & re-create it without units

           This is what i found as a work around.

 

But need to know why it was not possible to set the value. even after trying so many ways.

 

NXObject.SetUserAttribute has 5 overloading options, none of them are giving me the results.

 SetUserAttribute(NXObject.AttributeInformation info, Update.Option option) 		Creates or modifies an attribute with the option to update or not.  
 SetUserAttribute(String title, Int32 index, Int32 value, Update.Option option) 	Creates or modifies an integer attribute with the option to update or not.  
 SetUserAttribute(String title, Int32 index, Double value, Update.Option option) 	Creates or modifies a real attribute with the option to update or not.  
 SetUserAttribute(String title, Int32 index, String value, Update.Option option) 	Creates or modifies a string attribute with the option to update or not.  
 SetUserAttribute(String title, Int32 index, Update.Option option) 					Creates or modifies a null attribute with the option to update or not.  

 

 

Regards,

Maddy

 

 

Windows 7 x64
NX 8.5, NX 9.0. And also NX 7.5
Visual Studio 2010 SP1, 2012 Update 4

Re: Not able to modify NXObject.Attributes value (NX9.0)

Phenom
Phenom

Fire up the journal recorder and edit the attribute of interest. If the operation completes successfully, examine the code that was recorded.