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!

SelectElement2 is lost if I click

Status
Not open for further replies.

AlvaroPers

Mechanical
Nov 29, 2020
30
Hello,

If I call the method "SelectElement2", I select the proper element, all ok. But, at this point (with the selected element "loaded") if I click in the 3D workspace or anywhere, the selection is lost.
So, if the end user make a click before using the selected element, the selected element is lost.

This doesn't happen in the CATIA features that use seleccion. For example: in a CATPart if I launch the "Extract" function, I select a face and then I can click all over the empty space and the selection in the dialog form doesn't lost. The selected element is kept.

So, using the "SelectElement2", how not to lost the selection by clicking afterwords?

Thanks
Al.



 
Replies continue below

Recommended for you

Public Function SingleSelection2(oCATIA As CATIA) As INFITF.Selection

Dim oDocumentSelected As INFITF.Document
Dim oAppCATIA As INFITF.Application = oCATIA.AppCATIA
Dim oActiveDocu As INFITF.Document = oAppCATIA.ActiveDocument

' Sew indica el tipo que se quiere seleccionar
Dim strObjectType As String = "Product"

' Cuidado, lo hace contra el "ActiveDocument". Ver comentario: "Comprobar si el objeto "selection" se hizo sobre el documento activo "
Dim oSelection As INFITF.Selection = oAppCATIA.ActiveDocument.Selection 'Si se llama a esta funcion sin documento abierto en CATIA da error
Dim strStatus As String
Dim InputObject(0) As Object
Dim message As String = "Select " & strObjectType & " to proceed"

' Objeto Selection
oSelection.Clear()
InputObject(0) = strObjectType 'El "InputObject" es un array Indicar el "tipo de objeto" que se busca seleccionar.
oSelection.Clear()
strStatus = oSelection.SelectElement2(InputObject, message, True) 'línea que invoca al método de seleccion, el programa espera por la seleccion

' Comprobar si el objeto "selection" se hizo sobre el documento activo (ver seccion: "Interfaces VisPropertySet (Object)").
oDocumentSelected = oSelection.Application.ActiveDocument
If oDocumentSelected IsNot oActiveDocu Then
MsgBox("Ha seleccionando un objeto de una ventana que no era la activa" & vbCrLf _
& "Click aceptar y volver a seleccionar")
' oSelection.Clear()
' el clear se hace sobre el nuevo documento activo. La línea "oSelection.Clear()" no hace nada en este caso.
oDocumentSelected.Selection.Clear()
Return Nothing
Exit Function
End If

' oOutputState:
Select Case strStatus
Case "Normal"
Exit Select
Case "Cancel"
oSelection.Clear()
Return Nothing
Exit Function
Case "Undo"
oSelection.Clear()
Return Nothing
Exit Function
End Select
Return oSelection
End Function
 
SelectElementX functions can't preserve previously selected elements while adding new ones.

You've got two options:
1. Select elements one by one with SelectElement2
2. Select all elements at once with SelectElement3
 
I understand that, my concern is another one, let me explain:

Open a CatPart, and invoke the "extract" command for example (GSD Workbench), select a face or something.
The seleccion at this point is kept in the extract menu (in the form, indicating the name of the entity you selected).
Now, at this point, if you go with your mouse and click anywhere in the 3D workspace or even in another face of the geometry, the selection is kept in the form.

Now, if you use the Selectelement2, ones you performed the selection, if you click with the mouse, the selection is lost.
So the behavior is not the same. I'm looking for replicate the selection as the CATIA in-built commands, so If the user click anywhere the selection is not lost.



 
It is like: "the mouse clicks cleans the slection object"
 
Why don't you save previously selected by yourself and reselect them after each SelectElement2 call?

C#:
INFITF.AnyObject SelectSingleElement(INFITF.Document document, string[] typeFilter, string message)
{
  // preserve selection
  INFITF.Selection selection = document.Selection;
  List<INFITF.Selection> preselected = new();
  for (int i=1; i <= selection.Count; i++)
  {
    preselected.Add(selection.Item(i).Value);
  }
  
  // select new element
  string status = selection.SelectElement2(typeFilter.Cast<object>().ToArray(), message, false);
  INFITF.AnyObject selected = string.Equals("Normal", status) ? selection.Item(1).Value : null;
  
  // restore selection
  foreach (INFITF.AnyObject obj in preselected)
  {
    selection.Add(obj);
  }

  return selected;
}
 
Why don't you use slectelement3 instead, and use ctrl to do multiselection?
{“MultiSelectionMode” can have the following values:
“CATMonoSel” (one selection),
“CATMultiSelTriggWhenSelPerf” (selection through the “Tools Palette” toolbar, “Shift” and “Ctrl” keys are not supported),
or “CATMultiSelTriggWhenUserValidatesSelection” (selection through the “Tools Palette” toolbar, “Shift” and “Ctrl” keys are supported).}
 
Guys,
I appreciate your answers, but again, I'm not looking for multi-selection nor pre-selection.
It is a different question I'm asking.

When one uses the "SelectElement2" CATIA await for you to pick one element, in this case let say a product from the tree.
Ones the selection is done, the selected product is "stored" in your variable, let say "oSel" (which is a module variable).
AT THIS MOMENT, if you see the left bottom corner of the CATIA application it reads: "1 element selected"
AT THIS SAME MOMENT, if you use some textbox to display the selection, like: MsgBox(oSel.Count), it will display "1".
THEN: click "Ok" to close the MsgBox, go to CATIA application and make a mouse click over any place in the 3D working space area.
Look again at the left bottom corner of the CATIA application: the selection disappeared!, and if you were to display the textbox again it will show "0" now.

My question is: how to preserve the selected element, even if the user clicks over the CATIA while the macro is running?

I attached the code.
 
 https://files.engineering.com/getfile.aspx?folder=71ffd0e4-3e0c-464b-a7c5-28210d4ea61e&file=SelectElement2.jpg
Oh god. What you want is to highlight a feature, but CATIA has no Automation API to do that.

Technically, you can check selection state on timer and modify it but this is a bad idea UI-wise.
 
I don't want to highlight a feature.
The code I attached was for illustration purposes, just to show that the oSel object is empty after some mouse clicking in the 3D workspace.
So, there is no way to "retain" or "preserve" the selected object if the user make an accidental click while the oSel is "loaded", so at the time to "press OK" to apply the feature, the object is empty.
The clicking action acts like a "ESC" keyword, erasing the selection object.

This doesn't happen in the built-in CATIA features. For example, you can try "extract" feature of the GSD workbench. Call the feature, select something, then make some random clicks in the 3d space, and you will see that the selected object is still there selected awaiting for you to press "ok" and create the extraction and finalize the operation. I'm just looking to replicate that behavior.

Thank you again for your answers.

 
Highlighting and selection are two different mechanisms in CATIA. By default they are in sync , but can be decoupled by setting CATIA.HSOSynchronized=False

The problem is CATIA.Selection allows to manage selected objects only. Highlighting API is available with CAA, not Automation.
 
Ok, I understood.
Please, don't close the thread, I will try to find a workaround.

Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor