Make sure you select the face with the same mark of the IPropertyManagerPageSelectionbox object.
Or select the face regardless of the mark:
swModelDocExt.SelectByID2("selection", "FACE", 0, 0, 0, False,-1, Nothing, 0)
Thank you Amen!
I tried with the second method but sadly it doesnot work. It shows me the same output message as I got before.
To be honest, I dont fully understand your first sentence. In the selection1's defination using IPropertyManagerPageSelectionbox, I have defined that the selection1 has the caption of selection, and only surfaces are allowed to be selected. Then the "selection" is transfered to the Function then to SelectByID2.
Or, do you mean I should use the selection only for some specific cylinder surfaces? Because I have a lot of cylinder surfaces in the part file, I would prefer to use the codes for all cylinder surfaces.
Here is how I do it
In the handler class definition...
Public Class MyPMPHandler
Dim iSwApp As SldWorks
Dim userAddin As SwAddin
Dim ppage As MyPMP
Function Init(ByVal sw As SldWorks, ByVal addin As SwAddin, ByRef pmp As MyPMP) As Integer
iSwApp = sw
userAddin = addin
ppage = pmp
Then in the handler subroutine...
Dim swModel As ModelDoc2 = iSwApp.ActiveDoc
Dim swSelMgr As SelectionMgr = swModel.SelectionManager
Dim swFace As Face2
swFace = swSelMgr.GetSelectedObject6(1, ppage.pm_Selection_Box.Mark)
You just need to make sure that your selection box control on your property manager page is public...
Public pm_Selection_Box As PropertyManagerPageSelectionbox
and your ppage is friend
Friend ppage As PropertyManagerPage2
Thank you Matthew! Your idea is better than mine. I tried with it and it works. I choose Patrik's answer as the best because his idea is more efficient. Please understand. :-)
you need to use Face2::GetSurface and cast IFace2 to ISurface.
After that you should check if surface is cylinder with Surface::IsCylinder
Now you can get paramaters of surface Surface::CylinderParams
Thank you Patrik! I was totally wrong with my coding idea. Yours is easier and efficient.
You are welcome.