Macro CenterFace/fr: Difference between revisions
m (Created page with "==Description== Cette macro crée un point rouge (éditable) au centre (mass) de la face sélectionnée et affiche ses coordonnées dans la vue rapport.") |
No edit summary |
||
(32 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
<languages/> |
|||
{{Macro/fr|Icon=Text-x-python|Name=Macro CenterFace|Name/fr=Macro CenterFace|Description=Cette macro crée un point rouge (éditable) au centre (mass) de la face sélectionnée et affiche ses coordonnées dans la vue rapport.|Author=Mario52}} |
|||
{{Macro/fr |
|||
==Description== |
|||
|Name=Macro CenterFace |
|||
Cette macro crée un point rouge (éditable) au centre (mass) de la face sélectionnée et affiche ses coordonnées dans la vue rapport. |
|||
|Name/fr=Macro CenterFace |
|||
|Icon=CenterFace.png |
|||
|Description=Cette macro crée un point rouge (éditable) au centre de la face (centre de gravité) sélectionnée et affiche ses coordonnées dans la vue rapport. |
|||
|Author=Mario52 |
|||
|Download=[https://wiki.freecad.org/images/1/16/CenterFace.png Icône de la barre d'outils] |
|||
|Version=0.2 |
|||
|Date=2018-10-07 |
|||
}} |
|||
==Description== |
|||
Cette macro crée un point rouge (éditable) au centre de la face (centre de gravité) sélectionnée et affiche ses coordonnées dans la vue rapport. |
|||
[[File:Macro_CenterFace_00.png|480px|CenterFace]] |
[[File:Macro_CenterFace_00.png|480px|CenterFace]] |
||
{{Caption|CenterFace}} |
|||
{{clear}} |
|||
<span id="Usage"></span> |
|||
==Use== |
|||
==Utilisation== |
|||
Select one face and launch the macro. 1 point to face are colored red (can be changed). |
|||
Sélectionnez une face et lancez la macro. Un point sur la face est coloré en rouge (peut être modifié). |
|||
To change the color of the dot change the lines 36, 37, 38 |
|||
<syntaxhighlight> |
|||
Pour changer la couleur du point, modifiez les lignes 36, 37, 38 |
|||
red = 1.0 # 1 = 255 |
|||
green = 0.0 # |
|||
red = 1.0 # 1 = 255 |
|||
</syntaxhighlight> |
|||
green = 0.0 # |
|||
The center of the face (mass) surface and the XYZ coordinates of the face are displayed in the report view. |
|||
blue = 0.0 # |
|||
Le centre de la face et les coordonnées XYZ de ce centre seront affichés dans la vue rapport ainsi que la surface de la face et ses coordonnées. |
|||
<span id="Icon"></span> |
|||
==Icône== |
|||
Téléchargez l'icône pour votre barre d'outils et copiez la dans votre répertoire de macros. |
|||
Cliquez sur l'image, dans la nouvelle fenêtre faites clic droit de la souris et cliquez "Enregistrez l'image sous..." |
|||
[[File:CenterFace.png|Bouton]] |
|||
<span id="Script"></span> |
|||
==Macro== |
|||
==Macro== |
|||
'''Macro_CenterFace.FCMacro''' |
'''Macro_CenterFace.FCMacro''' |
||
{{MacroCode|code= |
|||
<syntaxhighlight> |
|||
# -*- coding: utf-8 -*- |
# -*- 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 |
#OS: Windows Vista #OS: Windows 10 |
||
#Platform: 32-bit |
#Platform: 32-bit #Word size of OS: 64-bit |
||
#Version: 0.14.3389 |
#Version: 0.14.3389 #Word size of FreeCAD: 64-bit |
||
#Python version: 2.6.2 |
#Python version: 2.6.2 #Version: 0.17.13528 (Git) |
||
#Qt version: 4.5.2 |
#Qt version: 4.5.2 #Build type: Release |
||
#Coin version: 3.1.0 |
#Coin version: 3.1.0 #Branch: releases/FreeCAD-0-17 |
||
#SoQt version: 1.4.1 |
#SoQt version: 1.4.1 #Hash: 5c3f7bf8ec51e2c7187789f7edba71a7aa82a88b |
||
#OCC version: 6.5.1 |
#OCC version: 6.5.1 #Python version: 2.7.14 |
||
#Qt version: 4.8.7 |
|||
#Coin version: 4.0.0a |
|||
#OCC version: 7.2.0 |
|||
# 29/04/2014, 07/10/2018 |
|||
__title__ = "Macro_CenterFace" |
|||
__author__ = "Mario52" |
|||
__url__ = "http://www.freecadweb.org/index-fr.html" |
|||
__Wiki__ = "https://www.freecadweb.org/wiki/Macro_CenterFace" |
|||
__version__ = "00.02" |
|||
__date__ = "07/10/2018" |
|||
__Comment__ = "select a face launch and list the center coordinate XYZ of face" |
|||
import FreeCAD, FreeCADGui, Draft, Part |
import FreeCAD, FreeCADGui, Draft, Part |
||
def objectRealPlacement3D(obj): # search the real Placement |
|||
try: |
|||
try: |
|||
sel = FreeCADGui.Selection.getSelection() # get the selection |
|||
objectPlacement = obj.Shape.Placement |
|||
sh = sel[0].Shape # seletion of the first element |
|||
objectPlacementBase = FreeCAD.Vector(objectPlacement.Base) |
|||
#### |
|||
App.Console.PrintMessage("Label : "+ str(sel[0].Label)+"\n") # extract the Label |
|||
objectWorkCenter = objectPlacementBase |
|||
#### |
|||
if hasattr(obj, "getGlobalPlacement"): |
|||
globalPlacement = obj.getGlobalPlacement() |
|||
globalPlacementBase = FreeCAD.Vector(globalPlacement.Base) |
|||
#### |
|||
objectRealPlacement3D = globalPlacementBase.sub(objectWorkCenter)#mode=0 adapte pour BBox + Centerpoints |
|||
#### |
|||
else: |
|||
objectRealPlacement3D = objectWorkCenter |
|||
return objectRealPlacement3D |
|||
except Exception: |
|||
return FreeCAD.Vector(0.0, 0.0, 0.0) |
|||
try: |
|||
sel = FreeCADGui.Selection.getSelection() # get the selection |
|||
sh = sel[0] # seletion of the first element |
|||
App.Console.PrintMessage( "__Begin__________"+"\n") |
|||
import unicodedata |
|||
nameLabel = unicodedata.normalize('NFKD', sh.Label).encode('ascii','ignore') |
|||
App.Console.PrintMessage("Label : "+ str(nameLabel)+"\n") # extract the Label |
|||
App.Console.PrintMessage("Name : "+ str(sel[0].Name) +"\n") # extract the Name |
App.Console.PrintMessage("Name : "+ str(sel[0].Name) +"\n") # extract the Name |
||
except: |
except: |
||
App.Console.PrintError( " |
App.Console.PrintError( "Select a face"+"\n") |
||
try: |
try: |
||
SubElement = FreeCADGui.Selection.getSelectionEx()# "getSelectionEx" Used for selecting subobjects |
SubElement = FreeCADGui.Selection.getSelectionEx()# "getSelectionEx" Used for selecting subobjects |
||
element_ = SubElement[0].SubElementNames[0] # seletion of the first element |
element_ = SubElement[0].SubElementNames[0] # seletion of the first element |
||
#print element_ |
|||
#print sh.Faces |
|||
# LineColor |
# LineColor |
||
red = 1.0 # 1 = 255 |
red = 1.0 # 1 = 255 |
||
Line 66: | Line 120: | ||
blue = 0.0 # |
blue = 0.0 # |
||
for i in range(len(sh.Faces)): # list and extract the data |
for i in range(len(sh.Shape.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) |
|||
oripl_X = sh.Shape.Faces[i].CenterOfMass.x |
|||
oripl_Y = sh.Shape.Faces[i].CenterOfMass.y |
|||
oripl_Z = sh.Shape.Faces[i].CenterOfMass.z |
|||
placementOrigine = objectRealPlacement3D( sh ) |
|||
oripl_X += placementOrigine[0] |
|||
oripl_Y += placementOrigine[1] |
|||
oripl_Z += placementOrigine[2] |
|||
App.Console.PrintMessage( "Center Face "+str(i)+" : "+str(sh.Shape.Faces[i].CenterOfMass)+"\n") # Vector center mass to face |
|||
App.Console.PrintMessage( "GlobalPlacement : "+str(placementOrigine)+"\n") # Vector center mass to face |
|||
Draft.makePoint(oripl_X, oripl_Y, oripl_Z) # create a point |
|||
FreeCADGui.activeDocument().activeObject().PointColor = (red, green, blue) |
|||
App.Console.PrintMessage( " Surface : "+str(sel[0].Shape.Faces[i-1].Area)+"\n") |
App.Console.PrintMessage( " Surface : "+str(sel[0].Shape.Faces[i-1].Area)+"\n") |
||
fco = 0 |
fco = 0 |
||
Line 81: | Line 142: | ||
except: |
except: |
||
App.Console.PrintError( " |
App.Console.PrintError( "Select a face *"+"\n") |
||
App.Console.PrintMessage( "__End____________"+"\n") |
|||
}} |
|||
==Version== |
|||
ver 0.2 07/10/2018 : mise à jour pour FC 017 "getGlobalPlacement" |
|||
ver 0.1 29/04/2014 |
|||
</syntaxhighlight> |
|||
{{clear}} |
{{clear}} |
||
<languages/> |
Latest revision as of 10:48, 29 December 2023
Description |
---|
Cette macro crée un point rouge (éditable) au centre de la face (centre de gravité) sélectionnée et affiche ses coordonnées dans la vue rapport. Version macro : 0.2 Date dernière modification : 2018-10-07 Téléchargement : Icône de la barre d'outils Auteur: Mario52 |
Auteur |
Mario52 |
Téléchargement |
Icône de la barre d'outils |
Liens |
Page des macros Comment installer une macro Comment créer une barre d'outils |
Version Macro |
0.2 |
Dernière modification |
2018-10-07 |
Version(s) FreeCAD |
None |
Raccourci clavier |
None |
Voir aussi |
None |
Description
Cette macro crée un point rouge (éditable) au centre de la face (centre de gravité) sélectionnée et affiche ses coordonnées dans la vue rapport.
CenterFace
Utilisation
Sélectionnez une face et lancez la macro. Un point sur la face est coloré en rouge (peut être modifié).
Pour changer la couleur du point, modifiez les lignes 36, 37, 38
red = 1.0 # 1 = 255
green = 0.0 #
blue = 0.0 #
Le centre de la face et les coordonnées XYZ de ce centre seront affichés dans la vue rapport ainsi que la surface de la face et ses coordonnées.
Icône
Téléchargez l'icône pour votre barre d'outils et copiez la dans votre répertoire de macros.
Cliquez sur l'image, dans la nouvelle fenêtre faites clic droit de la souris et cliquez "Enregistrez l'image sous..."
Macro
Macro_CenterFace.FCMacro
# -*- coding: utf-8 -*- #OS: Windows Vista #OS: Windows 10 #Platform: 32-bit #Word size of OS: 64-bit #Version: 0.14.3389 #Word size of FreeCAD: 64-bit #Python version: 2.6.2 #Version: 0.17.13528 (Git) #Qt version: 4.5.2 #Build type: Release #Coin version: 3.1.0 #Branch: releases/FreeCAD-0-17 #SoQt version: 1.4.1 #Hash: 5c3f7bf8ec51e2c7187789f7edba71a7aa82a88b #OCC version: 6.5.1 #Python version: 2.7.14 #Qt version: 4.8.7 #Coin version: 4.0.0a #OCC version: 7.2.0 # 29/04/2014, 07/10/2018 __title__ = "Macro_CenterFace" __author__ = "Mario52" __url__ = "http://www.freecadweb.org/index-fr.html" __Wiki__ = "https://www.freecadweb.org/wiki/Macro_CenterFace" __version__ = "00.02" __date__ = "07/10/2018" __Comment__ = "select a face launch and list the center coordinate XYZ of face" import FreeCAD, FreeCADGui, Draft, Part def objectRealPlacement3D(obj): # search the real Placement try: objectPlacement = obj.Shape.Placement objectPlacementBase = FreeCAD.Vector(objectPlacement.Base) #### objectWorkCenter = objectPlacementBase #### if hasattr(obj, "getGlobalPlacement"): globalPlacement = obj.getGlobalPlacement() globalPlacementBase = FreeCAD.Vector(globalPlacement.Base) #### objectRealPlacement3D = globalPlacementBase.sub(objectWorkCenter)#mode=0 adapte pour BBox + Centerpoints #### else: objectRealPlacement3D = objectWorkCenter return objectRealPlacement3D except Exception: return FreeCAD.Vector(0.0, 0.0, 0.0) try: sel = FreeCADGui.Selection.getSelection() # get the selection sh = sel[0] # seletion of the first element App.Console.PrintMessage( "__Begin__________"+"\n") import unicodedata nameLabel = unicodedata.normalize('NFKD', sh.Label).encode('ascii','ignore') App.Console.PrintMessage("Label : "+ str(nameLabel)+"\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.Shape.Faces)): # list and extract the data oripl_X = sh.Shape.Faces[i].CenterOfMass.x oripl_Y = sh.Shape.Faces[i].CenterOfMass.y oripl_Z = sh.Shape.Faces[i].CenterOfMass.z placementOrigine = objectRealPlacement3D( sh ) oripl_X += placementOrigine[0] oripl_Y += placementOrigine[1] oripl_Z += placementOrigine[2] App.Console.PrintMessage( "Center Face "+str(i)+" : "+str(sh.Shape.Faces[i].CenterOfMass)+"\n") # Vector center mass to face App.Console.PrintMessage( "GlobalPlacement : "+str(placementOrigine)+"\n") # Vector center mass to face Draft.makePoint(oripl_X, oripl_Y, oripl_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") App.Console.PrintMessage( "__End____________"+"\n")
Version
ver 0.2 07/10/2018 : mise à jour pour FC 017 "getGlobalPlacement"
ver 0.1 29/04/2014