Cancel
Showing results for 
Search instead for 
Did you mean: 

original part get modified .

Solution Partner Pioneer Solution Partner Pioneer
Solution Partner Pioneer

I have a assembly file having 3 component.I have modified a component and want to save this assembly file at desired location without modified original assembly file.

Firstly i modified component i.e assembly2.prt,Then using saveAs API ,each component saved at desired location .It get saved properly,but what i observed that  assembly2.prt which I edited also get updated of original assembly file.

Can you please tell reason behind this.

Here is code I have used.

public static Main()
{

List<NXOpen.Assemblies.Component> allComp = new List<NXOpen.Assemblies.Component>();
PMIPlusNXUtilityFunctions.FindAllComponentsOfAssemblyTree(workPart.ComponentAssembly.RootComponent, ref allComp);
List<string> strList = new List<string>();
for (int i = 0; i < allComp.Count; i++)
{
component1 = allComp[i];
string str = component1.DisplayName;
if (strList.Contains(str))
continue;
strList.Add(str);
if (str.Equals("assembly2"))
{
NXJournal.Edit(component1);
continue;
}
}
System.Collections.Generic.List<NXOpen.Assemblies.Component> allCompNX = new System.Collections.Generic.List<NXOpen.Assemblies.Component>();
strList = new System.Collections.Generic.List<string>();
for (int i = 0; i < allComp.Count; i++)
{
component1 = allComp[i];
string str = component1.DisplayName;
if (strList.Contains(str))
continue;
strList.Add(str);
{
allCompNX.Add(component1);
continue;
}
}

strList = new System.Collections.Generic.List<string>();
for (int i = 0; i < allCompNX.Count; i++)
{
component1 = allCompNX[i];
string str = component1.DisplayName;
if (strList.Contains(str))
continue;
strList.Add(str);
SaveComponent(component1);
}

CloseFile();
}



public static void SaveComponent(NXOpen.Assemblies.Component component1)
{
NXOpen.Session theSession = NXOpen.Session.GetSession();
NXOpen.Part workPart = theSession.Parts.Work;
NXOpen.Part displayPart = theSession.Parts.Display;

NXOpen.PartLoadStatus partLoadStatus1;
theSession.Parts.SetWorkComponent(component1, NXOpen.PartCollection.RefsetOption.Entire,
NXOpen.PartCollection.WorkComponentOption.Visible, out partLoadStatus1);

workPart = theSession.Parts.Work;

try
{
NXOpen.Features.Feature[] features1;
features1 = workPart.Features.GetFeatures();

NXOpen.PartSaveStatus partSaveStatus1;
partSaveStatus1 = workPart.SaveAs("D:\\tempFiles\\" + component1.DisplayName + ".prt");

partSaveStatus1.Dispose();
NXOpen.Session.UndoMarkId markId6;
markId6 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Make Work Part");

NXOpen.Assemblies.Component nullNXOpen_Assemblies_Component = null;
NXOpen.Part part3;
part3 = theSession.Parts.Work;

NXOpen.Part part4;
part4 = theSession.Parts.Work;

NXOpen.BasePart.Units units2;
units2 = displayPart.PartUnits;

NXOpen.PartLoadStatus partLoadStatus2;
theSession.Parts.SetWorkComponent(nullNXOpen_Assemblies_Component, NXOpen.PartCollection.RefsetOption.Entire, NXOpen.PartCollection.WorkComponentOption.Visible, out partLoadStatus2);

workPart = theSession.Parts.Work;
partLoadStatus2.Dispose();
theSession.SetUndoMarkName(markId6, "Make Work Part");
}
catch(Exception ex)
{

}
}

public static void CloseFile()
{
Session theSession = Session.GetSession();
NXOpen.Session.UndoMarkId markId6;
markId6 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Make Work Part");

NXOpen.Assemblies.Component nullNXOpen_Assemblies_Component = null;
NXOpen.PartLoadStatus partLoadStatus2;
theSession.Parts.SetWorkComponent(nullNXOpen_Assemblies_Component, NXOpen.PartCollection.RefsetOption.Entire, NXOpen.PartCollection.WorkComponentOption.Visible, out partLoadStatus2);

NXOpen.Part workPart = theSession.Parts.Work;
partLoadStatus2.Dispose();
theSession.SetUndoMarkName(markId6, "Make Work Part");

NXOpen.Part part5;
part5 = theSession.Parts.Work;

workPart.Close(NXOpen.BasePart.CloseWholeTree.True, NXOpen.BasePart.CloseModified.UseResponses, null);

workPart = null;

Session.GetSession().ApplicationSwitchImmediate("UG_APP_NOPART");
}