forked from MariwanJ/Design456
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDesign456_SplitObject.py
More file actions
123 lines (112 loc) · 5.69 KB
/
Copy pathDesign456_SplitObject.py
File metadata and controls
123 lines (112 loc) · 5.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
#
# ***************************************************************************
# * *
# * This file is a part of the Open Source Design456 Workbench - FreeCAD. *
# * *
# * Copyright (C) 2025 *
# * *
# * *
# * This library is free software; you can redistribute it and/or *
# * modify it under the terms of the GNU Lesser General Public *
# * License as published by the Free Software Foundation; either *
# * version 2 of the License, or (at your option) any later version. *
# * *
# * This library is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
# * Lesser General Public License for more details. *
# * *
# * You should have received a copy of the GNU Lesser General Public *
# * License along with this library; if not, If not, see *
# * <http://www.gnu.org/licenses/>. *
# * *
# * Author : Mariwan Jalal mariwan.jalal@gmail.com *
# ***************************************************************************
import os
import FreeCAD as App
import FreeCADGui as Gui
import Design456Init
from PySide import QtGui, QtCore # https://www.freecadweb.org/wiki/PySide
import Draft
import Part
import BOPTools.SplitFeatures as SPLIT
from FreeCAD import Base
from time import time as _time, sleep as _sleep
import FACE_D as faced
from draftutils.translate import translate #for translate
__updated__ = '2022-04-18 14:50:36'
class Design456_SplitObject:
"""Divide object in to two parts"""
def Activated(self):
try:
# Save object name that will be divided.
selection = Gui.Selection.getSelectionEx()
if (len(selection) < 1):
# An object must be selected
errMessage = "Select an object to use Split Tool"
faced.errorDialog(errMessage)
return
App.ActiveDocument.openTransaction(translate("Design456","Split Object"))
shape = selection[0].Object.Shape
bb = shape.BoundBox
length = max(bb.XLength, bb.YLength, bb.ZLength)
nameOfselectedObject = selection[0].ObjectName
totalName = nameOfselectedObject+'_cs'
""" slow function . . you need to use wait before getting
the answer as the execution is continuing down """
Gui.runCommand('Part_CrossSections', 0)
gcompund = App.ActiveDocument.addObject(
"Part::Compound", "Compound")
App.ActiveDocument.recompute()
# get object name
# We need this delay to let user choose the split form. And
getExtrude_cs = None # Dummy variable used to wait for the Extrude_cs be made
while (getExtrude_cs is None):
getExtrude_cs = App.ActiveDocument.getObject(totalName)
_sleep(.1)
Gui.updateGui()
# Begin command Part_Compound
gcompund.Links = [getExtrude_cs, ]
# Begin command Part_BooleanFragments
j = SPLIT.makeBooleanFragments(name='BooleanFragments')
j.Objects = [gcompund, App.ActiveDocument.getObject(
nameOfselectedObject)]
j.Mode = 'Standard'
j.Proxy.execute(j)
j.purgeTouched()
App.ActiveDocument.recompute()
if j.isValid() is False:
App.ActiveDocument.removeObject(j.Name)
# Shape != OK
errMessage = "Failed to fillet the objects"
faced.errorDialog(errMessage)
else:
# Make a simple copy
newShape = Part.getShape(j, '', needSubElement=False, refine=False)
NewJ = App.ActiveDocument.addObject(
'Part::Feature', 'SplitObject')
NewJ.Shape = newShape
#Preserve color and other properties of the old obj
faced.PreserveColorTexture(selection[0].Object,NewJ)
# Remove Old objects
for obj in j.Objects:
App.ActiveDocument.removeObject(obj.Name)
App.ActiveDocument.removeObject(totalName)
App.ActiveDocument.removeObject(j.Name)
App.ActiveDocument.commitTransaction() #undo reg.
App.ActiveDocument.recompute()
except Exception as err:
App.Console.PrintError("'SplitObject' Failed. "
"{err}\n".format(err=str(err)))
exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
print(exc_type, fname, exc_tb.tb_lineno)
def GetResources(self):
return{
'Pixmap': Design456Init.ICON_PATH + 'SplitObject.svg',
'MenuText': 'Split Object',
'ToolTip': 'Divide object in to two parts'
}
Gui.addCommand('Design456_SplitObject', Design456_SplitObject())