Skip to content

Commit

Permalink
Fix: Issue with Parts Library File
Browse files Browse the repository at this point in the history
An issue occurred if you opened Blender with a new file. The library file pointed relative to
the Blender App, not the working directory so was not found. Parts Library file is now moved
to the Parts Library Menu, so must be set for a new blend file, existing saved blend files are not
affected by this change.

Error message altered to reflect the option of having this Parts Library anywhere.
  • Loading branch information
Clockmender committed May 5, 2020
1 parent ff79326 commit 4cc1de1
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 63 deletions.
146 changes: 91 additions & 55 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
bl_info = {
"name": "Precision Drawing Tools (PDT)",
"author": "Alan Odom (Clockmender), Rune Morling (ermo)",
"version": (1, 3, 0),
"blender": (2, 80, 2),
"version": (1, 2, 2),
"blender": (2, 80, 0),
"location": "View3D > UI > PDT",
"description": "Precision Drawing Tools for Acccurate Modelling",
"warning": "",
Expand All @@ -54,6 +54,7 @@
importlib.reload(pdt_bix)
importlib.reload(pdt_etof)
importlib.reload(pdt_tangent)
importlib.reload(pdt_trig_waves)
else:
from . import pdt_design
from . import pdt_pivot_point
Expand All @@ -64,11 +65,17 @@
from . import pdt_bix
from . import pdt_etof
from . import pdt_tangent
from . import pdt_trig_waves

import bpy
import os
from pathlib import Path
from bpy.types import AddonPreferences, PropertyGroup, Scene, WindowManager
from bpy.types import (
AddonPreferences,
PropertyGroup, Scene,
WindowManager,
Object,
)
from bpy.props import (
BoolProperty,
CollectionProperty,
Expand Down Expand Up @@ -130,6 +137,39 @@
_pdt_mat_items = []


class PDTPreferences(AddonPreferences):
# This must match the addon name, use '__package__'
# when defining this in a submodule of a python package.

bl_idname = __name__

debug: BoolProperty(
name="Enable console debug output from PDT scripts",
default=False,
description="NOTE: Does not enable debugging globally in Blender (only in PDT scripts)",
)

pdt_ui_width: IntProperty(
name="UI Width Cut-off",
default=350,
description="Cutoff width for shrinking items per line in menus",
)

pdt_input_round: IntProperty(
name="Input Rounding", default=5, description="Rounding Factor for Inputs"
)

def draw(self, context):
layout = self.layout

box = layout.box()
row1 = box.row()
row2 = box.row()
row1.prop(self, "debug")
row2.prop(self, "pdt_ui_width")
row2.prop(self, "pdt_input_round")


def enumlist_objects(self, context):
"""Populate Objects List from Parts Library.
Expand All @@ -145,8 +185,8 @@ def enumlist_objects(self, context):

scene = context.scene
pg = scene.pdt_pg
file_path = context.preferences.addons[__package__].preferences.pdt_library_path
path = Path(file_path)
file_path = pg.pdt_library_path
path = Path(bpy.path.abspath(file_path))
_pdt_obj_items.clear()

if path.is_file() and ".blend" in str(path):
Expand All @@ -158,7 +198,7 @@ def enumlist_objects(self, context):
for object_name in object_names:
_pdt_obj_items.append((object_name, object_name, ""))
else:
_pdt_obj_items.append(("MISSING", "Library is Missing", ""))
_pdt_obj_items.append(("MISSING", "Library Not Set", ""))
return _pdt_obj_items


Expand All @@ -177,8 +217,8 @@ def enumlist_collections(self, context):

scene = context.scene
pg = scene.pdt_pg
file_path = context.preferences.addons[__package__].preferences.pdt_library_path
path = Path(file_path)
file_path = pg.pdt_library_path
path = Path(bpy.path.abspath(file_path))
_pdt_col_items.clear()

if path.is_file() and ".blend" in str(path):
Expand All @@ -192,7 +232,7 @@ def enumlist_collections(self, context):
for object_name in object_names:
_pdt_col_items.append((object_name, object_name, ""))
else:
_pdt_col_items.append(("MISSING", "Library is Missing", ""))
_pdt_col_items.append(("MISSING", "Library Not Set", ""))
return _pdt_col_items


Expand All @@ -211,8 +251,8 @@ def enumlist_materials(self, context):

scene = context.scene
pg = scene.pdt_pg
file_path = context.preferences.addons[__package__].preferences.pdt_library_path
path = Path(file_path)
file_path = pg.pdt_library_path
path = Path(bpy.path.abspath(file_path))
_pdt_mat_items.clear()

if path.is_file() and ".blend" in str(path):
Expand All @@ -226,13 +266,21 @@ def enumlist_materials(self, context):
for object_name in object_names:
_pdt_mat_items.append((object_name, object_name, ""))
else:
_pdt_mat_items.append(("MISSING", "Library is Missing", ""))
_pdt_mat_items.append(("MISSING", "Library Not Set", ""))
return _pdt_mat_items


class PDTSceneProperties(PropertyGroup):
"""Contains all PDT related properties."""

pdt_library_path: StringProperty(
name="Library",
default="",
description="Parts Library File",
maxlen=1024,
subtype="FILE_PATH",
)

object_search_string: StringProperty(name="Search", default="", description=PDT_DES_LIBSER)
collection_search_string: StringProperty(name="Search", default="", description=PDT_DES_LIBSER)
material_search_string: StringProperty(name="Search", default="", description=PDT_DES_LIBSER)
Expand Down Expand Up @@ -429,48 +477,34 @@ class PDTSceneProperties(PropertyGroup):
description=PDT_DES_TANMODE,
)


class PDTPreferences(AddonPreferences):
# This must match the addon name, use '__package__'
# when defining this in a submodule of a python package.

bl_idname = __name__

pdt_library_path: StringProperty(
name="Parts Library",
default="",
description="Parts Library File",
maxlen=1024,
subtype="FILE_PATH",
)

debug: BoolProperty(
name="Enable console debug output from PDT scripts",
default=False,
description="NOTE: Does not enable debugging globally in Blender (only in PDT scripts)",
)

pdt_ui_width: IntProperty(
name="UI Width Cut-off",
default=350,
description="Cutoff width for shrinking items per line in menus",
)

pdt_input_round: IntProperty(
name="Input Rounding", default=5, description="Rounding Factor for Inputs"
)

def draw(self, context):
layout = self.layout

box = layout.box()
row1 = box.row()
row2 = box.row()
row3 = box.row()
row1.prop(self, "debug")
row2.prop(self, "pdt_ui_width")
row2.prop(self, "pdt_input_round")
row3.prop(self, "pdt_library_path")
# For Trig Waves
trig_type : EnumProperty(
items=(
("sin", "Sine", "Sine Wave"),
("cos", "Cosine", "Cosine Wave"),
("tan", "Tangent", "Tangent Wave"),
),
name="Wave Form",
default="sin",
description="Trig. Wave Form",
)
trig_cycles : IntProperty(name="Cycles #", default=1, min=1,
description="1 Cycle = 180 Degrees")
trig_amp : FloatProperty(name="Amplitude", default=1, min=0.01,
description="Maximum Height of 1 Cycle (forms Basis for Tangents)")
trig_len : FloatProperty(name="Cycle Length", default=2, min=0.02,
description="Length in Blender Units of 1 Cycle")
trig_obj : PointerProperty(name="Object", type=Object)
trig_del : BoolProperty(name="Empty Object", default=False,
description="Delete ALL Vertices in Object First")
trig_res : IntProperty(name="Resolution", default=18, min=4, max=72,
description="Number of Vertices per Cycle (180 Degrees)")
trig_tanmax : FloatProperty(name="Tangent Max", default=10, min=0.1,
description="Maximum Permitted Tangent Value")
trig_off : FloatVectorProperty(name="Start Loc", default=(0,0,0),
description="Location in World Space for Origin of Wave")
trig_abs : BoolProperty(name="Absolute", default=False,
description="Use Absolute Values Only")


# List of All Classes in the Add-on to register
Expand All @@ -479,8 +513,8 @@ def draw(self, context):
# (and unloaded last)
#
classes = (
PDTSceneProperties,
PDTPreferences,
PDTSceneProperties,
pdt_bix.PDT_OT_LineOnBisection,
pdt_command.PDT_OT_CommandReRun,
pdt_design.PDT_OT_PlacementAbs,
Expand All @@ -507,6 +541,7 @@ def draw(self, context):
pdt_menus.PDT_PT_PanelViewControl,
pdt_menus.PDT_PT_PanelPivotPoint,
pdt_menus.PDT_PT_PanelPartsLibrary,
pdt_menus.PDT_PT_PanelTrig,
pdt_pivot_point.PDT_OT_ModalDrawOperator,
pdt_pivot_point.PDT_OT_ViewPlaneRotate,
pdt_pivot_point.PDT_OT_ViewPlaneScale,
Expand All @@ -523,6 +558,7 @@ def draw(self, context):
pdt_tangent.PDT_OT_TangentSet3,
pdt_tangent.PDT_OT_TangentSet4,
pdt_tangent.PDT_OT_TangentExpandMenu,
pdt_trig_waves.PDT_OT_WaveGenerator,
pdt_view.PDT_OT_ViewRot,
pdt_view.PDT_OT_ViewRotL,
pdt_view.PDT_OT_ViewRotR,
Expand Down
11 changes: 6 additions & 5 deletions pdt_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def execute(self, context):

scene = context.scene
pg = scene.pdt_pg
file_path = context.preferences.addons[__package__].preferences.pdt_library_path
file_path = pg.pdt_library_path
pg.error = str(Path(file_path))
debug("PDT Parts Library:")
debug(f"{pg.error}")
Expand Down Expand Up @@ -89,10 +89,10 @@ def execute(self, context):
return {"FINISHED"}

obj_names = [o.name for o in context.view_layer.objects].copy()
file_path = context.preferences.addons[__package__].preferences.pdt_library_path
file_path = pg.pdt_library_path
path = Path(file_path)

if path.is_file() and ".blend" in str(path):
if path.is_file() and str(path).endswith(".blend"):
if pg.lib_mode == "OBJECTS":
bpy.ops.wm.append(
filepath=str(path),
Expand Down Expand Up @@ -170,9 +170,10 @@ def execute(self, context):
self.report({"ERROR"}, error_message)
return {"FINISHED"}

file_path = context.preferences.addons[__package__].preferences.pdt_library_path
file_path = pg.pdt_library_path
path = Path(file_path)
if path.is_file() and ".blend" in str(path):

if path.is_file() and str(path).endswith(".blend"):
if pg.lib_mode == "OBJECTS":
bpy.ops.wm.link(
filepath=str(path),
Expand Down
41 changes: 40 additions & 1 deletion pdt_menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ def draw(self, context):
layout = self.layout
pdt_pg = context.scene.pdt_pg
row = layout.row()
row.prop(pdt_pg, "pdt_library_path")
row = layout.row()
col = row.column()
col.operator("pdt.append", text="Append")
col = row.column()
Expand Down Expand Up @@ -339,7 +341,7 @@ def draw(self, context):
row = box.row()
row.prop(pdt_pg, "lib_materials", text="")
row = box.row()
row.operator("pdt.lib_show", text="Show Library File", icon='INFO')
#row.operator("pdt.lib_show", text="Load Library File", icon='INFO')


class PDT_PT_PanelViewControl(Panel):
Expand Down Expand Up @@ -474,3 +476,40 @@ def draw(self,context):
split.prop(pdt_pg, "tangent_radius1", text="")
row = box.row()
row.operator("pdt.tangentoperate", text="Tangents From Inputs", icon="NONE")

class PDT_PT_PanelTrig(Panel):
bl_idname = "PDT_PT_PanelTrig"
bl_label = "PDT Trigonometrical Waves"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "PDT"
bl_options = {'DEFAULT_CLOSED'}

def draw(self,context):
layout = self.layout
pdt_pg = context.scene.pdt_pg
row = layout.row()
row.label(text=f"Working {PDT_LAB_PLANE}:")
row.prop(pdt_pg, "plane", text="")

row = layout.row()
split = row.split(factor=0.5, align=True)
split.prop(pdt_pg, "trig_type")
split.prop(pdt_pg, "trig_cycles")
row = layout.row()
split = row.split(factor=0.5, align=True)
split.prop(pdt_pg, "trig_amp")
split.prop(pdt_pg, "trig_len")
row = layout.row()
split = row.split(factor=0.5, align=True)
split.prop(pdt_pg, "trig_obj", text="")
split.prop(pdt_pg, "trig_del")
row = layout.row()
split = row.split(factor=0.5, align=True)
split.prop(pdt_pg, "trig_res")
split.prop(pdt_pg, "trig_tanmax")
row = layout.row()
row.prop(pdt_pg, "trig_off")
row = layout.row()
row.operator("pdt.wave_generator", icon="SEQ_LUMA_WAVEFORM")
row.prop(pdt_pg, "trig_abs")
4 changes: 2 additions & 2 deletions pdt_msg_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@
PDT_ERR_NOPPLOC = (
"Custom Property PDT_PP_LOC for this object not found, have you Written it yet?"
)
PDT_ERR_NO_LIBRARY = ("PDT Library Blend File (parts_library.blend) is Missing "
+ "from Addons/clockworxpdt Folder")
PDT_ERR_NO_LIBRARY = ("PDT Library Blend File is Missing "
+ "or not Correctly Set to a Blend File")

PDT_ERR_SEL_1_VERTI = "Select at least 1 Vertex Individually (Currently selected:"
PDT_ERR_SEL_1_VERT = "Select at least 1 Vertex (Currently selected:"
Expand Down

0 comments on commit 4cc1de1

Please sign in to comment.