FreeCAD-macros
45 строк · 1.9 Кб
1#!/usr/bin/python
2#####################################
3# Copyright (c) openBrain 2019
4# Licensed under LGPL v2
5#
6# This macro will reset position of all part containers to document origin while keeping the absolute object positions
7#
8# Version history :
9# *0.2 : some typo improvement + commenting for official PR
10# *0.1 : alpha release, almost no test performed
11#
12#####################################
13
14__Name__ = 'PlacementAbsolufy'15__Comment__ = 'Reset part containers to global origin while keeping object positions'16__Author__ = 'openBrain'17__Version__ = '0.2'18__Date__ = '2019-06-10'19__License__ = 'LGPL v2'20__Web__ = 'https://www.freecadweb.org/wiki/Macro_PlacementAbsolufy'21__Wiki__ = 'https://www.freecadweb.org/wiki/Macro_PlacementAbsolufy'22__Icon__ = ''23__Help__ = 'Run the macro with model active in the GUI'24__Status__ = 'Alpha'25__Requires__ = 'FreeCAD >= 0.17'26__Communication__ = 'https://forum.freecadweb.org/viewtopic.php?f=3&t=36869'27__Files__ = ''28
29currState = {} #initialize a dictionary to store current object placements30
31for obj in App.ActiveDocument.Objects: #going through active document objects32if "Placement" in obj.PropertiesList: #if object has a Placement property33currState[obj] = obj.getGlobalPlacement() #store the object pointer with its global placement34
35App.ActiveDocument.openTransaction("Absolufy") #open a transaction for undo management36
37for obj, plac in currState.items(): #going through all moveable objects38if obj.isDerivedFrom("App::Part"): #if object is a part container39obj.Placement = App.Placement(App.Vector(0,0,0),App.Rotation(0,0,0)) #reset its placement to global document origin40elif obj.TypeId[:5] == "App::": #if object is another App type (typically an origin axis or plane)41None #do nothing42else: #for all other objects43obj.Placement = plac #replace them at their global (absolute) placement44
45App.ActiveDocument.commitTransaction() #commit transaction46