I am playing around with an AddIn, just trying to learn the funcationality behind selecting entities that have been named. Under the UI Callbacks region of my AddIn, I created a new method called CheckName.
Pre-Conditions to using this method, which is called from my AddIn Menu
1. There is an open part document / model
2. I have named a face
3. I select that named face before I execute the CheckName method
Here is the method. Basically, it starts with a face I have selected. The face I selected, has been named. It is the only face in the model that has been named. I retrieve the name and save to a string. I then clear the selection list. Then, using the name save to the string, I get the named entity, add it back to the selection list (which I cleared). Along the way I throw in a few MSGBox statements to confirm thngs are working.
public void CheckName()
{
IModelDoc2 iModDoc = (IModelDoc2)iSwApp.ActiveDoc;//Get our active document
iSwSelect = (ISelectionMgr)iModDoc.SelectionManager;//Gets the Selection Manager for the active doc
IPartDoc iPart = (IPartDoc)iModDoc;//Get the more specific Part object as well. This is needed to the GetEntityByName method
if (iSwSelect.GetSelectedObjectCount2(-1)==1)//If we have ONE and only one component (face, edge, vertex, etc) selected....
{
object entity = (object)iSwSelect.GetSelectedObject6(1,-1);//Gets reference variable to the selected face/edge, etc. We do not know type, so we cast to object
System.Windows.Forms.MessageBox.Show("Selected Entity Name is " +iModDoc.GetEntityName(entity) + "." );//MSGBox to confirm...
string retName = iModDoc.GetEntityName(entity);//Save the retrieved name to a string
iModDoc.ClearSelection2(true);//Clear the selection list
IEntity iSwEnt = (IEntity)iPart.GetEntityByName(retName, 2);//Get the named entity/face. When we NAMED the entity, we noted the type = 2
SelectData iSelData; //HERE IS MY Question....Why does Select Data work...but ISelect does not?
iSelData= iSwSelect.CreateSelectData();//Create the select data object for our named face.
bool newSelect = iSwEnt.Select4(true, iSelData);//Now, finally, select the named face. We are right back where we started, with the named face selected.
if (newSelect)
{
entity = (object)iSwSelect.GetSelectedObject6(1, -1);//Gets reference variable to the selected object
System.Windows.Forms.MessageBox.Show("Selected Entity Name is " + iModDoc.GetEntityName(entity) + ".");//Check objects name
}
else System.Windows.Forms.MessageBox.Show("Entity was not successfully selected by ID");
}
else System.Windows.Forms.MessageBox.Show("Please select only one face." );
}
Here is my question. This code work perfect with
SelectData iSelData;
Originally, I wrote it with the ISelect interface as follows:
ISelectData iSelData;
The former works...ISelectData does not! Why is this. Documentation on the help only shows the Interface objects, the the class objects...I can not figure out whey SelectData works...but ISelectData will not.
Thanks!
SolidworksApi macros