FreeCAD-macros

Форк
0
/
PlacementAbsolufy.FCMacro 
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

29
currState = {} #initialize a dictionary to store current object placements
30

31
for obj in App.ActiveDocument.Objects: #going through active document objects
32
    if "Placement" in obj.PropertiesList: #if object has a Placement property
33
        currState[obj] = obj.getGlobalPlacement() #store the object pointer with its global placement
34

35
App.ActiveDocument.openTransaction("Absolufy") #open a transaction for undo management
36

37
for obj, plac in currState.items(): #going through all moveable objects
38
    if obj.isDerivedFrom("App::Part"): #if object is a part container
39
        obj.Placement = App.Placement(App.Vector(0,0,0),App.Rotation(0,0,0)) #reset its placement to global document origin
40
    elif obj.TypeId[:5] == "App::": #if object is another App type (typically an origin axis or plane)
41
        None #do nothing
42
    else: #for all other objects
43
        obj.Placement = plac #replace them at their global (absolute) placement
44

45
App.ActiveDocument.commitTransaction() #commit transaction
46

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.