cancel
Showing results for 
Search instead for 
Did you mean: 

SetInstanceUserAttribute vs SetUserAttribute on nested component groups

Creator
Creator

NX 9

2015_05_13_16_12_13_NX_9_Modeling_99999_99879_BOM_1.0_WITH_BOM2.0_DETAILS_.png

Currently we have software in place that is updating finish, finish spec and finish_color using "SetUserAttribute" but when "Make Display Part" is selected for sub assemblies is selected from the grid these values are not set. Talked to a siemens rep and he "suggested" I use "SetInstanceUserAttribute". What is the difference and could someone post a snippet.  I've added the source where the update is accomplished and starts withUpDNXSessionFrom_dgvAssemblies. Thanks guys and gals.

garaber

5 REPLIES

Re: SetInstanceUserAttribute vs SetUserAttribute on nested component groups

Valued Contributor
Valued Contributor
Maybe you set the attribute in the component instead of the part? You can check it in the component properties and see if it makes a difference.
W10 NX11.0.1

Re: SetInstanceUserAttribute vs SetUserAttribute on nested component groups

Creator
Creator

I believe were are setting for both part and component.

 

        private void SetAttribute(object toSet, string attrName, string value, IEnumerable<NXObject.AttributeInformation> attrList)
        {
            if (toSet is Part || toSet is Component)
            {

                var attr = attrList.FirstOrDefault(ii => ii.Title == attrName);
                if (attr.Title == null)
                {
                    attr = new NXObject.AttributeInformation { StringValue = value, Title = attrName, Category = "ItemRevision Master", Type = NXObject.AttributeType.String };
                }

                attr.StringValue = value;
                //var method = toSet.GetType().GetMethods().FirstOrDefault(mi => mi.Name == "SetInstanceUserAttribute");
                var method = toSet.GetType().GetMethods().FirstOrDefault(mi => mi.Name == "SetUserAttribute");
                if (method != null)
                {
                    method.Invoke(toSet, new object[] { attr, NXOpen.Update.Option.Now });
                }
            }
            else
            {
                throw new Exception("The developer has input the wrong values.");
            }
        }

Re: SetInstanceUserAttribute vs SetUserAttribute on nested component groups

Honored Contributor
Honored Contributor

That is the code that will create the attribute on whatever object it is given (well, whatever component or part anyway). We need to look deeper into the code to see what object type is being passed to this function. The SetAttribute function is called by the SetObjectAttributes function which will pass in either a component or a part. It will pass in a component if the component.DisplayName does not equal the _part.FullPath.

 

foreach (var component in list)
{
   if (component.DisplayName != _part.FullPath)
   {
      OpenComponent(component);
      SetObjectAttributes(component, row);
      //Session.GetSession().Parts.SetWork(_part);
      Session.GetSession().Parts.SetDisplay(_part, false, true, out loadStatus);
      Session.GetSession().Parts.Display.Save(BasePart.SaveComponents.True, BasePart.CloseAfterSave.False);
      //Session.GetSession().Parts.SetDisplay(_part, false, true, out loadStatus);
   }
   else
   {
      SetObjectAttributes(_part, row);
   }
}

 

In short, the code will assign an attribute to either a component or a part, but not to both. It appears to be assigning the attributes to the components - evidenced by the fact that you cannot see them at the part level (when you make the part the displayed part).

Re: SetInstanceUserAttribute vs SetUserAttribute on nested component groups

Creator
Creator

That is exactly what I came to find out.  Thanks for the confirmation.

Re: SetInstanceUserAttribute vs SetUserAttribute on nested component groups

Creator
Creator

yeah we discovered this. We are now takeing  the component casting the prototype to a part and setting the attributes that way as well as setting attributes the previous way.

                            ((Part)component.Prototype).SetUserAttribute("FINISH_SPEC", -1, row.Cells["FinishSpec"].Value.ToString(), NXOpen.Update.Option.Now);
                            ((Part)component.Prototype).SetUserAttribute("FINISH", -1, row.Cells["Color"].Value.ToString(), NXOpen.Update.Option.Now);
                            ((Part)component.Prototype).SetUserAttribute("FINISH_COLORNAME", -1, txtColorName.Text, NXOpen.Update.Option.Now);

There is only one problem remaining. We are not picking up the part for 99999-99879-5 hosted down in 99999-99879-3. I've add a new post showing some of the debug as well