1 # ***** BEGIN GPL LICENSE BLOCK *****
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software Foundation,
16 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # ***** END GPL LICENCE BLOCK *****
20 # -----------------------------------------------------------------------
21 # Author: Alan Odom (Clockmender), Rune Morling (ermo) Copyright (c) 2019
22 # -----------------------------------------------------------------------
25 from bpy
.types
import Operator
26 from mathutils
import Vector
27 from pathlib
import Path
28 from .pdt_functions
import debug
, oops
29 from .pdt_msg_strings
import PDT_ERR_NO_LIBRARY
, PDT_ERR_OBJECTMODE
32 class PDT_OT_LibShow(Operator
):
33 """Show Library File Details."""
35 bl_idname
= "pdt.lib_show"
36 bl_label
= "Show Library Details"
37 bl_options
= {"REGISTER", "UNDO"}
39 def execute(self
, context
):
40 """Shows Location Of PDT Library File.
43 context: Blender bpy.context instance.
51 file_path
= pg
.pdt_library_path
52 pg
.error
= str(Path(file_path
))
53 debug("PDT Parts Library:")
55 bpy
.context
.window_manager
.popup_menu(
56 oops
, title
="Information - Parts Library File", icon
="INFO"
61 class PDT_OT_Append(Operator
):
62 """Append from Library at cursor Location."""
64 bl_idname
= "pdt.append"
66 bl_options
= {"REGISTER", "UNDO"}
68 def execute(self
, context
):
69 """Appends Objects from PDT Library file.
72 Appended Objects are placed at Cursor Location.
73 Uses pg.lib_objects, pg.lib_collections & pg.lib_materials
76 context: Blender bpy.context instance.
84 obj
= context
.view_layer
.objects
.active
86 if obj
.mode
!= "OBJECT":
87 error_message
= PDT_ERR_OBJECTMODE
88 self
.report({"ERROR"}, error_message
)
91 obj_names
= [o
.name
for o
in context
.view_layer
.objects
].copy()
92 file_path
= pg
.pdt_library_path
93 path
= Path(file_path
)
95 if path
.is_file() and str(path
).endswith(".blend"):
96 if pg
.lib_mode
== "OBJECTS":
99 directory
=str(path
) + "/Object",
100 filename
=pg
.lib_objects
,
102 for obj
in context
.view_layer
.objects
:
103 if obj
.name
not in obj_names
:
104 obj
.select_set(False)
105 obj
.location
= Vector(
107 scene
.cursor
.location
.x
,
108 scene
.cursor
.location
.y
,
109 scene
.cursor
.location
.z
,
113 if pg
.lib_mode
== "COLLECTIONS":
116 directory
=str(path
) + "/Collection",
117 filename
=pg
.lib_collections
,
119 for obj
in context
.view_layer
.objects
:
120 if obj
.name
not in obj_names
:
121 obj
.select_set(False)
122 obj
.location
= Vector(
124 scene
.cursor
.location
.x
,
125 scene
.cursor
.location
.y
,
126 scene
.cursor
.location
.z
,
130 if pg
.lib_mode
== "MATERIALS":
133 directory
=str(path
) + "/Material",
134 filename
=pg
.lib_materials
,
138 error_message
= PDT_ERR_NO_LIBRARY
139 self
.report({"ERROR"}, error_message
)
143 class PDT_OT_Link(Operator
):
144 """Link from Library at Object's Origin."""
146 bl_idname
= "pdt.link"
148 bl_options
= {"REGISTER", "UNDO"}
150 def execute(self
, context
):
151 """Links Objects from PDT Library file.
154 Linked Objects are placed at Cursor Location
155 Uses pg.lib_objects, pg.lib_collections & pg.lib_materials
158 context: Blender bpy.context instance.
164 scene
= context
.scene
166 obj
= context
.view_layer
.objects
.active
168 if obj
.mode
!= "OBJECT":
169 error_message
= PDT_ERR_OBJECTMODE
170 self
.report({"ERROR"}, error_message
)
173 file_path
= pg
.pdt_library_path
174 path
= Path(file_path
)
176 if path
.is_file() and str(path
).endswith(".blend"):
177 if pg
.lib_mode
== "OBJECTS":
180 directory
=str(path
) + "/Object",
181 filename
=pg
.lib_objects
,
183 for obj
in context
.view_layer
.objects
:
184 obj
.select_set(False)
186 if pg
.lib_mode
== "COLLECTIONS":
189 directory
=str(path
) + "/Collection",
190 filename
=pg
.lib_collections
,
192 for obj
in context
.view_layer
.objects
:
193 obj
.select_set(False)
195 if pg
.lib_mode
== "MATERIALS":
198 directory
=str(path
) + "/Material",
199 filename
=pg
.lib_materials
,
203 error_message
= PDT_ERR_NO_LIBRARY
204 self
.report({"ERROR"}, error_message
)