Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

NX Journal:retrieve attribute value(s) from parent part

Status
Not open for further replies.

nxexplorer

Mechanical
Jun 23, 2010
84
Hello,
I need help on NX Journal:
how retrieve attribute value(s) from parent part(one level assy). Appreciate for Any suggest.
Thank you,
NXExplorer
 
Replies continue below

Recommended for you

What version of NX are you using ?
Are you using TeamCenter ?

Jerry J.
UGV5-NX1961
 
Hi Jerry,
It is NX10.0.3.native nx, no teamcenter.
Regards,
Maryadi
 
Hi
In below journal an attribute named "CALLOUT" value will be copied from parent part to child part. Parent part is the displayed part and child part is the work part.
let me know is this approach for work for you or not we can modify the journal as per your requirement.



using System;
using NXOpen;
using NXOpenUI;
using NXOpen.Assemblies;

namespace ParentAttributes
{
public class NXAttributes

{
public static void Main()
{
Session theSession = Session.GetSession();
UI theUI = UI.GetUI();
ListingWindow lw = theSession.ListingWindow;

try
{
Part wp = theSession.Parts.Work;
Part dp = theSession.Parts.Display;

Component pt = dp.ComponentAssembly.RootComponent; // Check the assembly is valid or not

if (pt != null)
{

BasePart parent = pt.OwningPart;

String at_val = parent.GetStringUserAttribute("CALLOUT", -1);

wp.SetUserAttribute("CALLOUT", -1, at_val, Update.Option.Now);



lw.Open();

lw.WriteFullline(pt.OwningPart.Leaf + " Attribute value: "+at_val+ " is copied to " + wp.Leaf);


}

else
{
theUI.NXMessageBox.Show("NXAttribute Tool", NXMessageBox.DialogType.Information, "This is not a valid Assembly");
}




}
catch (Exception ex)
{

theUI.NXMessageBox.Show("NXAttributes", NXMessageBox.DialogType.Error, ex.ToString());

}

}

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

}
}
 
Hi Ram K,
Thank you for your suggestion, I will try your codes.
Actually, my requirement is in assembly when the child part as work part, asking the mother part whether it has a specific attribute or not.

Thank you,
Maryadi
 
Hi Maryadi,
Current code will copy the attribute value from mother part to child(work part). We can tweak this code to get your desired result, by adding "if" condition to check the attribute existence.

===========================
if (pt != null)
{
BasePart parent = pt.OwningPart;

if( parent.GetUserAttributeAsString(){} //To get Attribute names
}

Ram K
ramkan8@gmail.com
 
Hi Ram K

I will make some changes to it to adjust for my requirements.
Thank you for your journal.

Regards,
Maryadi
 
Hi Ram K
Here I have edited your C# Journal above, become vb.net. Maybe someone needs it in vb.
Once again, Thank you.
Regards,
Maryadi

'****************************************************************
'By: Maryadi - Edited from C# Journal by. Ram K *
'****************************************************************
Option Strict Off

Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Imports NXOpen.Assemblies

Module NXJournal

Dim theSession As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim lw As ListingWindow = theSession.ListingWindow

Sub Main()
try
Dim wp As Part = theSession.Parts.Work
Dim dp As Part = theSession.Parts.Display
Dim pt As Component = dp.ComponentAssembly.RootComponent
Dim null As System.DBNull
Dim theUI As UI = UI.GetUI()
if Not String.IsNullOrEmpty(pt.ToString)
Dim parent As BasePart = pt.OwningPart
Dim at_val As String = parent.GetStringUserAttribute("Project Number", -1)
wp.SetUserAttribute("Project Number", -1, at_val, Update.Option.Now)
lw.Open()
lw.WriteFullline(pt.OwningPart.Leaf + " Attribute value: "+at_val+ " is copied to " + wp.Leaf)
else
theUI.NXMessageBox.Show("NXAttribute Tool", NXMessageBox.DialogType.Information, "This is not a valid Assembly")
End If
Catch ex As Exception
Dim theUI As UI = UI.GetUI()
theUI.NXMessageBox.Show("NXAttributes", NXMessageBox.DialogType.Error, ex.ToString())
End Try
End Sub
End Module
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor