Showing results for 
Search instead for 
Do you mean 
Reply
Solved! Go to solution

Delete empty attribute

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
Solution
Solution
Accepted by topic author cubalibre00
‎08-26-2015 04:32 AM

Re: Delete empty attribute

replace attributePropertiesBuilder1.Delete(workPart); with

if (attributePropertiesBuilder1.ArrayIndex>0)

attributePropertiesBuilder1.Delete(workPart);

Re: Delete empty attribute

Doesn't work.

Thank you...

Using NX 11 / RuleDesigner PDM

Solution
Solution
Accepted by topic author cubalibre00
‎08-26-2015 04:32 AM

Re: Delete empty attribute

[ Edited ]

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: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community

Re: Delete empty attribute

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

Using NX 11 / RuleDesigner PDM

Re: Delete empty attribute

cubalibre00 you made a mistake while pasting my code.