Cancel
Showing results for 
Search instead for 
Did you mean: 

How to set sheet attribute of "Date" type using API in NX Drawing?

Pioneer
Pioneer

Hi ,

Is there any specific way  to set the "Date" type attribute on NX DrawingSheet object. 

 

Use case :

1. Create NX-Drawing having drawing sheet.

2. Add manually attribute of type "Date"on drawing sheet.

3. Now by using API's try to modify the value.

4. In my case it is thrwoing exceptions as "The date value is invalid".

 

API Used for setting attribute:

if(attrInfo.Title=="TestDate")

{

attrInfo.TimeValue ="2016/11/30 12:45:00";

drawingSheet.SetUserAttribute(attrInfo, Update.Option.Now);

}

 

Thanks in Advance.

 

Regards,

OnkarP

4 REPLIES

Re: How to set sheet attribute of "Date" type using API in NX Drawing?

Esteemed Contributor
Esteemed Contributor

Have you tries recording a journal of you manually setting the date?

 

I have successfully set a part attribute of type "date" with this code.

Offhand, I don't recall why I'm using the string for year, instead of the integer in Date_Attribute_struct:

 

struct Date_Attribute_struct {
	int Day;
	int Month;
	int Year;
};

void SetDateTB_Attribute(std::string New_Attr_Value, Date_Attribute_struct& NX_DateInfo)
{
	std::vector<NXOpen::NXObject *> objects1(1);
	objects1[0] = m_workPart;
	NXOpen::AttributePropertiesBuilder *attributePropertiesBuilder1;
	attributePropertiesBuilder1 = theSession->AttributeManager()->CreateAttributePropertiesBuilder(m_workPart, objects1, NXOpen::AttributePropertiesBuilder::OperationTypeNone);
	attributePropertiesBuilder1->SetAttributeObjects(objects1);
    
	attributePropertiesBuilder1->SetCategory("YOUR_CATEGORY_HERE");
	attributePropertiesBuilder1->SetTitle("YOUR_TITLE_HERE");

	// date formatted as YYYYMMDD in string
	std::string strYear = New_Attr_Value.substr(0, 4);

	attributePropertiesBuilder1->SetDataType(NXOpen::AttributePropertiesBaseBuilder::DataTypeOptionsDate);
	attributePropertiesBuilder1->DateValue()->DateItem()->SetYear(strYear.c_str());
	attributePropertiesBuilder1->DateValue()->DateItem()->SetMonth((NXOpen::DateItemBuilder::MonthOfYear) NX_DateInfo.Month);
	attributePropertiesBuilder1->DateValue()->DateItem()->SetDay((NXOpen::DateItemBuilder::DayOfMonth)NX_DateInfo.Day);
	attributePropertiesBuilder1->DateValue()->DateItem()->SetTime("00:00:00");

	NXOpen::NXObject *nXObject1;
	nXObject1 = attributePropertiesBuilder1->Commit();
	attributePropertiesBuilder1->Destroy();
}
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: How to set sheet attribute of "Date" type using API in NX Drawing?

Pioneer
Pioneer

Hi Ken_A,

 

Thanks for the reply. I have tried jornal recording and got the same code.

Here my concern is why this API is not working only for attribute type of "Date" where as it works for all of the other type of attributes i.e . String, Integer, Real.

If any hint please let me know.

 

Regards,

Onkar 

Re: How to set sheet attribute of "Date" type using API in NX Drawing?

Pioneer
Pioneer

Hi Onkar,

 

Can't really comment on why it isn't working as the format looks correct. I tried two very simple VB examples using the SetTimeUserAttribute method and both seemed to work OK for me. In my example I created a part attribute called "DateTest". I then added a note on a drawing sheet which referenced this attribute (relationships -> insert part attribute -> DateTest). I then used the vb program to modify the part attribute

 

workpart.SetTimeUserAttribute("DateTest", -1, "2010/04/15 20:05:10", 0)

or

workpart.SetTimeUserAttribute("DateTest", -1, "15-Apr-2010 20:05:10", 0)

Geoff Donohoo

NX10.0.3.5 & TC 10.1.4.2
Dell T3600 32Gb Ram, Nvidia Quadro 4000
Windows 7

Re: How to set sheet attribute of "Date" type using API in NX Drawing?

Pioneer
Pioneer

Hi Geoff,

 

Yes. It is working correctly when we use SetTimeUserAttribute method. This method can work with the inputs mentioned in the API help.

 

When working with SetUserAttribute method it is not accepting the same input and throwng the exception as mentioned in discussion.

 

Thanks for the reply.

 

Regards,

Onkar