facet representation

Hi,
i am creating facet representation of assembly,( assemblies->advanced->representations->create) using apis, after creating we should do deassociate so that the facet representation can be moved to particular layer,

below is the code , i am not able able to create representation through program, plz help?

using System;
using NXOpen;
using NXOpen.UF;
using System.Collections;

public class Program
{
// class members
private static Session theSession;
private static UI theUI;
private static UFSession theUfSession;
public static Program theProgram;
public static bool isDisposeCalled;
public static ArrayList component_list=new ArrayList ();
//------------------------------------------------------------------------------
// Constructor
//------------------------------------------------------------------------------
public Program()
{
try
{
theSession = Session.GetSession();
theUI = UI.GetUI();
theUfSession = UFSession.GetUFSession();
isDisposeCalled = false;
}
catch (NXOpen.NXException ex)
{
// ---- Enter your exception handling code here -----
// UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
}
}

//------------------------------------------------------------------------------
// Explicit Activation
// This entry point is used to activate the application explicitly
//------------------------------------------------------------------------------
public static int Main(string[] args)
{
int retValue = 0;
try
{
theProgram = new Program();
Part w = theSession.Parts.Work;
Part dis = theSession.Parts.Display;
NXOpen .Assemblies .Component cmp=w.ComponentAssembly.RootComponent;
NXOpen .Assemblies .Component []cmp_list=cmp.GetChildren();

Recursive( cmp,0);

IEnumerator en = component_list .GetEnumerator();

while (en.MoveNext())
{

Part one_part=(Part )en.Current;

BodyCollection bodies=one_part.Bodies;

Body []arr= one_part.Bodies.ToArray();
for (int i = 0; i < arr.Length; i++)
{
if (arr[i].IsSolidBody)
{
Body[] solidbodies3 = new Body[1];
solidbodies3[0] = arr[i];
NXOpen.Facet.FacetedBody[] facetbodies3;
int[] errortable3;
w.FacetedBodies.CreateFacetBody(solidbodies3, out facetbodies3, out errortable3);

theSession.CleanUpFacetedFacesAndEdges();

}
}

}

theProgram.Dispose();
}
catch (NXOpen.NXException ex)
{
// ---- Enter your exception handling code here -----

}
return retValue;
}

static void Recursive( NXOpen .Assemblies .Component comp ,int count)
{

foreach (NXOpen.Assemblies.Component component in comp.GetChildren ())
{
//Part wp=(Part )component.Prototype;
if (component .GetChildren ().Length == 0)
{
// list.Add(wp);
//NXOpen.Assemblies.Component[] req = new NXOpen.Assemblies.Component[1];
//req[0] = component;
//ErrorList err;
Part wp = (Part)component.Prototype;
//err =component.DisplayComponentsLightweight(req );
//err.Clear();
//theSession.CleanUpFacetedFacesAndEdges();
component_list.Add(wp);
}
else
{

}
Recursive(component ,count + 1);
}
// throw new Exception("End");

}

//------------------------------------------------------------------------------
// Following method disposes all the class members
//------------------------------------------------------------------------------
public void Dispose()
{
try
{
if (isDisposeCalled == false)
{
//TODO: Add your application code here
}
isDisposeCalled = true;
}
catch (NXOpen.NXException ex)
{
// ---- Enter your exception handling code here -----

}
}

public static int GetUnloadOption(string arg)
{
//Unloads the image explicitly, via an unload dialog
//return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);

//Unloads the image immediately after execution within NX
return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);

//Unloads the image when the NX session terminates
// return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);
}

}

> i am not able able to create representation through program

What does that mean? What happens when you run this code? Does it crash? What errors do you see? What gets written to the syslog?

Also, people would be more inclined to help you if you formatted your code properly (to make it more readable), and you removed all the extraneous stuff that's not related to your problem.

Hi Ciao,
the program is running properly,i have debug the program it returns facetbody also (w.FacetedBodies.CreateFacetBody(solidbodies3, out facetbodies3, out errortable3);)here
Repesentation is not getting created in NX, through upper code
I want to create facet representation of assembly & this facet representation should be in some particular layer

using System;
using NXOpen;
using NXOpen.UF;
using System.Collections;

public class Program
{
// class members
private static Session theSession;
private static UI theUI;
private static UFSession theUfSession;
public static Program theProgram;
public static bool isDisposeCalled;
public static ArrayList component_list=new ArrayList ();
//------------------------------------------------------------------------------
// Constructor
//------------------------------------------------------------------------------
public Program()
{
try
{
theSession = Session.GetSession();
theUI = UI.GetUI();
theUfSession = UFSession.GetUFSession();
isDisposeCalled = false;
}
catch (NXOpen.NXException ex)
{
// ---- Enter your exception handling code here -----
// UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
}
}

//------------------------------------------------------------------------------
// Explicit Activation
// This entry point is used to activate the application explicitly
//------------------------------------------------------------------------------
public static int Main(string[] args)
{
int retValue = 0;
try
{
theProgram = new Program();
Part w = theSession.Parts.Work;
Part dis = theSession.Parts.Display;
NXOpen .Assemblies .Component cmp=w.ComponentAssembly.RootComponent;
NXOpen .Assemblies .Component []cmp_list=cmp.GetChildren();

Recursive( cmp,0);

IEnumerator en = component_list .GetEnumerator();

while (en.MoveNext())
{

Part one_part=(Part )en.Current;

BodyCollection bodies=one_part.Bodies;

Body []arr= one_part.Bodies.ToArray();
for (int i = 0; i < arr.Length; i++)
{
if (arr[i].IsSolidBody)
{
Body[] solidbodies3 = new Body[1];
solidbodies3[0] = arr[i];
NXOpen.Facet.FacetedBody[] facetbodies3;
int[] errortable3;
w.FacetedBodies.CreateFacetBody(solidbodies3, out facetbodies3, out errortable3);

theSession.CleanUpFacetedFacesAndEdges();

}
}

}

theProgram.Dispose();
}
catch (NXOpen.NXException ex)
{
// ---- Enter your exception handling code here -----

}
return retValue;
}

static void Recursive( NXOpen .Assemblies .Component comp ,int count)
{

foreach (NXOpen.Assemblies.Component component in comp.GetChildren ())
{
if (component .GetChildren ().Length == 0)
{
Part wp = (Part)component.Prototype;
component_list.Add(wp);
}
else
{

}
Recursive(component ,count + 1);
}
// throw new Exception("End");

}

//------------------------------------------------------------------------------
// Following method disposes all the class members
//------------------------------------------------------------------------------
public void Dispose()
{
try
{
if (isDisposeCalled == false)
{
}
isDisposeCalled = true;
}
catch (NXOpen.NXException ex)
{
// ---- Enter your exception handling code here -----

}
}

public static int GetUnloadOption(string arg)
{
return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);
}

}

Unfortunately, I don't have access to an advanced assemblies license, so I cannot test or tweak your code. However, you state that the facet bodies are returned. If this is the case, you should be able to change the layer property and redisplay the object or use a display modification object to change the facet body's layer.

Hi,
I have written a code for facet creation, the only problem i am facing is , i am not able to move facets to layer, i have tried several methods but unsuccesful.

using System;
using NXOpen;
using NXOpen.UF;
using NXOpenUI;
using System.Collections;

public class Program
{
// class members
private static Session theSession;
private static UI theUI;
private static UFSession theUfSession;
public static Program theProgram;
public static bool isDisposeCalled;
public static ArrayList component_list=new ArrayList ();
//------------------------------------------------------------------------------
// Constructor
//------------------------------------------------------------------------------
public Program()
{
try
{
theSession = Session.GetSession();
theUI = UI.GetUI();
theUfSession = UFSession.GetUFSession();
isDisposeCalled = false;
}
catch (NXOpen.NXException ex)
{
// ---- Enter your exception handling code here -----
// UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
}
}

//------------------------------------------------------------------------------
// Explicit Activation
// This entry point is used to activate the application explicitly
//------------------------------------------------------------------------------
public static int Main(string[] args)
{
int retValue = 0;
try
{
theProgram = new Program();
Part w = theSession.Parts.Work;
Part dis = theSession.Parts.Display;

NXOpen.Assemblies.Component cmp = w.ComponentAssembly.RootComponent;

NXOpen.Assemblies.Component[] cmp_list1 = new NXOpen.Assemblies.Component[2];
NXOpen.Assemblies.Component[] cmp_list = cmp.GetChildren();

DisplayableObject[] objects1 = new DisplayableObject[1];

PartLoadStatus pls;
Recursive(cmp, 0);

IEnumerator en = component_list.GetEnumerator();
Tag model_1 = new Tag();
NXOpen.UF.UFFacet ufface = theUfSession.Facet;
NXOpen.UF.UFFacet.Parameters parm;
Tag rep = new Tag();

NXObject nXObject1;
ArrayList list_of_objects=new ArrayList ();

while (en.MoveNext())
{

Part one_part = (Part)en.Current;

BodyCollection bodies = one_part.Bodies;
UFFacet .Parameters prs;
theSession.Parts.SetWork(one_part);

Body[] arr = one_part.Bodies.ToArray();
for (int i = 0; i < arr.Length; i++)
{
if (arr[i].IsSolidBody)
{

theUfSession.Facet.AskDefaultParameters(out parm);

theUfSession.Facet.FacetSolid(arr[i].Tag, ref parm, out rep);
theUfSession.Facet.DisassocFromSolid(rep);

theUfSession.Facet.AskModelParameters(rep, out prs);

NXOpen .Facet .FacetedBody []fc_collection= one_part.FacetedBodies.ToArray();
NXObject[] objects12 = new NXObject[fc_collection .Length ];
for (int j = 0; j < fc_collection.Length; j++)
{
objects12[j] = fc_collection[j];
theUfSession.Obj.SetLayer(fc_collection[j].Tag, 250);
list_of_objects.Add(fc_collection);

}

}
}

}

}

catch (NXOpen.NXException ex)
{
// ---- Enter your exception handling code here -----

}
return retValue;
}

static void reportPartLoadStatus(PartLoadStatus load_status)
{
if (load_status.NumberUnloadedParts == 0) return;

Echo(" Load notes:");

for (int ii = 0; ii < load_status.NumberUnloadedParts; ii++)
{
Echo(" " + load_status.GetPartName(ii) + " - "
+ load_status.GetStatusDescription(ii));
}
}

public static void Echo(string output)
{
theSession.ListingWindow.Open();
theSession.ListingWindow.WriteLine(output);
theSession.LogFile.WriteLine(output);
}

static void Recursive( NXOpen .Assemblies .Component comp ,int count)
{

foreach (NXOpen.Assemblies.Component component in comp.GetChildren ())
{
//Part wp=(Part )component.Prototype;
if (component .GetChildren ().Length == 0)
{
Part wp = (Part)component.Prototype;
component_list.Add(wp);
}
else
{

}
Recursive(component ,count + 1);
}

}

//------------------------------------------------------------------------------
// Following method disposes all the class members
//------------------------------------------------------------------------------
public void Dispose()
{
try
{
if (isDisposeCalled == false)
{
//TODO: Add your application code here
}
isDisposeCalled = true;
}
catch (NXOpen.NXException ex)
{
// ---- Enter your exception handling code here -----

}
}

public static int GetUnloadOption(string arg)
{
//Unloads the image immediately after execution within NX
return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);

}

}