[Solved] getting point on a face.

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
mfasano
Posts: 122
Joined: Wed Apr 11, 2018 12:31 pm

[Solved] getting point on a face.

Post by mfasano »

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
Veteran
Posts: 1957
Joined: Sun Jul 07, 2013 12:08 pm

Re: getting point on a face.

Post by ulrich1a »

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
User avatar
mfasano
Posts: 122
Joined: Wed Apr 11, 2018 12:31 pm

Re: getting point on a face.

Post by mfasano »

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,
User avatar
mfasano
Posts: 122
Joined: Wed Apr 11, 2018 12:31 pm

Re: getting point on a face.

Post by mfasano »

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

point = pre.GetPoints

point[0] will be the vector I want.

Thanks,
Post Reply