Cancel
Showing results for 
Search instead for 
Did you mean: 

Default selection intent for Select object block

Valued Contributor
Valued Contributor

Hi,

 

I am trying to set default selection intent for the select object block to face. Whenever the tool is launched and select object block is selected the selection intent should be set to Face by default and other selection options should also be available to the user.

I have tried using the SetSelectionFilter method but it only allows you to set the filter and not set a default

 

selectedBlock.GetProperties().SetSelectionFilter("SelectionFilter", Selection.SelectionAction.ClearAndEnableSpecific, selectionMask);

 

selectionIntent.JPG

 

Any idea or suggestion how can we go about solving this problem?

 

Happy Weekend later on!!!

8 REPLIES 8

Re: Default selection intent for Select object block

PLM World Member Legend PLM World Member Legend
PLM World Member Legend

Hi @CADEnthusiast 

 

There is no option to set default filter option using NXOpen APIs.

But you can use the macro to set the filter 'Face' as default, I hope.

Re: Default selection intent for Select object block

Valued Contributor
Valued Contributor

HI @Manikandan_R 

 

That's an interesting idea. I just recorded a macro and reran it. It works fine. But I guess I will have to generate this macro from my c# code and then rerun it when my code is executed.

 

Do you have any reference code where a simple macro is written and then is called from that code itself?

Re: Default selection intent for Select object block

PLM World Member Legend PLM World Member Legend
PLM World Member Legend

Hi @CADEnthusiast,

 

Refer the below sample program to create macro and procedure to call it in appication.

 

    'To execute a macro file in nx session
    Declare Sub MACRO_playback_from_usertool Lib "libugui" Alias "?MACRO_playback_from_usertool@@YAXPEBD@Z" (ByVal lpName As String)

    Public Sub Main(ByVal args As String())

        Dim tmpDir As String = Nothing
        Dim theButton As MenuBar.MenuButton = Nothing

        theUFSession.UF.TranslateVariable("UGII_TMP_DIR", tmpDir)
        theMacroName = tmpDir & "\" & "SetFilter.macro"

        If File.Exists(theMacroName) Then
            File.Delete(theMacroName)
        End If               

        Using theWriter As New StreamWriter(File.Open(theMacroName, FileMode.OpenOrCreate))

' Do necessary modification in the below code
' ------------------------------------------- theWriter.WriteLine("NX 11.0.2.7") theWriter.WriteLine("Macro File: " & theMacroName) theWriter.WriteLine("Macro Version 7.50") theWriter.WriteLine("Macro List Language and Codeset: english 17") theWriter.WriteLine("Created by xxxxx on Thu Jan 11 19:27:41 2018") theWriter.WriteLine("Part Name Display Style: $FILENAME") theWriter.WriteLine("Selection Parameters 1 2 0.229167 1") theWriter.WriteLine("Display Parameters 1.000000 11.135417 8.552083 -1.000000 -0.768007 1.000000 0.768007") theWriter.WriteLine("*****************") theWriter.WriteLine("RESET") ' Add the lines from your recorded macro file below
' ------------------------------------------------- theWriter.Close() End Using Dim theFileExists As Boolean = File.Exists(theMacroName) If theFileExists Then MACRO_playback_from_usertool(theMacroName) End If End Sub

The above code is in VB language. It will not be much work to convert into C#.

 

Modify the macro lines in the above code as per your recorded macro.

Re: Default selection intent for Select object block

Valued Contributor
Valued Contributor

Hi @Manikandan_R 

 

Thanks for sharing the reference code. I have modified it and integrated it within my application. It does the work of setting the selection filter to the desired value but then the tool UI is getting automatically closed. Below is the code snippet. Do you have any idea why is the tool UI getting automatically closed?

 

public class MacroClass
{
[DllImport("libugui.dll", EntryPoint = "?MACRO_playback_from_usertool@@YAXPEBD@Z")]
static extern void MACRO_playback_from_usertool64(string macroName);

public static string Macro()
{
string tmpDir = null;
NXOpen.MenuBar.MenuButton theButton = null/* TODO Change to default(_) if this is not a reference type */;

UFSession.GetUFSession().UF.TranslateVariable("UGII_TMP_DIR", out tmpDir);
string theMacroName = tmpDir + @"\" + "SetFilter"+ Guid.NewGuid() + ".macro";

if (File.Exists(theMacroName))
{
File.GetAccessControl(theMacroName);
File.Delete(theMacroName);
}

using (StreamWriter theWriter = new StreamWriter(File.Open(theMacroName, FileMode.OpenOrCreate)))
{

// Do necessary modification in the below code
// -------------------------------------------
theWriter.WriteLine("NX 11.0.2.7");
theWriter.WriteLine("Macro File: " + theMacroName);
theWriter.WriteLine("Macro Version 7.50");
theWriter.WriteLine("Macro List Language and Codeset: english 17");
theWriter.WriteLine("Created by xxxxx on " + DateTime.Now);
theWriter.WriteLine("Part Name Display Style: $FILENAME");
theWriter.WriteLine("Selection Parameters 1 2 0.229167 1");
theWriter.WriteLine("Display Parameters 1.000000 13.833333 10.114583 -1.000000 -0.731175 1.000000 0.731175");
theWriter.WriteLine("*****************");
theWriter.WriteLine("RESET");

// Add the lines from your recorded macro file below
// -------------------------------------------------
theWriter.WriteLine("TBR COMBO UG_SEL_TYPE_FILTER 4 -7 0");
theWriter.WriteLine("TBR COMBO UG_SEL_TYPE_FILTER 1 26 1");
theWriter.WriteLine("LINE \"Face\"");
theWriter.Close();
}

bool theFileExists = File.Exists(theMacroName);

if (theFileExists)
MACRO_playback_from_usertool64(theMacroName);

 

return theMacroName;
}
}

Re: Default selection intent for Select object block

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

Did you look in the syslog to see if it crashes or anything?

Ken Akerboom Sr CAx Systems Engr, Moog, Inc.
Production: NX10.0.3.5 MP16/TC11.2
I'd rather be e-steamed than e-diseaseled


Re: Default selection intent for Select object block

Valued Contributor
Valued Contributor

Hi @Ken_A 

 

Yes i did had a look at the log report. There's no crash or error message. The tool UI simply closes with out any error message.

Re: Default selection intent for Select object block

Gears Phenom Gears Phenom
Gears Phenom

I've never tried running a Macro from inside a Blockdialog, but I'm guessing executing the Macro is acting like clicking a button on the NX UI, i.e. the Blockdialog simply closes via the auto-cancel action.

If you try and execute your macro interactively with any other NX dialog open (i.e. Menu->Information->Object...), the open dialog closes as soon as the macro starts.

Graham Inchley Snr R&D Engineer (Systems Development), Sandvik Coromant
Dell 7530 Precision, Win10, 32GB. Developing in: Java | C | KF
Production: [NX12.0.2 MP1]

Re: Default selection intent for Select object block

Valued Contributor
Valued Contributor

Hi @Inch ,

 

That's correct. Even with a native NX dialog the behaviour of the rcorded Macro is the same as with the customized tool UI. The native NX dialog closes automatically as soon as the recorded Macro is executed.

 

It's good to understand the functioning and behaviour of macro but still the probelm for which this Macro workaround was intended remains unsolved.