| | | Gut zu wissen: Hilfreiche Tipps und Tricks aus der Praxis prägnant, und auf den Punkt gebracht für NX |
Autor
|
Thema: Block Styler - Flächeninformation (4136 mal gelesen)
|
jazzix Mitglied Student
Beiträge: 4 Registriert: 27.09.2011 NX 7.5.2.5 MS Visual Studio 2010 Professional C#
|
erstellt am: 27. Sep. 2011 11:09 <-- editieren / zitieren --> Unities abgeben:
Hallo CAD.de, ich bin zwar regelmäßiger CAD.de-Leser aber dies ist mein erster Eintrag. Ich bin Student im Praxissemester und habe die Aufgabe mich in NX, C# und die Verbindung der beiden durch den "Block Styler" einzuarbeiten. Zur Verfügung steht mir das Buch "Visual C# 2010" von Andreas Kühnel, welches ich bereits bis zum Kapitel "LINQ" gelesen habe, was nicht heißt, dass ich das alles beherrsche. Auch den "NX Open Programmer´s Guide" habe ich durchgelesen, dieser jedoch hat mir nicht wirklich geholfen. Ich soll ein einfaches Block Styler Programm schreiben, das die Auswahl einer Fläche ermöglicht und nach einem Klick auf einen Button verschiedene Informationen zu dieser Fläche in einem seperaten Fenster ausgibt. Die Wunsch-Informationen wären Fläche[m²], Normalenvektor, Eckpunkte und alles was sonst noch interessant ist. Natürlich wäre ich schon damit zufrieden wenn ich die Fläche[m²] ausgeben könnte. Der Block Styler erzeugt mir sehr viel Code den ich nicht wirklich verstehe, jedoch habe ich es soweit gebracht, dass mir der Knopf eine Message-Box öffnet in der steht: "Face 31600". Am besten zeige ich euch mal "meinen" Code: Code: //============================================================================== //------------------------------------------------------------------------------ //These imports are needed for the following template code //------------------------------------------------------------------------------ using System; using NXOpen; using NXOpen.BlockStyler;//------------------------------------------------------------------------------ //Represents Block Styler application class //------------------------------------------------------------------------------ public class Flaecheninfo { //class members private static Session theSession = null; private static UI theUI = null; public static Flaecheninfo theFlaecheninfo; private string theDialogName; private NXOpen.BlockStyler.BlockDialog theDialog; private NXOpen.BlockStyler.UIBlock group0;// Block type: Group private NXOpen.BlockStyler.UIBlock face_select0;// Block type: Face Collector private NXOpen.BlockStyler.UIBlock group01;// Block type: Group private NXOpen.BlockStyler.UIBlock button0;// Block type: Button public static string info = null; //------------------------------------------------------------------------------ //Bit Option for Property: EntityType //------------------------------------------------------------------------------ public static readonly int EntityType_AllowFaces = (1 << 4); public static readonly int EntityType_AllowDatums = (1 << 5); public static readonly int EntityType_AllowBodies = (1 << 6); //------------------------------------------------------------------------------ //Bit Option for Property: FaceRules //------------------------------------------------------------------------------ public static readonly int FaceRules_SingleFace = (1 << 0); public static readonly int FaceRules_RegionFaces = (1 << 1); public static readonly int FaceRules_TangentFaces = (1 << 2); public static readonly int FaceRules_TangentRegionFaces = (1 << 3); public static readonly int FaceRules_BodyFaces = (1 << 4); public static readonly int FaceRules_FeatureFaces = (1 << 5); public static readonly int FaceRules_AdjacentFaces = (1 << 6); public static readonly int FaceRules_ConnectedBlendFaces = (1 << 7); public static readonly int FaceRules_AllBlendFaces = (1 << 8); public static readonly int FaceRules_RibFaces = (1 << 9); public static readonly int FaceRules_SlotFaces = (1 <<10); public static readonly int FaceRules_BossandPocketFaces = (1 <<11); public static readonly int FaceRules_MergedRibFaces = (1 <<12); public static readonly int FaceRules_RegionBoundaryFaces = (1 <<13); public static readonly int FaceRules_FaceandAdjacentFaces = (1 <<14); //------------------------------------------------------------------------------ //Constructor for NX Styler class //------------------------------------------------------------------------------ public Flaecheninfo() { try { theSession = Session.GetSession(); theUI = UI.GetUI(); theDialogName = "Flaechen-info.dlx"; theDialog = theUI.CreateDialog(theDialogName); theDialog.AddApplyHandler(new NXOpen.BlockStyler.BlockDialog.Apply(apply_cb)); theDialog.AddOkHandler(new NXOpen.BlockStyler.BlockDialog.Ok(ok_cb)); theDialog.AddUpdateHandler(new NXOpen.BlockStyler.BlockDialog.Update(update_cb)); theDialog.AddInitializeHandler(new NXOpen.BlockStyler.BlockDialog.Initialize(initialize_cb)); theDialog.AddFocusNotifyHandler(new NXOpen.BlockStyler.BlockDialog.FocusNotify(focusNotify_cb)); theDialog.AddKeyboardFocusNotifyHandler(new NXOpen.BlockStyler.BlockDialog.KeyboardFocusNotify(keyboardFocusNotify_cb)); theDialog.AddDialogShownHandler(new NXOpen.BlockStyler.BlockDialog.DialogShown(dialogShown_cb)); } catch (Exception ex) { //---- Enter your exception handling code here ----- throw ex; } } public static void Main() { try { theFlaecheninfo = new Flaecheninfo(); // The following method shows the dialog immediately theFlaecheninfo.Show(); } catch (Exception ex) { //---- Enter your exception handling code here ----- theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString()); } finally { if(theFlaecheninfo != null) theFlaecheninfo.Dispose(); } } public static int GetUnloadOption(string arg) { //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly); return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately); // return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination); } //------------------------------------------------------------------------------ // Following method cleanup any housekeeping chores that may be needed. // This method is automatically called by NX. //------------------------------------------------------------------------------ public static int UnloadLibrary(string arg) { try { //---- Enter your code here ----- } catch (Exception ex) { //---- Enter your exception handling code here ----- theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString()); } return 0; } //------------------------------------------------------------------------------ //This method shows the dialog on the screen //------------------------------------------------------------------------------ public NXOpen.UIStyler.DialogResponse Show() { try { theDialog.Show(); } catch (Exception ex) { //---- Enter your exception handling code here ----- theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString()); } return 0; } //------------------------------------------------------------------------------ //Method Name: Dispose //------------------------------------------------------------------------------ public void Dispose() { if(theDialog != null) { theDialog.Dispose(); theDialog = null; } } //------------------------------------------------------------------------------ //---------------------Block UI Styler Callback Functions-------------------------- //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ //Callback Name: initialize_cb //------------------------------------------------------------------------------ public void initialize_cb() { try { group0 = (NXOpen.BlockStyler.UIBlock)theDialog.TopBlock.FindBlock("group0"); face_select0 = (NXOpen.BlockStyler.UIBlock)theDialog.TopBlock.FindBlock("face_select0"); group01 = (NXOpen.BlockStyler.UIBlock)theDialog.TopBlock.FindBlock("group01"); button0 = (NXOpen.BlockStyler.UIBlock)theDialog.TopBlock.FindBlock("button0"); } catch (Exception ex) { //---- Enter your exception handling code here ----- theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString()); } } //------------------------------------------------------------------------------ //Callback Name: dialogShown_cb //This callback is executed just before the dialog launch. Thus any value set //here will take precedence and dialog will be launched showing that value. //------------------------------------------------------------------------------ public void dialogShown_cb() { try { //---- Enter your callback code here ----- } catch (Exception ex) { //---- Enter your exception handling code here ----- theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString()); } } //------------------------------------------------------------------------------ //Callback Name: apply_cb //------------------------------------------------------------------------------ public int apply_cb() { try { //---- Enter your callback code here ----- } catch (Exception ex) { //---- Enter your exception handling code here ----- theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString()); } return 0; } //------------------------------------------------------------------------------ //Callback Name: update_cb //------------------------------------------------------------------------------ public int update_cb( NXOpen.BlockStyler.UIBlock block) { try { if(block == face_select0) { //---------Enter your code here-----------
//? NXObject nxobj = theUI.SelectionManager.GetSelectedObject(0);
theUI.NXMessageBox.Show("", NXMessageBox.DialogType.Information, "Fläche wurde ausgewählt!"); } else if(block == button0) { //---------Enter your code here----------- //?MeasureFaces.ActiveValue info = Convert.ToString(theUI.SelectionManager.GetSelectedObject(0)); theUI.NXMessageBox.Show("Informationen zur Fläche", NXMessageBox.DialogType.Information, info); } } catch (Exception ex) { //---- Enter your exception handling code here ----- theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString()); } return 0; } //------------------------------------------------------------------------------ //Callback Name: ok_cb //------------------------------------------------------------------------------ public int ok_cb() { int errorCode = 0; try { //---- Enter your callback code here ----- errorCode = apply_cb(); } catch (Exception ex) { //---- Enter your exception handling code here ----- errorCode = 1; theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString()); } //return errorCode; return 0; } //------------------------------------------------------------------------------ //Callback Name: focusNotify_cb //This callback is executed when any block (except the ones which receive keyboard entry such as Integer block) receives focus. //------------------------------------------------------------------------------ public void focusNotify_cb(NXOpen.BlockStyler.UIBlock block, bool focus) { try { //---- Enter your callback code here ----- } catch (Exception ex) { //---- Enter your exception handling code here ----- theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString()); } } //------------------------------------------------------------------------------ //Callback Name: keyboardFocusNotify_cb //This callback is executed when block which can receive keyboard entry, receives the focus. //------------------------------------------------------------------------------ public void keyboardFocusNotify_cb(NXOpen.BlockStyler.UIBlock block, bool focus) { try { //---- Enter your callback code here ----- } catch (Exception ex) { //---- Enter your exception handling code here ----- theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString()); } } }
Mein großes Problem im Moment ist, dass ich nicht die richtigen Befehle für mein Vorhaben kenne und auch nicht weiß woher ich diese beziehen soll. Ich habe schon vieles aus der NXOpen.NET Reference versucht, aber ich glaube nicht, dass jemand imstande ist diese Riesige Bibliothek auwendig zu kennen. Das heißt es muss ein anderer Weg vorhanden sein um an die richtigen Befehle ran zu kommen nur sehe ich ihn nicht. Vielleicht kann mir jemand helfen? Ich hoffe mal, dass meine Anfrage nicht zu trivial ist, ich will hier niemanden beleidigen.
Schönen Gruß, Severin Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
mseufert Moderator Freiberuflicher CAD/CAM Ingenieur
Beiträge: 2624 Registriert: 18.10.2005 HP Z420 WIN7 64 Win 10 UG NX6-1980 3D Printer Prusa MK2 S
|
erstellt am: 28. Sep. 2011 09:23 <-- editieren / zitieren --> Unities abgeben: Nur für jazzix
Hallo Severin, der einfachste Weg, eine unbekannte Funktion zu finden, ist die Aufzeichnung eines Journals. In Deinem Fall würd' ich's mal mit Analysis->Measure Face oder ->Geometric Properties versuchen. Gruß, Michael Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
jazzix Mitglied Student
Beiträge: 4 Registriert: 27.09.2011 NX 7.5.2.5 MS Visual Studio 2010 Professional C#
|
erstellt am: 28. Sep. 2011 17:45 <-- editieren / zitieren --> Unities abgeben:
|
jazzix Mitglied Student
Beiträge: 4 Registriert: 27.09.2011 NX 7.5.2.5 MS Visual Studio 2010 Professional C#
|
erstellt am: 29. Sep. 2011 17:10 <-- editieren / zitieren --> Unities abgeben:
Hallo Michael, mit den Journals bin ich jetzt schon ziemlich weit gekommen. Mein aktuelles Problem ist folgendes: Ich erstelle einen Quader(1), in den ich 4 Bohrungen bringen will, was am Ende meine Bauplatte darstellen soll. Mit ein paar Journals habe ich es geschafft den Quader zu erstellen, nur die Bohrungen erwarten eine Fläche die nach meiner Angabe die Oberfläche des Quaders sein soll. Im Journal wird das mit "(NXOpen.Features.Block)workPart.Features.FindObject("BLOCK(1)");"geregelt, jedoch will ich das Programm für mehrere Bauplatten universell anfertigen. Dazu muss ich von den sechs Flächen des Quaders die auswählen, deren Normalenvektor nach oben zeigt. Mir fehlt die Funktion dazu und ich kann sie beim besten Willen nicht finden. Auch die NXOpen .Net API Reference hat für Flächen keine Methode die einen Normalenvektor auswirft. Vielleicht bin ich nach einem halben Arbeitstag Suchen blind geworden oder ich gehe die Sache viel zu umständlich an? Ich hoffe mir kann geholfen werden, Schönen Gruß, Severin Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
| CAD-Konstrukteur (m/w/d) | Wir entwickeln und bauen Prüfgeräte und Montageanlagen für elektronische Baugruppen und Produkte. Unsere Wurzeln sind in Radolfzell, unsere Produkte in der ganzen Welt im Einsatz. Wir sind lokal und international, technikbegeistert und leidenschaftlich, sorgfältig und schnell. Unsere Mitarbeiter sind unser wichtigstes Kapital. Denn der Erfolg von ENGMATEC hängt von ihren Leistungen ab, von ihren Ideen, ihrer Leidenschaft und ihrer Energie, die sie einbringen.... | Anzeige ansehen | Konstruktion, Visualisierung |
|
mseufert Moderator Freiberuflicher CAD/CAM Ingenieur
Beiträge: 2624 Registriert: 18.10.2005 HP Z420 WIN7 64 Win 10 UG NX6-1980 3D Printer Prusa MK2 S
|
erstellt am: 30. Sep. 2011 10:13 <-- editieren / zitieren --> Unities abgeben: Nur für jazzix
Zitat: Original erstellt von jazzix: Auch die NXOpen .Net API Reference hat für Flächen keine Methode die einen Normalenvektor auswirft.
Hallo Severin, diese Aussage ist definitiv falsch. Wenn Du keine passende Methode gefunden hast, muss das nicht zwangsläufig heißen, daß es keine gibt. Z.B. geben die oben schon genannten Analysefunktionen u.a. auch die Flächennormale aus .... Die einzelnen Faces kriegst Du über den Body mit getfaces(). Gruß, Michael
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
| Anzeige.:
Anzeige: (Infos zum Werbeplatz >>)
|