[Solved] getting point on a face.

Need help, or want to share a macro? Post here!
mfasano
Posts: 51
Joined: Wed Apr 11, 2018 12:31 pm

[Solved] getting point on a face.

Postby mfasano » Mon Dec 03, 2018 9:36 pm

I would like to get the point that shows up on the status bar when you click on a face. I tried

I tried

pos = FreeCADGui.ActiveDocument.ActiveView.getPoint(mouseposition)

I hope you can help

Thanks,

Code: Select all

import Part, FreeCAD, PartGui, FreeCADGui
from FreeCAD import Base, Console


#App.newDocument()

 
#This class logs any mouse button events. As the registered callback function fires twice for 'down' and
#'up' events we need a boolean flag to handle this.
class ViewObserver:
   def __init__(self):
       secondtime = 1
   def subselect(self, info):
       DOWN = (info["State"] == "DOWN")
       left = (info["Button"] == "BUTTON1")
       pixpos = info["Position"]
       pos = FreeCADGui.ActiveDocument.ActiveView.getPoint(pixpos)
       
       if (left and DOWN):
           
#             try:
               
               pre = FreeCADGui.Selection.getPreselection()
               param = pre.SubObjects[0].Surface.parameter(pos) 
               FreeCAD.Console.PrintMessage(pre.ObjectName+","+pre.SubElementNames[0]+"\n")
               App.Console.PrintMessage("is and edge " + str(pos)  + "\n") 
#           except: 
#               App.Console.PrintMessage("Oups"+"\n\n") 

actview=Gui.activeDocument().activeView() 


o = ViewObserver()

c = actview.addEventCallback("SoMouseButtonEvent",o.subselect) 

#  actview.removeEventCallback("SoMouseButtonEvent",c) 
Last edited by mfasano on Wed Dec 05, 2018 7:54 pm, edited 2 times in total.
ulrich1a
Posts: 1920
Joined: Sun Jul 07, 2013 12:08 pm

Re: getting point on a face.

Postby ulrich1a » Mon Dec 03, 2018 11:04 pm

In most cases I have a look at the properties of an object in the python console.
This revealed the following and should provide the requested Point.

Code: Select all

pre=Gui.Selection.getPreselection()
pre.PickedPoints
Ulrich
mfasano
Posts: 51
Joined: Wed Apr 11, 2018 12:31 pm

Re: getting point on a face.

Postby mfasano » Tue Dec 04, 2018 1:43 pm

it appears GetPoints gives a tuple of 1 item. It is not a string. I don't know what type it is. for example

points = pre.GetPoints

ponts = (vector (2 ,5, 7),)

how to I extract the point from it . I could convert to a string and parse it.

Thanks,
mfasano
Posts: 51
Joined: Wed Apr 11, 2018 12:31 pm

Re: getting point on a face.

Postby mfasano » Tue Dec 04, 2018 1:50 pm

I figured it out. GetPoints returns a tuple of Vectors. so

point = pre.GetPoints

point[0] will be the vector I want.

Thanks,