Macro CenterFace/cs


Text-x-python.png Macro CenterFace

Description
This macro red trace (editable) the center face (mass) with 1 point and print the coordinates.
Author
Mario52
Links
Makro návody
How to install macros
How to customize toolbars
Version
0.1
Date last modification
2014-04-29


Description

This macro red trace (editable) the center face (mass) with 1 point and print the coordinates.


CenterFace


Use

Select one face and launch the macro. 1 point to face are coloured red (can be changed).

To change the color of the dot change the lines 36, 37, 38

red   = 1.0  # 1 = 255
    green = 0.0  #
    blue  = 0.0  # 

The center of the face (mass) surface and the XYZ coordinates of the face are displayed in the report view.

Icone

Download the file image and copy in your macro repertory.

Click the image, in the new window position the mouse over the image, click the right mouse and do "Save target as ..."

Button

Script

Macro_CenterFace.FCMacro

# -*- coding: utf-8 -*-
# 29/04/2014
# select a face launch and list the center coordinate XYZ of face
# To change the color of the dot change the lines 36, 37, 38
# red   = 1.0  # 1 = 255
# green = 0.0  #
# blue  = 0.0  #
# Macro_CenterFace
# Mario52

#OS: Windows Vista
#Platform: 32-bit
#Version: 0.14.3389
#Python version: 2.6.2
#Qt version: 4.5.2
#Coin version: 3.1.0
#SoQt version: 1.4.1
#OCC version: 6.5.1

import FreeCAD, FreeCADGui, Draft, Part

try:
    sel = FreeCADGui.Selection.getSelection()             # get the selection
    sh = sel[0].Shape                                     # seletion of the first element

    App.Console.PrintMessage("Label : "+ str(sel[0].Label)+"\n")     # extract the Label
    App.Console.PrintMessage("Name  : "+ str(sel[0].Name) +"\n")     # extract the Name
except:
    App.Console.PrintError( "select a face"+"\n")


try:
    SubElement = FreeCADGui.Selection.getSelectionEx()# "getSelectionEx" Used for selecting subobjects
    element_ = SubElement[0].SubElementNames[0]       # seletion of the first element

#    print element_
#    print sh.Faces

    # LineColor
    red   = 1.0  # 1 = 255
    green = 0.0  #
    blue  = 0.0  #

    for i in range(len(sh.Faces)):                    # list and extract the data
        App.Console.PrintMessage( "Center Face "+str(i)+" "+str(sh.Faces[i].CenterOfMass)+"\n") # Vector center mass to face
#        print "X : ",sh.Faces[i].CenterOfMass.x                                                # Coord. X center mass to face
#        print "Y : ",sh.Faces[i].CenterOfMass.y                                                # Coord. Y center mass to face
#        print "Z : ",sh.Faces[i].CenterOfMass.z                                                # Coord. Z center mass to face
        Draft.makePoint(sh.Faces[i].CenterOfMass.x,sh.Faces[i].CenterOfMass.y,sh.Faces[i].CenterOfMass.z) # create a point
        FreeCADGui.activeDocument().activeObject().PointColor = (red, green, blue)

        App.Console.PrintMessage( "       Surface   : "+str(sel[0].Shape.Faces[i-1].Area)+"\n")
        fco = 0
        for f0 in sel[0].Shape.Faces[i].Vertexes:      # Vertexes faces
            fco += 1
            App.Console.PrintMessage("       Vertexe X"+str(fco)+": "+str(f0.Point.x)+" Y"+str(fco)+": "+str(f0.Point.y)+" Z"+str(fco)+": "+str(f0.Point.z)+"\n")

except:
    App.Console.PrintError( "select a face *"+"\n") 
Online version: "http://www.freecadweb.org/wiki/index.php?title=Macro_CenterFace/cs&oldid=240936"

Navigation menu