studiotreccani
Mechanical
- Nov 28, 2012
- 80
thread561-388210
Hi I try to use this journal but
sometimes it work fine , sometimes not (work only on a few part)
// NX 10.0.1.4
// Journal created by paul.turner V1 - 27/05/15
//
using System;
using System.IO;
using NXOpen;
using NXOpen.UF;
using NXOpen.Utilities;
using NXOpen.Assemblies;
public class NXJournal
{
// Cached NXOpen session
private static NXOpen.Session theSession;
private static NXOpen.UF.UFSession theUFSession;
private static NXOpen.Part workPart;
private static NXOpen.Part displayPart;
//----------------------------------------------------------------------
// Start with displayPart and process all parts in the assembly
public static void ProcessAssy()
{
//theSession.ListingWindow.Open();
try {
ComponentAssembly c = displayPart.ComponentAssembly;
ProcessPart(displayPart);
if (c.RootComponent != null) {
ProcessChildren(c.RootComponent, 0);
}
} catch (Exception e) {
//theSession.ListingWindow.WriteLine("Failed: " & e.ToString);
}
//theSession.ListingWindow.Close();
// reset the display part
NXOpen.PartLoadStatus partLoadStatus1;
NXOpen.PartCollection.SdpsStatus status1;
status1 = theSession.Parts.SetDisplay(displayPart, false, true, out partLoadStatus1);
partLoadStatus1.Dispose();
}
//----------------------------------------------------------------------
// This does not do the component loading
public static void ProcessChildren(Component comp, int indent )
{
foreach (Component child in comp.GetChildren()) {
// insert code to process component or subassembly
if (true /*LoadComponent(child)*/) {
//theSession.ListingWindow.WriteLine("old component name: " + child.Name);
//theSession.ListingWindow.WriteLine("file name: " + child.Prototype.OwningPart.Leaf);
// Get the Part() object
Part aPart = (Part) child.Prototype;
ProcessPart(aPart);
// child.SetName(child.Prototype.OwningPart.Leaf.ToUpper);
//lw.WriteLine("new component name: " & child.Name);
//lw.WriteLine("");
} else {
//component could not be loaded
}
// end of code to process component or subassembly
ProcessChildren(child, indent + 1);
}
}
//----------------------------------------------------------------------
// We know that they are Assemblies.Component objects, from our filter
private static void ProcessPart(Part aPart)
{
// HandleSelectionColor can only be called on DisplayedPart
// so change
NXOpen.PartLoadStatus partLoadStatus1;
NXOpen.PartCollection.SdpsStatus status1;
status1 = theSession.Parts.SetDisplay(aPart, true, true, out partLoadStatus1);
partLoadStatus1.Dispose();
// change the selection colours
aPart.Preferences.ColorSettingVisualization.SelectionColor = 119;
aPart.Preferences.ColorSettingVisualization.PreselectionColor = 149;
string rootDir = Environment.GetEnvironmentVariable("UGII_ROOT_DIR");
string colorPalette = rootDir + "\\ugcolor.cdf";
string colorName = "";
string red = "";
string green = "";
string blue = "";
double[] rgbColor = new double[3];
int thisColor = 0;
string textLine = "";
int lineCounter = 0;
Stream myStream = null;
//VB FileSystem.FileOpen(1, colorPalette, OpenMode.Input, -1, -1, -1);
System.IO.StreamReader file = new System.IO.StreamReader(@colorPalette);
//VB while (!(FileSystem.EOF(1)))
while ((textLine = file.ReadLine()) != null)
{
//VB textLine = FileSystem.LineInput(1);
if (lineCounter > 3)
{
colorName = textLine.Substring(0, 30);
red = textLine.Substring(34, 8);
green = textLine.Substring(45, 8);
blue = textLine.Substring(56, 8);
rgbColor[0] = Convert.ToDouble(red);
rgbColor[1] = Convert.ToDouble(green);
rgbColor[2] = Convert.ToDouble(blue);
thisColor = lineCounter - 4;
theUFSession.Disp.SetColor(thisColor, UFConstants.UF_DISP_rgb_model, colorName, rgbColor);
}
lineCounter++;
}
//VB FileSystem.FileClose(1);
file.Close();
theUFSession.Disp.LoadColorTable();
}
//----------------------------------------------------------------------
public static void Main(string[] args)
{
theSession = Session.GetSession();
theUFSession = UFSession.GetUFSession();
workPart = theSession.Parts.Work;
displayPart = theSession.Parts.Display;
// Undo
NXOpen.Session.UndoMarkId markId1;
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");
theSession.SetUndoMarkName(markId1, "Update Colours");
// Process the assembly
ProcessAssy();
}
public static int GetUnloadOption(string dummy) { return (int)NXOpen.Session.LibraryUnloadOption.Immediately; }
}
Any suggestion please?
NX 7.5 64bit
NX 9.0.3.4 MP4 64bit
NX 10.0.3.5 MP3 64bit
Hi I try to use this journal but
sometimes it work fine , sometimes not (work only on a few part)
// NX 10.0.1.4
// Journal created by paul.turner V1 - 27/05/15
//
using System;
using System.IO;
using NXOpen;
using NXOpen.UF;
using NXOpen.Utilities;
using NXOpen.Assemblies;
public class NXJournal
{
// Cached NXOpen session
private static NXOpen.Session theSession;
private static NXOpen.UF.UFSession theUFSession;
private static NXOpen.Part workPart;
private static NXOpen.Part displayPart;
//----------------------------------------------------------------------
// Start with displayPart and process all parts in the assembly
public static void ProcessAssy()
{
//theSession.ListingWindow.Open();
try {
ComponentAssembly c = displayPart.ComponentAssembly;
ProcessPart(displayPart);
if (c.RootComponent != null) {
ProcessChildren(c.RootComponent, 0);
}
} catch (Exception e) {
//theSession.ListingWindow.WriteLine("Failed: " & e.ToString);
}
//theSession.ListingWindow.Close();
// reset the display part
NXOpen.PartLoadStatus partLoadStatus1;
NXOpen.PartCollection.SdpsStatus status1;
status1 = theSession.Parts.SetDisplay(displayPart, false, true, out partLoadStatus1);
partLoadStatus1.Dispose();
}
//----------------------------------------------------------------------
// This does not do the component loading
public static void ProcessChildren(Component comp, int indent )
{
foreach (Component child in comp.GetChildren()) {
// insert code to process component or subassembly
if (true /*LoadComponent(child)*/) {
//theSession.ListingWindow.WriteLine("old component name: " + child.Name);
//theSession.ListingWindow.WriteLine("file name: " + child.Prototype.OwningPart.Leaf);
// Get the Part() object
Part aPart = (Part) child.Prototype;
ProcessPart(aPart);
// child.SetName(child.Prototype.OwningPart.Leaf.ToUpper);
//lw.WriteLine("new component name: " & child.Name);
//lw.WriteLine("");
} else {
//component could not be loaded
}
// end of code to process component or subassembly
ProcessChildren(child, indent + 1);
}
}
//----------------------------------------------------------------------
// We know that they are Assemblies.Component objects, from our filter
private static void ProcessPart(Part aPart)
{
// HandleSelectionColor can only be called on DisplayedPart
// so change
NXOpen.PartLoadStatus partLoadStatus1;
NXOpen.PartCollection.SdpsStatus status1;
status1 = theSession.Parts.SetDisplay(aPart, true, true, out partLoadStatus1);
partLoadStatus1.Dispose();
// change the selection colours
aPart.Preferences.ColorSettingVisualization.SelectionColor = 119;
aPart.Preferences.ColorSettingVisualization.PreselectionColor = 149;
string rootDir = Environment.GetEnvironmentVariable("UGII_ROOT_DIR");
string colorPalette = rootDir + "\\ugcolor.cdf";
string colorName = "";
string red = "";
string green = "";
string blue = "";
double[] rgbColor = new double[3];
int thisColor = 0;
string textLine = "";
int lineCounter = 0;
Stream myStream = null;
//VB FileSystem.FileOpen(1, colorPalette, OpenMode.Input, -1, -1, -1);
System.IO.StreamReader file = new System.IO.StreamReader(@colorPalette);
//VB while (!(FileSystem.EOF(1)))
while ((textLine = file.ReadLine()) != null)
{
//VB textLine = FileSystem.LineInput(1);
if (lineCounter > 3)
{
colorName = textLine.Substring(0, 30);
red = textLine.Substring(34, 8);
green = textLine.Substring(45, 8);
blue = textLine.Substring(56, 8);
rgbColor[0] = Convert.ToDouble(red);
rgbColor[1] = Convert.ToDouble(green);
rgbColor[2] = Convert.ToDouble(blue);
thisColor = lineCounter - 4;
theUFSession.Disp.SetColor(thisColor, UFConstants.UF_DISP_rgb_model, colorName, rgbColor);
}
lineCounter++;
}
//VB FileSystem.FileClose(1);
file.Close();
theUFSession.Disp.LoadColorTable();
}
//----------------------------------------------------------------------
public static void Main(string[] args)
{
theSession = Session.GetSession();
theUFSession = UFSession.GetUFSession();
workPart = theSession.Parts.Work;
displayPart = theSession.Parts.Display;
// Undo
NXOpen.Session.UndoMarkId markId1;
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");
theSession.SetUndoMarkName(markId1, "Update Colours");
// Process the assembly
ProcessAssy();
}
public static int GetUnloadOption(string dummy) { return (int)NXOpen.Session.LibraryUnloadOption.Immediately; }
}
Any suggestion please?
NX 7.5 64bit
NX 9.0.3.4 MP4 64bit
NX 10.0.3.5 MP3 64bit