I'm new to this method and don't know how it works,can any one explain me why can't I get a value that is not null from
swView = (SolidWorks.Interop.sldworks.View)swSeleMgr.GetSelectedObject6(1, -1); ? I do did the select.
I am not aware of C# but will just give you some pointers which may help: -
Hope it helps!!!
I would need to see your code to know exactly what you are doing wrong, but if you are simply trying to get the selected drawing view, then here is what you would need:
I don't know how new you are to API programming, but let me step you through this. After declaring the object variables, we need to set the object variables. Generally you will set the variables in the order that they appear in the SolidWorks API model hierarchy, beginning with the top level and moving toward the lower level. In other words, you must first access the higher level objects before you can access the lower level objects. So the highest object in the SolidWorks API is ISldWorks, which we declared as swApp. This is the application itself. Once we set the application object variable, we can set the model using the currently active document, then that document's selection manager. ISelectionMgr is the object for getting currently selected object. Once we have set the selection manager, we can use the GetSelectedObject6 method to get the selected view. The first argument in this method is the index, in the event that you have selected multiple items. If you are only selected one item them you can just use "1" for this argument. The next argument is for marking, which is a way to keep track of particular items when you have selected many items. If you don't plan on using marking, just make this "-1", which ignores marking.
Hope that helps.
Thanks for replying.
I copied the code from API help http://help.solidworks.com/2010/english/api/sldworksapi/set_body_for_view_example_csharp.htm
into my eventhandler function OnNewSelection(), but I always get null returned. If the API is right then I must have done something wrong when debugging or just something wrong with my PC.
I'll try again and thank you very much for the explain, I'll contact you later after I try again.
Thanks for your advice.
I checkek my program, and find it is not the GetSelectedObject6(1,-1); returns null, but just after I do GetSelectedObject6(1,-1);
the program goes to Repaint,and then start a loop of EnableTA(); which I used in
cmdIndex0 = cmdGroup.AddCommandItem("****", -1, "****", "****", 0, "ThicknessAna", "EnableTA", 0);
and never end.
If you know why this happen, please help me.
EnableTA（）is like this:
It is normal that a repaint is called after getSelectedObject6(). It is also normal that EnableTA() is being called. The only issue is how are you using the complete functionality.
If you are using it in PropertyManagerPage then I believe that a call to getSelectedObject6() might not be required.
I shall be able to give you an insight on the problem in hand once I get a chance to see your code. Is it possible for you to share the code?
Does it matter that I use this in a multibody parts model?
I do not think that multibody part scenario should change the approach. The functionality should (and does) work normal with multibody part unless you are doing something specific.
Thank you very much.
I have got some advice from others, I'll try that after my class and if it failed I'll mail you my program.
Thank you very much for the help, I have solved this problem.
I have used this method in a wrong way until I find another API to remind me.
It seems that swView = (SolidWorks.Interop.sldworks.View) was not needed, that makes the program start a endless loop.
Maybe that's a differce between C# and VB. I'm new to both C# and Solidworks and never used VB, that was terrible.
But thanks for your help, I have finally done this.
Thank you very much, and Keith too.
I am glad that your issue is finally fixed. I wsh you all the luck with your developments further..
Retrieving data ...