1 Reply Latest reply on Apr 4, 2014 3:09 PM by Keith Rice

    Asking about selection by mouse click

    Stanley Sentoso

      Hi All,

       

      I have one sketch that contain several circles (no overlapping circle). Now, I want to create a macro that allow user to click any where and then this macro will check whether the location is inside any circle. If it does, the related circle will be selected.

      However, I could find any function to test whether one point is inside sketch contour. Do you have any Idea how to implement it?

       

       

      TIA,

       

       

      Stanley

        • Re: Asking about selection by mouse click
          Keith Rice

          Stanley,

           

          This would be fairly complex, I think. If I am understanding you correctly, this is how it might have to be done:

           

          1. Collect the information about all circles in sketch that is necessary to determine if a point is inside one of them.
            1. I would recommend you use ISketchManager::GetSketchSegments, then test each sketch segment using ISketchSegment::GetType for arcs. If an arc, then return ISketchArc and get the radius with ISketchArc::GetRadius.
              • If you need to distinguish between partial arcs and closed arcs (full circles) then simply determine if the start and end point of the arc is the same. If yes, its a circle.
            2. Store the information about all circles in a collection (if using VBA) or list (if using .NET)
          2. Start the event listener that listens for a left mouse button down-click using swMouseNotify_e (particularly the swMouseLBtnDownNotify member).
            1. If you can always expect the user to click on a face, then ISelectionMgr::GetSelectionPointInSketchSpace2 could get the selection point I believe. (Otherwise, there's always ISelectionMgr::GetSelectionPoint2).
            2. If the user isn't clicking on a face and is instead clicking into empty space, ISelectionMgr won't do you any good as far as I can tell. You would have to get the XYZ coords returned from swMouseLBtnDownNotify and figure out how to convert from screen space to model space. I'm not even sure this is possible since there may be no way to accurately transform the point between the two spaces.
          3. Once a click occurs and you have the XYZ coords in model space, you can run those points against the data you have in the collection from #1. Here is where you'll need to do some math. This resource gives an equation you could use.

           

          Hope this helps.

           

          Keith

          SolidWorks API Tutorials