Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Journal Help! Add attributes to a part/asm/drw

Status
Not open for further replies.

Azakalabaza

Electrical
Jul 31, 2020
1
Hello All,
I hope you can help me with some advice for NX12 Journal, I need to create a macro that adds specific attributes to a part, assembly and drawings but I am not sure how journal can identify if I am using a part assembly or drawing and also if we have part in millimetres or inches

In short words:
1.- Identify if it is a part / assembly / drawing.
2.- Identify if units are mm / inches


So we have different scenarios:

Part in mm
AttributeA Value = A mm
AttributeB Value = B mm
AttributeC Value = C mm

Part in inches
AttributeA Value = A in
AttributeB Value = B in
AttributeC Value = C mm

Assembly in mm
AttributeD Value = D mm
AttributeE Value = E mm
AttributeF Value = F mm

Assembly in inches
AttributeD Value = D in
AttributeE Value = E in
AttributeF Value = F in

Drawing in mm
AttributeX Value = X mm
AttributeY Value = Y mm
AttributeZ Value = Z mm

Drawing in inches
AttributeX Value = X in
AttributeY Value = Y in
AttributeZ Value = Z in

So basically I can create the parameters with Journal but I do not know how to add if statements and get the function to identify type of file and units.

Thanks.

 
Replies continue below

Recommended for you

In NX part can be also an assembly and drawing (non-master part). It will be difficult to check it. How do you want to play journal? On each part in directory, on assembly, on opened part?

With best regards
Michael
 
Azakalabaza, This is a C# journal which is made according to below logic.

Logic:
Any file(part or assembly) which is having at lest one drawing view will be considered as a drawing.
Else the file is having assembly structure ( no drawing views) will be considered as an Assembly.
In case of no drawing views and structure will be considered as part.

Please run below journal if it can solve your purpose.




using System;
using System.Collections;
using NXOpen;
using NXOpen.Assemblies;
using NXOpen.Drawings;
using NXOpenUI;

public class AttributeCreate
{
public static string GetTyp(Part w)
{

string k = "none";



if (w.DraftingViews.ToArray().Length > 0)
{
k = "dwg";

}

else if(w.ComponentAssembly.RootComponent != null)
{
k = "assy";
}

else
{
k = "part";
}


return k;
}






public static void Main(string[] args)
{
NXOpen.Session theSession = NXOpen.Session.GetSession();

UI theUI = UI.GetUI();

Part wp = theSession.Parts.Work;

Part dp = theSession.Parts.Display;

ListingWindow lw = theSession.ListingWindow;








try
{

string typ = "none";

string unts = wp.PartUnits.ToString();

typ = GetTyp(wp);

string at1= "",at2= "",at3 = "";

string at1val="", at2val="", at3val = "";

if (typ == "part")

{
at1 = "A";
at2 = "B";
at3 = "C";

}
else if (typ == "assy")
{
at1 = "D";
at2 = "E";
at3 = "F";
}

else if (typ == "dwg")
{
at1 = "X";
at2 = "Y";
at3 = "Z";
}


at1val = at1 + unts;
at2val = at2 + unts;
at3val = at3 + unts;



NXObject[] n = new NXObject[1];

n[0] = wp;


AttributePropertiesBuilder atb1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(wp, n, AttributePropertiesBuilder.OperationType.None);

atb1.SetAttributeObjects(n);

atb1.Title = at1;

atb1.StringValue = at1val;

atb1.Commit();

atb1.Title = at2;

atb1.StringValue = at2val;

atb1.Commit();

atb1.Title = at3;

atb1.StringValue = at3val;

atb1.Commit();


lw.Open();
lw.WriteFullline("This is :- " + typ + " and the Units are :-" + unts);





}

catch (Exception ex)
{
theUI.NXMessageBox.Show("Warning", NXMessageBox.DialogType.Warning, ex.ToString());

}




}

public static int GetUnloadOption(string dummy) { return (int)NXOpen.Session.LibraryUnloadOption.Immediately; }

}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor