Compare commits

...

5 commits
pgp ... main

Author SHA1 Message Date
pgp 6088214107 oups 2025-10-29 15:17:38 +01:00
pgp 3e581d38c2 maj 2025-10-29 15:14:32 +01:00
pgp 044ec9424a Merge branch 'main' of ssh://git.cohabit.fr:22222/thomalex.moreau/MultiExport-FreeCAD 2025-10-29 13:54:40 +01:00
pgp 63e4c08990 Merge branch 'main' of ssh://git.cohabit.fr:22222/thomalex.moreau/MultiExport-FreeCAD 2025-07-10 14:28:21 +02:00
pgp febbb0efdb maj 2025-05-15 16:15:40 +02:00
3 changed files with 91 additions and 0 deletions

View file

@ -0,0 +1,87 @@
# -*- coding: utf-8 -*-
# Set the current view perpendicular to the selected line
# Place la vue perpendiculairement a la line selectionnee
# 2013 Jonathan Wiedemann,
# 2016 Werner Mayer,
# 2022 tchernomax, https://forum.freecadweb.org/viewtopic.php?p=630019#p630019
# 2023 FreeCutter, modifications towards linked objects like in workbench Assembly 4 , https://forum.freecad.org/viewtopic.php?p=718516#p718516
#
__title__ = "Align_View_to_Face"
__author__ = "Jonathan Wiedemann (Rockn)"
__url__ = "https://www.freecadweb.org/"
__Wiki__ = "https://wiki.freecadweb.org/Macro_Align_View_to_Face"
__version__ = "3.1"
__date__ = "2023/11/12" #YYYY/MM/DD
from pivy import coin
import FreeCAD as app
import FreeCADGui as gui
def pointAt(normal, up):
z = normal
y = up
x = y.cross(z)
y = z.cross(x)
rot = App.Matrix()
rot.A11 = x.x
rot.A21 = x.y
rot.A31 = x.z
rot.A12 = y.x
rot.A22 = y.y
rot.A32 = y.z
rot.A13 = z.x
rot.A23 = z.y
rot.A33 = z.z
return App.Placement(rot).Rotation
def get_selection_and_turn_view():
doc = app.activeDocument()
if doc is None:
app.Console.PrintWarning('Align_view_to_face: No file open, nothing to do\n')
return
selection = gui.Selection.getSelectionEx('', 0) # Returns a vector of selection objects
if not selection:
app.Console.PrintWarning('Align_view_to_face: Nothing selected, nothing to do\n')
return
cam = FreeCADGui.ActiveDocument.ActiveView.getCameraNode()
''' used to understand the 'getSelection' results
for selection_object in selection:
object_ = selection_object.Object
sub_fullpaths = selection_object.SubElementNames
if not sub_fullpaths:
# An object is selected, not a face, edge, vertex.
print(object_.Name)
for sub_fullpath in sub_fullpaths:
# One or more subelements are selected.
print(object_.Name, sub_fullpath)
'''
sel = selection[0]
face = sel.SubObjects[0]
if face.Area == 0: # trying to avoid errors due to wrong selected objects
app.Console.PrintWarning('Align_view_to_face: Please select a face - not an edge or vertex\n')
return
dir = face.normalAt(0,0)
if dir.z == 1 :
rot = pointAt(dir, App.Vector(0.0,1.0,0.0))
elif dir.z == -1 :
rot = pointAt(dir, App.Vector(0.0,1.0,0.0))
else :
rot = pointAt(dir, App.Vector(0.0,0.0,1.0))
cam.orientation.setValue(rot.Q)
gui.SendMsgToActiveView("ViewSelection")
app.Console.PrintWarning('Align_view_to_face: Done\n')
if __name__ == '__main__':
get_selection_and_turn_view()

View file

@ -0,0 +1,4 @@
[
"/home/pgp/.var/app/org.freecad.FreeCAD/data/FreeCAD/Macro/MultiExport-FreeCAD/Macro_Align_View_to_Face.png",
"/home/pgp/.var/app/org.freecad.FreeCAD/data/FreeCAD/Macro/MultiExport-FreeCAD/Align_View_to_Face.FCMacro"
]

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB