using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
//using System.Data;
//using System.Drawing;
using System.Linq;
//using System.Runtime.InteropServices;
using System.Text;
//using System.Windows.Forms;
using CS_DotNet;
using NXOpen;
using features = NXOpen.Features;
using NXOpen.Annotations;
namespace CS_NX
{
///
/// CNX_FindAndMove
///
[Description("CNX_FindAndMove")]
public class CNX_FindAndMove
{
/* region Definitionen+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#region Definitionen
private static String _Class;
private static C_LogFile logFile;
private static Session theSession;
private static Part workPart;
private static Part display;
private static features.MoveObject moveObject;
private static features.MoveObjectBuilder moveObjectBuilder;
#endregion
/* endregion ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/* region Konstruktor +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
# region Konstruktor
///
/// Konstruktor der Klasse.
///
public CNX_FindAndMove()
{
_Class = System.Windows.Forms.Application.ProductName + " - " + "CNX_FindAndMove";
logFile = new C_LogFile();
theSession = Session.GetSession();
workPart = theSession.Parts.Work;
display = theSession.Parts.Display;
moveObject = null;
moveObjectBuilder = workPart.BaseFeatures.CreateMoveObjectBuilder(moveObject);
moveObjectBuilder.TransformMotion.Option = NXOpen.GeometricUtilities.ModlMotion.Options.PointToPoint;
moveObjectBuilder.TransformMotion.SetUpdateOption(NXOpen.SmartObject.UpdateOption.AfterModeling);
}
#endregion
/* endregion ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
///
/// Fügt dem MoveObjectBuilder ein NXObject[] an.
///
/// NXObjectArray
///
///
///
///
[Description("AddToMoveObjectBuilder")]
public void AddToMoveObjectBuilder(NXObject[] NXObjectArray)
{
String _Sub = "AddToMoveObjectBuilder";
try
{
if (Init.DebugModus) { logFile.WriteLine("***** Start ----- {0} ----- {1} ", _Class, _Sub); }
bool added1;
added1 = moveObjectBuilder.ObjectToMoveObject.Add(NXObjectArray);
if (!added1)
{
logFile.WriteLine(" +++++ F e h l e r in {0} ----- NXObjectArray konnte dem MoveObjectBuilder nicht hinzugefügt werden.", _Sub);
}
}
catch (Exception ex)
{
logFile.WriteLine(" +++++ F e h l e r in Klasse {0} ----- {1} ", _Class, _Sub);
logFile.WriteLine(ex.ToString());
}
finally
{
if (Init.DebugModus) { logFile.WriteLine("----- Ende ----- {0} ----- {1} ", _Class, _Sub); }
}
}
///
/// Sucht Texte nach ihrem ObjectNamen und fügt sie dem MoveObjectBuilder hinzu.
///
/// Der Text.Name
/// true, wenn etwas gefunden wurde
///
///
/// CNX_FindAndMove cNX_FindAndMove = new CNX_FindAndMove();
/// cNX_FindAndMove.FindNotesByName("TABELLE91");
///
///
[Description("FindNotesByName")]
public Boolean FindNotesByName(String NoteName)
{
String _Sub = "FindNotesByName";
Boolean founded = new Boolean();
founded = false;
NXObject[] object1 = null;
try
{
if (Init.DebugModus) { logFile.WriteLine("***** Start ----- {0} ----- {1} ", _Class, _Sub); }
var allNotes = (display.Notes.ToArray()).Where(aNote => aNote.Name == NoteName);
logFile.WriteLine(" {0} Texte mit dem Namen {1} gefunden.", (allNotes.Count()).ToString(), NoteName);
if (allNotes.Count() == 0)
{
logFile.WriteLine(" Keine Texte mit dem Namen {0} gefunden.", NoteName);
return founded;
}
object1 = new NXObject[allNotes.Count()];
int ii = 0;
foreach (Note aNote in allNotes)
{
object1[ii] = aNote;
ii++;
}
founded = true;
this.AddToMoveObjectBuilder(object1);
}
catch (Exception ex)
{
logFile.WriteLine(" +++++ F e h l e r in Klasse {0} ----- {1} ", _Class, _Sub);
logFile.WriteLine(ex.ToString());
}
finally
{
if (Init.DebugModus) { logFile.WriteLine("----- Ende ----- {0} ----- {1} ", _Class, _Sub); }
}
return founded;
}
///
/// Sucht Texte in einem Bereich und fügt sie dem MoveObjectBuilder hinzu.
///
///
///
/// true, wenn etwas gefunden wurde
///
///
///
///
[Description("FindNotesInArea")]
public Boolean FindNotesInArea(Point3d WindowTopLeft, Point3d WindowBottomRight)
{
String _Sub = "FindNotesInArea";
Boolean founded = new Boolean();
founded = false;
NXObject[] object1 = null;
Note[] allNotes = null;
try
{
if (Init.DebugModus) { logFile.WriteLine("***** Start ----- {0} ----- {1} ", _Class, _Sub); }
allNotes = display.Notes.ToArray();
object1 = new NXObject[allNotes.Length];
int ii = 0;
foreach (Note aNote in allNotes)
{
// erst zählen für Arraygröße
Point3d point3D;
aNote.GetAssociativeOrigin(out point3D);
if ((point3D.X >= WindowTopLeft.X && point3D.X <= WindowBottomRight.X) &&
(point3D.Y >= WindowBottomRight.Y && point3D.Y <= WindowTopLeft.Y))
{
ii++;
}
}
if (ii > 0)
{
// Array definieren
object1 = new NXObject[ii];
ii = 0;
foreach (Note aNote in allNotes)
{
//
Point3d point3D;
aNote.GetAssociativeOrigin(out point3D);
if ((point3D.X >= WindowTopLeft.X && point3D.X <= WindowBottomRight.X) &&
(point3D.Y >= WindowBottomRight.Y && point3D.Y <= WindowTopLeft.Y))
{
object1[ii] = aNote;
ii++;
}
}
logFile.WriteLine(" {0} Texte gefunden.", ii.ToString());
founded = true;
this.AddToMoveObjectBuilder(object1);
}
else
{
logFile.WriteLine(" Keine Texte gefunden.");
}
}
catch (Exception ex)
{
logFile.WriteLine(" +++++ F e h l e r in Klasse {0} ----- {1} ", _Class, _Sub);
logFile.WriteLine(ex.ToString());
}
finally
{
if (Init.DebugModus) { logFile.WriteLine("----- Ende ----- {0} ----- {1} ", _Class, _Sub); }
}
return founded;
}
///
/// Sucht Linien nach ihrem ObjectNamen und fügt sie dem MoveObjectBuilder hinzu.
///
/// Der Linien.Name
/// true, wenn etwas gefunden wurde
///
///
/// CNX_FindAndMove cNX_FindAndMove = new CNX_FindAndMove();
/// cNX_FindAndMove.FindLinesByName("TABELLE91");
///
///
[Description("FindLinesByName")]
public Boolean FindLinesByName(String LineName)
{
String _Sub = "FindLinesByName";
Boolean founded = new Boolean();
founded = false;
NXObject[] object1 = null;
try
{
if (Init.DebugModus) { logFile.WriteLine("***** Start ----- {0} ----- {1} ", _Class, _Sub); }
var allLines = (display.Lines.ToArray()).Where(aLine => aLine.Name == LineName);
logFile.WriteLine(" {0} Linien mit dem Namen {1} gefunden.", (allLines.Count()).ToString(), LineName);
object1 = new NXObject[allLines.Count()];
int ii = 0;
foreach (Line aLine in allLines)
{
object1[ii] = aLine;
ii++;
}
founded = true;
this.AddToMoveObjectBuilder(object1);
}
catch (Exception ex)
{
logFile.WriteLine(" +++++ F e h l e r in Klasse {0} ----- {1} ", _Class, _Sub);
logFile.WriteLine(ex.ToString());
}
finally
{
if (Init.DebugModus) { logFile.WriteLine("----- Ende ----- {0} ----- {1} ", _Class, _Sub); }
}
return founded;
}
///
/// Sucht Linien in einem Bereich und fügt sie dem MoveObjectBuilder hinzu.
///
///
///
/// true, wenn etwas gefunden wurde
///
///
///
///
[Description("FindLinesInArea")]
public Boolean FindLinesInArea(Point3d WindowTopLeft, Point3d WindowBottomRight)
{
String _Sub = "FindLinesInArea";
Boolean founded = new Boolean();
founded = false;
NXObject[] object1 = null;
Line[] allLines = null;
try
{
if (Init.DebugModus) { logFile.WriteLine("***** Start ----- {0} ----- {1} ", _Class, _Sub); }
allLines = display.Lines.ToArray();
int ii = 0;
foreach (Line aLine in allLines)
{
Point3d startLine;
Point3d endLine;
startLine = aLine.StartPoint;
endLine = aLine.EndPoint;
// erst zählen für Arraygröße
if ((startLine.X >= WindowTopLeft.X && startLine.X <= WindowBottomRight.X) &&
(startLine.Y >= WindowBottomRight.Y && startLine.Y <= WindowTopLeft.Y) &&
(endLine.X >= WindowTopLeft.X && endLine.X <= WindowBottomRight.X) &&
(endLine.Y >= WindowBottomRight.Y && endLine.Y <= WindowTopLeft.Y))
{
ii++;
}
}
if (ii > 0)
{
// Array definieren
object1 = new NXObject[ii];
ii = 0;
foreach (Line aLine in allLines)
{
Point3d startLine;
Point3d endLine;
startLine = aLine.StartPoint;
endLine = aLine.EndPoint;
// erst zählen für Arraygröße
if ((startLine.X >= WindowTopLeft.X && startLine.X <= WindowBottomRight.X) &&
(startLine.Y >= WindowBottomRight.Y && startLine.Y <= WindowTopLeft.Y) &&
(endLine.X >= WindowTopLeft.X && endLine.X <= WindowBottomRight.X) &&
(endLine.Y >= WindowBottomRight.Y && endLine.Y <= WindowTopLeft.Y))
{
object1[ii] = aLine;
ii++;
}
}
logFile.WriteLine(" {0} Linen gefunden.", ii.ToString());
founded = true;
this.AddToMoveObjectBuilder(object1);
}
else
{
logFile.WriteLine(" Keine Linen gefunden.");
}
}
catch (Exception ex)
{
logFile.WriteLine(" +++++ F e h l e r in Klasse {0} ----- {1} ", _Class, _Sub);
logFile.WriteLine(ex.ToString());
}
finally
{
if (Init.DebugModus) { logFile.WriteLine("----- Ende ----- {0} ----- {1} ", _Class, _Sub); }
}
return founded;
}
///
/// Sucht Anwenderdefinierte Symbole in einem Bereich und fügt sie dem MoveObjectBuilder hinzu.
///
///
///
/// true, wenn etwas gefunden wurde
///
///
///
///
[Description("FindeCustomSymbolInArea")]
public Boolean FindeCustomSymbolInArea(Point3d WindowTopLeft, Point3d WindowBottomRight)
{
String _Sub = "FindeCustomSymbolInArea";
Boolean founded = new Boolean();
founded = false;
NXObject[] object1 = null;
CustomSymbol[] allSymbols = null;
try
{
if (Init.DebugModus) { logFile.WriteLine("***** Start ----- {0} ----- {1} ", _Class, _Sub); }
allSymbols = display.Annotations.CustomSymbols.ToArray();
object1 = new NXObject[allSymbols.Length];
int ii = 0;
foreach (CustomSymbol _symbol in allSymbols)
{
// erst zählen für Arraygröße
Point3d point3D;
_symbol.GetAssociativeOrigin(out point3D);
if ((point3D.X >= WindowTopLeft.X && point3D.X <= WindowBottomRight.X) &&
(point3D.Y >= WindowBottomRight.Y && point3D.Y <= WindowTopLeft.Y))
{
ii++;
}
}
if (ii > 0)
{
// Array definieren
object1 = new NXObject[ii];
ii = 0;
foreach (CustomSymbol _symbol in allSymbols)
{
//
Point3d point3D;
_symbol.GetAssociativeOrigin(out point3D);
if ((point3D.X >= WindowTopLeft.X && point3D.X <= WindowBottomRight.X) &&
(point3D.Y >= WindowBottomRight.Y && point3D.Y <= WindowTopLeft.Y))
{
object1[ii] = _symbol;
ii++;
}
}
logFile.WriteLine(" {0} Symbole gefunden.", ii.ToString());
founded = true;
this.AddToMoveObjectBuilder(object1);
}
else
{
logFile.WriteLine(" Keine Symbole gefunden.");
}
}
catch (Exception ex)
{
logFile.WriteLine(" +++++ F e h l e r in Klasse {0} ----- {1} ", _Class, _Sub);
logFile.WriteLine(ex.ToString());
}
finally
{
if (Init.DebugModus) { logFile.WriteLine("----- Ende ----- {0} ----- {1} ", _Class, _Sub); }
}
return founded;
}
///
/// Verschiebt die Objecte, welche vorher gesucht wurden und schließt den MoveObjectBuilder
///
/// Startpunkt
/// Zielpunkt
///
///
/// CNX_FindAndMove cNX_FindAndMove = new CNX_FindAndMove();
/// cNX_FindAndMove.MoveObjects(Startpunkt, Zielpunkt);
///
///
[Description("MoveObjects")]
public void MoveObjects(Point3d FromPoint, Point3d ToPoint)
{
String _Sub = "MoveObjects";
try
{
if (Init.DebugModus) { logFile.WriteLine("***** Start ----- {0} ----- {1} ", _Class, _Sub); }
// Point3D in Point umsetzen
NXOpen.Point fromPoint = workPart.Points.CreatePoint(FromPoint);
NXOpen.Point toPoint = workPart.Points.CreatePoint(ToPoint);
moveObjectBuilder.TransformMotion.FromPoint = fromPoint;
moveObjectBuilder.TransformMotion.ToPoint = toPoint;
NXObject nXObject1;
nXObject1 = moveObjectBuilder.Commit();
moveObjectBuilder.Destroy();
}
catch (Exception ex)
{
logFile.WriteLine(" +++++ F e h l e r in Klasse {0} ----- {1} ", _Class, _Sub);
logFile.WriteLine(ex.ToString());
}
finally
{
if (Init.DebugModus) { logFile.WriteLine("----- Ende ----- {0} ----- {1} ", _Class, _Sub); }
}
}
}
}