openBrain wrote: ↑Mon Sep 27, 2021 8:23 am
ifohancroft wrote: ↑Sat Sep 25, 2021 3:21 am
1. The ActiveSketch object doesn't get deleted when the Sketch does. What way would you recommend to check for the presence of an active sketch before drawing geometry or adding constraints? If you try to add geometry to a deleted sketch, by using ActiveSketch, there are no errors, just nothing happens, but I'd still like to have a proper check in place.
If your point is about determining if a sketch is currently in edition mode, see here :
https://forum.freecadweb.org/viewtopic. ... 57#p418157
No. I am trying to figure out if a sketch still exists so I don't try to execute my code if the sketch got deleted. However, I can't use ActiveSketch to check for that, because apparently it still holds the sketch object, even after the sketch is deleted.
2. My custom cursor is too big. Is it the SVG file I have used or do I have to specify the scale or something? I couldn't actually find where FreeCAD holds its UI icons, so I downloaded the SVG from the wiki, then modified it a bit.
You can give the size when generating the pixmap :
https://doc.qt.io/qt-5/qpixmap.html#QPixmap
Thank you! I'd look into that.
I forgot to add this, just in-case it isn't the scale's problem: It's not just that the cursor is bigger than expected, the cursor's "point" doesn't fall on the cross in the image, but somewhere between the cross and the the other image in the cursor. So basically the custom cursor gets centered around the actual cursor.
3. I am trying to imitate Sketcher's own tools with this macro, so I've made it that once you start it, you can keep clicking in the document and it will keep "drawing", unless you hit the right mouse button. Hitting the right mouse button shows the context menu on screen. Is there a way to prevent the context screen from showing when hitting the right mouse button while the macro is working?
Also, I just discovered that hitting the right mouse button doesn't actually stop the macro. Am I removing the event callback the wrong way?
I think the problem here is that the right click event is consumed by FreeCAD and not passed to your macro. You can test it with the dialog example I posted above. This a problem and you have to choose a combination that you will receive to remove the callback
That's the problem, that my macro received the right click event, as on right click I try to stop the macro and reset the cursor image. The resetting cursor image works. However, stopping the macro (self.view.removeEventCallback("SoMouseButtonEvent", self.viewObserver)) doesn't and I don't get an error.
3.1. Sketcher's native tools also stop working when you select another geometry tool or constraint - Can I catch the selection of another tool, so I can stop my macro when that happens?
I don't think you can really do this. The solution would be that your macro adds a custom command to the Sketcher toolbar, rather than just executing the script.
In such a case I might strip down the macro to just getting the coordinates and drawing around them. I will be turning most of my macros in a workbench soon anyway.
Do you happen to know if input and tools are handled differently when writing a workbench (in Python)? Like would I have access to more events there? Such as when another tool gets selected or have access to the mouse coordinates and click events without needing to add a ViewObserver as a callback to the view? etc.. So I can make the tools appear more native?
4. I doubt that's possible, but if I add an icon for my macro to Sketcher's toolbar (by going to Tools > Customize > Macros, selecting a pixmap, etc, then going to the Sketcher's toolbar, adding a new one, adding the icon to it, etc), is it possible to make the icon be grayed out and unclickable when I am not editing a Sketch? (I.e. the way the icons for Sketch's own tools work)?
Same as above. Would solve the problem
Sorry, what would solve the problem? I mean when you said same as the above, I thought you meant that it's not possible?
P.S. Any tips for improving my macro further?
Looks quite correct ATM.
Thank you!