1import bpy 2from mathutils import * 3 4 5def GetSelectedCurves(): 6 rvList = [] 7 8 for obj in bpy.context.selected_objects: 9 try: 10 if obj.type == "CURVE": rvList.append(obj) 11 except: 12 pass 13 14 return rvList 15 16 17def GetSelectedMeshes(): 18 rvList = [] 19 20 for obj in bpy.context.selected_objects: 21 try: 22 if obj.type == "MESH": rvList.append(obj) 23 except: 24 pass 25 26 return rvList 27 28 29def Selected1Curve(): 30 try: 31 if len(GetSelectedCurves()) == 1: 32 return (bpy.context.active_object.type == "CURVE") 33 except: 34 pass 35 36 return False 37 38 39def Selected1Mesh(): 40 try: 41 if len(GetSelectedMeshes()) == 1: 42 return (bpy.context.active_object.type == "MESH") 43 except: 44 pass 45 46 return False 47 48 49def Selected1SingleSplineCurve(): 50 try: 51 if Selected1Curve(): 52 return (len(bpy.context.active_object.data.splines) == 1) 53 except: 54 pass 55 56 return False 57 58 59def Selected2Curves(): 60 try: 61 if len(GetSelectedCurves()) == 2: 62 return (bpy.context.active_object.type == "CURVE") 63 except: 64 pass 65 66 return False 67 68 69def Selected3Curves(): 70 try: 71 if len(GetSelectedCurves()) == 3: 72 return (bpy.context.active_object.type == "CURVE") 73 except: 74 pass 75 76 return False 77 78 79def Selected1OrMoreCurves(): 80 try: 81 if len(GetSelectedCurves()) > 0: 82 return (bpy.context.active_object.type == "CURVE") 83 except: 84 pass 85 86 return False 87 88def Selected2OrMoreCurves(): 89 try: 90 if len(GetSelectedCurves()) > 1: 91 return (bpy.context.active_object.type == "CURVE") 92 except: 93 pass 94 95 return False 96 97 98def Selected1OrMoreMesh(): 99 try: 100 if len(GetSelectedMeshes()) > 0: 101 return (bpy.context.active_object.type == "MESH") 102 except: 103 pass 104 105 return False 106 107 108def GetToolsRegion(): 109 for area in bpy.context.screen.areas: 110 if area.type == 'VIEW_3D': 111 for region in area.regions: 112 if region.type == 'TOOLS': return region 113 114 return None 115 116 117def GetFirstRegionView3D(): 118 for area in bpy.context.screen.areas: 119 if area.type == 'VIEW_3D': 120 return area.spaces[0].region_3d 121 122 return None 123 124 125def LogFirstRegionView3D(): 126 print("LogFirstRegionView3D()") 127 regionView3D = GetFirstRegionView3D() 128 if regionView3D is None: 129 print("--", "ERROR:", "regionView3D is None") 130 return 131 132 print("--", "view_matrix:") 133 print("--", "--", regionView3D.view_matrix) 134 print("--", "view_location:") 135 print("--", "--", regionView3D.view_location) 136 137 138class Intersection: 139 # listIP: list of BezierSplineIntersectionPoint 140 # return: list of splines 141 @staticmethod 142 def GetBezierSplines(listIP): 143 rvList = [] 144 145 for ip in listIP: 146 if not (ip.spline in rvList): rvList.append(ip.spline) 147 148 return rvList 149 150 151 # listIP: list of BezierSplineIntersectionPoint 152 # return: list of segments 153 @staticmethod 154 def GetBezierSegments(listIP, spline): 155 rvList = [] 156 157 for ip in listIP: 158 if not ip.spline is spline: continue 159 160 segIP = ip.bezierSegmentIntersectionPoint 161 if not (segIP.segment in rvList): rvList.append(segIP.segment) 162 163 return rvList 164 165 166 # listIP: list of BezierSplineIntersectionPoint 167 # return: list of floats (not necessarily ordered) 168 @staticmethod 169 def GetBezierSegmentParameters(listIP, segment): 170 rvList = [] 171 172 for ip in listIP: 173 segIP = ip.bezierSegmentIntersectionPoint 174 if not segIP.segment is segment: continue 175 176 rvList.append(segIP.parameter) 177 178 return rvList 179