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!

sometimes it works sometimes not

Status
Not open for further replies.

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

 
Replies continue below

Recommended for you

Do you have write access to all the parts?

Ronald van den Broek
Senior Application Engineer
Winterthur Gas & Diesel Ltd
NX9 / TC10.1.2

Building new PLM environment from Scratch using NX12 / TC11
 
Yes
The assembly and the parts, is saved on my computer
without any restriction.
And the files have a single directory for each project
(load from folder /OPTION) (fully load /OPTION)....
I actualy work with NX 12.0.2.9 MP4


NX 7.5 64bit
NX 9.0.3.4 MP4 64bit
NX 10.0.3.5 MP3 64bit

 
Something may have changed in the structures between 10.0.1 and 12.0.2.


"Wildfires are dangerous, hard to control, and economically catastrophic."

Ben Loosli
 
The components which aren't changed, when you open them separately, do they get changed?

Ronald van den Broek
Senior Application Engineer
Winterthur Gas & Diesel Ltd
NX9 / TC10.1.2

Building new PLM environment from Scratch using NX12 / TC11
 
I found out the origin of the problem:
when there's a part suppressed
the journal does not processed all the files.
But I don't know how the avoid this issue...
Any help please.

I actualy work with NX 12.0.2.9 MP4
NX 10.0.3.5 MP3

 
I don't remember all the specifics, but I believe that when a component is explicitly suppressed, it won't be loaded the next time the assembly is opened. Also, if the component is set to non-geometric or reference only, it will be ignored by default (there is an environment variable to change this behavior).

I wrote some code a while back that attempts to open all the components of an assembly. However, I don't remember what happens to explicitly suppressed components...

www.nxjournaling.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor