-
Re: Run macro,ask to select, finish running
Andreas Killer Jan 20, 2016 5:59 AM (in response to Hrituc Alexandru)You can create and open a VB-Userform modeless.
On that form show the user a message that he has to select a point and click on the Ok command button (on the Userform).
When a form is shown modeless the user is able to select something in Solidworks.
In the Click event of the button check if a point is selected. If so exit the form and finish your macro, otherwise throw an error.
Andreas.
-
Re: Run macro,ask to select, finish running
Artem Taturevych Jan 21, 2016 12:32 AM (in response to Hrituc Alexandru)-
Re: Run macro,ask to select, finish running
Andreas Killer Jan 21, 2016 4:41 AM (in response to Artem Taturevych)Hi Artem,
Interesting example, I've change the output on the from a little to get a better number format:
lblMessage.Caption = "Point is selected: X" & Format(vPt(0) * 1000, "0.000") & " Y" & Format(vPt(1) * 1000, "0.000") & " Z" & Format(vPt(2) * 1000, "0.000")
Y is exact 25, but why is the X coordinate is not zero?
(When I create a line and click on the same point, SW catches the exact middle point of the line.)
(Even if I move the cursor more exactly on the middle point, the X coordinate is never zero, but Y is 25 ever.)You can see the similar behavior on the vertical line, where X is exact 50, but Y is never zero.
What is missing in the sample code to get the exact middle point of the line?
Andreas.
-
Re: Run macro,ask to select, finish running
Artem Taturevych Jan 21, 2016 4:49 AM (in response to Andreas Killer)Hi Andreas,
The method used in the sample is getting the pick point (SolidWorks does the rest to find the snapping one). Not sure why Y is always an exact value, but I think this is just occasion. If you want the coordinate of the point you need to get the pointer to ISketchPoint from ISelectionManager::GetSelectedObject6 and then extract X, Y and Z values. You may need to use sketch transforms if you want a coordinates in the model space.
Thanks,
Artem
-
Re: Run macro,ask to select, finish running
Andreas Killer Jan 21, 2016 5:48 AM (in response to Artem Taturevych)Hi Artem,
I don't see how GetSelectedObject6 would be helpful, cause the user can select anything... splines, circles, text, blocks... I understand that I can get the coordinates of such objects, with tons of code...
Let us stay on my simple sample, the line has 3 points: end point on the left, middle point, end point on the right.
How should the code recognize which point I've clicked (the snapping one)?
Andreas.
-
Re: Run macro,ask to select, finish running
Artem Taturevych Jan 21, 2016 6:01 AM (in response to Andreas Killer)Hi Andreas,
Once user clicked on the point (including middle point, end points, key points for the spline) or near the point which resulted into the snapping to the point and regardless of what sketch entity was clicked on (line, spline, arc, etc) the selected object will be point (not the segment) so it is possible to extract this coordinate. In case user clicked on the random position within the sketch segment which hasn't snapped to any point the selected object's type would be the corresponding segment and the GetSelectionPoint method can be used in this case.
As the summary: if selected object is point - get the exact coordinate from the ISketchPoint interface
If selected object is ISketchSegment - get the approximate selection point.
The same logic can be applied for the edges and vertices if they needed to be supported.
Thanks,
Artem-
Re: Run macro,ask to select, finish running
Andreas Killer Jan 21, 2016 7:21 AM (in response to Artem Taturevych)Once user clicked on the point (including middle point, end points, key points for the spline) or near the point which resulted into the snapping to the point and regardless of what sketch entity was clicked on (line, spline, arc, etc) the selected object will be point (not the segment) so it is possible to extract this coordinate.
As the summary: if selected object is point - get the exact coordinate from the ISketchPoint interface
I can not see anything in ISketchPoint Interface to get a selected point nor selected object.
Can you show us a sample?
Andreas.
-
Re: Run macro,ask to select, finish running
Artem Taturevych Jan 21, 2016 4:58 PM (in response to Andreas Killer)-
Re: Run macro,ask to select, finish running
Andreas Killer Jan 22, 2016 2:59 AM (in response to Artem Taturevych)Hi Artem,
works like a charm, thank you.
Andreas.
-
-
-
-
-
-
-