cancel
Showing results for 
Search instead for 
Did you mean: 

Delete empty attribute

Legend
Legend

Hi,

I've this code that delete empty attribute.

using System;
using NXOpen;

public class NXJournal
{
  public static void Main(string[] args)
  {
    Session theSession = Session.GetSession();
    Part workPart = theSession.Parts.Work;
    
    NXObject[] objects1 = new NXObject[1];
    objects1[0] = workPart;
    AttributePropertiesBuilder attributePropertiesBuilder1;
    attributePropertiesBuilder1 = workPart.PropertiesManager.CreateAttributePropertiesBuilder(objects1);
    
    attributePropertiesBuilder1.IsArray = false;
    
    attributePropertiesBuilder1.StringValue = "";
   
    attributePropertiesBuilder1.Category = "";
    
    attributePropertiesBuilder1.Title = "";
    
    attributePropertiesBuilder1.Delete(workPart);
    
    NXObject nXObject1;
    nXObject1 = attributePropertiesBuilder1.Commit();
    
    attributePropertiesBuilder1.Destroy();
    
  }
  public static int GetUnloadOption(string dummy) { return (int)Session.LibraryUnloadOption.Immediately; }
}

 This works fine, but if the part hasn't an empty attribute give an error.

Can someone correct the code ?

Thank you...

Using NX 11 / RuleDesigner PDM

5 REPLIES

Re: Delete empty attribute

Siemens Valued Contributor Siemens Valued Contributor
Siemens Valued Contributor

replace attributePropertiesBuilder1.Delete(workPart); with

if (attributePropertiesBuilder1.ArrayIndex>0)

attributePropertiesBuilder1.Delete(workPart);

Re: Delete empty attribute

Legend
Legend

Doesn't work.

error.png

Thank you...

Using NX 11 / RuleDesigner PDM

Re: Delete empty attribute

Esteemed Contributor
Esteemed Contributor

The problem is the trailing semi-colon ( ; ), since the condition isn't used for the delete method.

 

You need to make sure to really use the code as posted or on one and the same line.

 

First way of doing it:

if (attributePropertiesBuilder1.ArrayIndex>0)
    attributePropertiesBuilder1.Delete(workPart);

 

Second way of doing it:

if (attributePropertiesBuilder1.ArrayIndex>0) attributePropertiesBuilder1.Delete(workPart);

 

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX12.0

How to Get the Most from Your Signature in the Community

Re: Delete empty attribute

Legend
Legend
Thank you Stefan,
it's works fine.
Thank you...

Using NX 11 / RuleDesigner PDM

Re: Delete empty attribute

Siemens Valued Contributor Siemens Valued Contributor
Siemens Valued Contributor
cubalibre00 you made a mistake while pasting my code.