@@ -3815,91 +3815,14 @@ class AddReferenceImage(bpy.types.Operator, tool.Ifc.Operator, ImportHelper):
38153815 description = "Existing object name to add a style with reference image to. If not provided will create a new object." ,
38163816 options = {"SKIP_SAVE" },
38173817 )
3818-
3819- x_length : bpy .props .FloatProperty (
3820- name = "X Length" ,
3821- description = "Width of the reference image in project units" ,
3822- default = 1.0 ,
3823- min = 0.001 ,
3824- soft_min = 0.01 ,
3825- precision = 3 ,
3826- )
3827- y_length : bpy .props .FloatProperty (
3828- name = "Y Length" ,
3829- description = "Height of the reference image in project units" ,
3830- default = 1.0 ,
3831- min = 0.001 ,
3832- soft_min = 0.01 ,
3833- precision = 3 ,
3834- )
3835-
3836- show_dimensions_dialog : bpy .props .BoolProperty (default = False , options = {"HIDDEN" , "SKIP_SAVE" })
3818+ size : bpy .props .FloatProperty (name = "Size" , description = "Size of the reference image" , default = 1.0 , unit = "LENGTH" )
38373819
38383820 def draw (self , context ):
3839- layout = self .layout
3840-
3841- if getattr (self , "show_dimensions_dialog" , False ):
3842- if tool .Ifc .get ():
3843- length_unit = ifcopenshell .util .unit .get_project_unit (tool .Ifc .get (), "LENGTHUNIT" )
3844- if length_unit :
3845- unit_name = ifcopenshell .util .unit .get_full_unit_name (length_unit ).lower ()
3846- else :
3847- unit_name = "project units"
3848- layout .label (text = f"Set Reference Image Dimensions (in { unit_name } ):" )
3849- else :
3850- layout .label (text = "Set Reference Image Dimensions (in project units):" )
3851- layout .separator ()
3852- layout .prop (self , "x_length" )
3853- layout .prop (self , "y_length" )
3854- else :
3855- if Path (tool .Ifc .get_path ()).is_file ():
3856- layout .prop (self , "use_relative_path" )
3857- else :
3858- self .use_relative_path = False
3859- layout .label (text = "Save the .ifc file first " )
3860- layout .label (text = "to use relative paths." )
3861- layout .prop (self , "override_existing_image" )
3862- layout .prop (self , "use_existing_object_by_name" )
3863-
3864- def invoke (self , context , event ):
3865- if not getattr (self , "show_dimensions_dialog" , False ):
3866- context .window_manager .fileselect_add (self )
3867- return {"RUNNING_MODAL" }
3868- else :
3869- return context .window_manager .invoke_props_dialog (self )
3870-
3871- def execute (self , context ):
3872- if not getattr (self , "show_dimensions_dialog" , False ):
3873- abs_path = Path (self .filepath ).absolute ().resolve ()
3874- if self .override_existing_image :
3875- params = {"check_existing" : True , "force_reload" : True }
3876- else :
3877- params = {"check_existing" : False }
3878-
3879- try :
3880- image = load_image (abs_path .name , str (abs_path .parent ), ** params )
3881-
3882- image_width_px = image .size [0 ]
3883- image_height_px = image .size [1 ]
3884- aspect_ratio = image_width_px / image_height_px
3885-
3886- if aspect_ratio >= 1.0 :
3887- self .x_length = 1.0
3888- self .y_length = 1.0 / aspect_ratio
3889- else :
3890- self .x_length = aspect_ratio
3891- self .y_length = 1.0
3892-
3893- bpy .data .images .remove (image )
3894-
3895- except Exception as e :
3896- self .report ({"ERROR" }, f"Failed to load image: { str (e )} " )
3897- return {"CANCELLED" }
3898-
3899- self .show_dimensions_dialog = True
3900- return context .window_manager .invoke_props_dialog (self )
3901-
3902- return self ._execute (context )
3821+ if Path (tool .Ifc .get_path ()).is_file ():
3822+ self .layout .prop (self , "use_relative_path" )
3823+ self .layout .prop (self , "override_existing_image" )
3824+ self .layout .prop (self , "use_existing_object_by_name" )
3825+ self .layout .prop (self , "size" )
39033826
39043827 def _execute (self , context ):
39053828 space = tool .Blender .get_view3d_space ()
@@ -3920,11 +3843,19 @@ def _execute(self, context):
39203843 params = {"check_existing" : False }
39213844 image = load_image (abs_path .name , str (abs_path .parent ), ** params )
39223845
3846+ aspect_ratio = image .size [0 ] / image .size [1 ]
3847+ if aspect_ratio >= 1.0 : # Landscape
3848+ x_length = self .size
3849+ y_length = self .size / aspect_ratio
3850+ else :
3851+ x_length = self .size / aspect_ratio
3852+ y_length = self .size
3853+
39233854 def bm_add_image_plane (mesh ):
39243855 bm = tool .Blender .get_bmesh_for_mesh (mesh , clean = True )
39253856
39263857 unit_scale = ifcopenshell .util .unit .calculate_unit_scale (ifc_file )
3927- plane_scale = Vector ((self . x_length * unit_scale / 2.0 , self . y_length * unit_scale / 2.0 , 1.0 ))
3858+ plane_scale = Vector ((x_length / 2.0 , y_length / 2.0 , 1.0 ))
39283859 matrix = Matrix .LocRotScale (None , None , plane_scale )
39293860 bmesh .ops .create_grid (bm , x_segments = 1 , y_segments = 1 , size = 1 , matrix = matrix , calc_uvs = False )
39303861
@@ -4028,8 +3959,6 @@ def bm_add_image_plane(mesh):
40283959 tool .Style .reload_material_from_ifc (material )
40293960 tool .Geometry .record_object_materials (obj )
40303961
4031- return {"FINISHED" }
4032-
40333962
40343963class ConvertSVGToDXF (bpy .types .Operator ):
40353964 bl_idname = "bim.convert_svg_to_dxf"
0 commit comments