Hi
I want a macro / dialog be interrupted to allow the user to specify a point by pointing with the mouse.
I know "Observing mouse events in the 3D viewer via Python" but I want the snaps of existing objects to be caught.
(In AutoCAD/Lisp it would be getpoint)
Thanks for help
Chri1
Interrupt macro for userinput point
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
- Joel_graff
- Veteran
- Posts: 1949
- Joined: Fri Apr 28, 2017 4:23 pm
- Contact:
Re: Interrupt macro for userinput point
I've never worked with snapping in Python, so I know nothing about it, I'm afraid.
However, snapping is managed in DraftSnap.py:
https://github.com/FreeCAD/FreeCAD/blob ... aftSnap.py
You might want to look at the source code there to get a feel for how it works. You can play with those functions from the FreeCAD console by importing DraftSnap in the console, then calling functions.
However, snapping is managed in DraftSnap.py:
https://github.com/FreeCAD/FreeCAD/blob ... aftSnap.py
You might want to look at the source code there to get a feel for how it works. You can play with those functions from the FreeCAD console by importing DraftSnap in the console, then calling functions.
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails
pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
Re: Interrupt macro for userinput point
A selection observer should be good for that.
Copy/paste this in the python console and pick some objects in the 3D view to test.
Uncomment last line to remove observer.
Copy/paste this in the python console and pick some objects in the 3D view to test.
Uncomment last line to remove observer.
Code: Select all
class my_selection_observer:
"""Selection observer"""
def __init__(self):
self.selection = []
def addSelection(self,doc,obj,sub,pnt):
self.selection.append(Gui.Selection.getSelectionObject(doc,obj,sub,pnt))
print("%s.%s.%s picked at point %s"%(doc, obj, sub, pnt))
def removeSelection(self,doc,obj,sub):
self.selection.remove(Gui.Selection.getSelectionObject(doc,obj,sub))
def clearSelection(self,doc):
self.Selection = []
obs = my_selection_observer()
FreeCADGui.Selection.addObserver(obs)
#FreeCADGui.Selection.removeObserver(obs)
Re: Interrupt macro for userinput point
Thanks
A first attempt worked out:
I typed in Phyton-Console:
and with every
I get the the snapped point of an existing object
(Depending on the current snap-settings)
There seem to be a lot more options to discover
Chri1
A first attempt worked out:
I typed in Phyton-Console:
Code: Select all
import DraftSnap
def cb(point):
if point:
print (point)
Code: Select all
FreeCADGui.Snapper.getPoint(callback=cb)
(Depending on the current snap-settings)
There seem to be a lot more options to discover
Chri1