Skip to content
Snippets Groups Projects
Operators.py 23.1 KiB
Newer Older
  • Learn to ignore specific revisions
  • 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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634
    import time
    import threading
    
    import bpy
    from bpy.props import *
    from bpy_extras import object_utils, view3d_utils
    from mathutils import  *
    from math import  *
    
    from . import Properties
    from . import Curves
    from . import CurveIntersections
    from . import Util
    from . import Surfaces
    from . import Math
    
    # 1 CURVE SELECTED
    # ################
    class OperatorCurveInfo(bpy.types.Operator):
        bl_idname = "curvetools2.operatorcurveinfo"
        bl_label = "Info"
        bl_description = "Displays general info about the active/selected curve"
    
    
        @classmethod
        def poll(cls, context):
            return Util.Selected1Curve()
    
    
        def execute(self, context):
            curve = Curves.Curve(context.active_object)
    
            nrSplines = len(curve.splines)
            nrSegments = 0
            nrEmptySplines = 0
            for spline in curve.splines:
                nrSegments += spline.nrSegments
                if spline.nrSegments < 1: nrEmptySplines += 1
    
    
            self.report({'INFO'}, "nrSplines: %d; nrSegments: %d; nrEmptySplines: %d" % (nrSplines, nrSegments, nrEmptySplines))
    
            return {'FINISHED'}
    
    
    
    class OperatorCurveLength(bpy.types.Operator):
        bl_idname = "curvetools2.operatorcurvelength"
        bl_label = "Length"
        bl_description = "Calculates the length of the active/selected curve"
    
    
        @classmethod
        def poll(cls, context):
            return Util.Selected1Curve()
    
    
        def execute(self, context):
            curve = Curves.Curve(context.active_object)
    
            context.scene.curvetools.CurveLength = curve.length
    
            return {'FINISHED'}
    
    
    
    class OperatorSplinesInfo(bpy.types.Operator):
        bl_idname = "curvetools2.operatorsplinesinfo"
        bl_label = "Info"
        bl_description = "Displays general info about the splines of the active/selected curve"
    
    
        @classmethod
        def poll(cls, context):
            return Util.Selected1Curve()
    
    
        def execute(self, context):
            curve = Curves.Curve(context.active_object)
            nrSplines = len(curve.splines)
    
            print("")
            print("OperatorSplinesInfo:", "nrSplines:", nrSplines)
    
            nrEmptySplines = 0
            for iSpline, spline in enumerate(curve.splines):
                print("--", "spline %d of %d: nrSegments: %d" % (iSpline + 1, nrSplines, spline.nrSegments))
    
                if spline.nrSegments < 1:
                    nrEmptySplines += 1
                    print("--", "--", "## WARNING: spline has no segments and will therefor be ignored in any further calculations")
    
    
            self.report({'INFO'}, "nrSplines: %d; nrEmptySplines: %d" % (nrSplines, nrEmptySplines) + " -- more info: see console")
    
            return {'FINISHED'}
    
    
    
    class OperatorSegmentsInfo(bpy.types.Operator):
        bl_idname = "curvetools2.operatorsegmentsinfo"
        bl_label = "Info"
        bl_description = "Displays general info about the segments of the active/selected curve"
    
    
        @classmethod
        def poll(cls, context):
            return Util.Selected1Curve()
    
    
        def execute(self, context):
            curve = Curves.Curve(context.active_object)
            nrSplines = len(curve.splines)
            nrSegments = 0
    
            print("")
            print("OperatorSegmentsInfo:", "nrSplines:", nrSplines)
    
            nrEmptySplines = 0
            for iSpline, spline in enumerate(curve.splines):
                nrSegmentsSpline = spline.nrSegments
                print("--", "spline %d of %d: nrSegments: %d" % (iSpline + 1, nrSplines, nrSegmentsSpline))
    
                if nrSegmentsSpline < 1:
                    nrEmptySplines += 1
                    print("--", "--", "## WARNING: spline has no segments and will therefor be ignored in any further calculations")
                    continue
    
                for iSegment, segment in enumerate(spline.segments):
                    print("--", "--", "segment %d of %d coefficients:" % (iSegment + 1, nrSegmentsSpline))
                    print("--", "--", "--", "C0: %.6f, %.6f, %.6f" % (segment.coeff0.x, segment.coeff0.y, segment.coeff0.z))
    
                nrSegments += nrSegmentsSpline
    
            self.report({'INFO'}, "nrSplines: %d; nrSegments: %d; nrEmptySplines: %d" % (nrSplines, nrSegments, nrEmptySplines))
    
            return {'FINISHED'}
    
    
    
    class OperatorOriginToSpline0Start(bpy.types.Operator):
        bl_idname = "curvetools2.operatororigintospline0start"
        bl_label = "OriginToSpline0Start"
        bl_description = "Sets the origin of the active/selected curve to the starting point of the (first) spline. Nice for curve modifiers."
    
    
        @classmethod
        def poll(cls, context):
            return Util.Selected1Curve()
    
    
        def execute(self, context):
            blCurve = context.active_object
            blSpline = blCurve.data.splines[0]
            newOrigin = blCurve.matrix_world @ blSpline.bezier_points[0].co
    
            origOrigin = bpy.context.scene.cursor.location.copy()
            print("--", "origOrigin: %.6f, %.6f, %.6f" % (origOrigin.x, origOrigin.y, origOrigin.z))
            print("--", "newOrigin: %.6f, %.6f, %.6f" % (newOrigin.x, newOrigin.y, newOrigin.z))
    
            bpy.context.scene.cursor.location = newOrigin
            bpy.ops.object.origin_set(type='ORIGIN_CURSOR')
            bpy.context.scene.cursor.location = origOrigin
    
            self.report({'INFO'}, "TODO: OperatorOriginToSpline0Start")
    
            return {'FINISHED'}
    
    
    
    # 2 CURVES SELECTED
    # #################
    class OperatorIntersectCurves(bpy.types.Operator):
        bl_idname = "curvetools2.operatorintersectcurves"
        bl_label = "Intersect"
        bl_description = "Intersects selected curves"
    
    
        @classmethod
        def poll(cls, context):
            return Util.Selected2OrMoreCurves()
    
    
        def execute(self, context):
            print("### TODO: OperatorIntersectCurves.execute()")
    
            algo = context.scene.curvetools.IntersectCurvesAlgorithm
            print("-- algo:", algo)
    
    
            mode = context.scene.curvetools.IntersectCurvesMode
            print("-- mode:", mode)
            # if mode == 'Split':
                # self.report({'WARNING'}, "'Split' mode is not implemented yet -- <<STOPPING>>")
                # return {'CANCELLED'}
    
            affect = context.scene.curvetools.IntersectCurvesAffect
            print("-- affect:", affect)
    
            selected_objects = context.selected_objects
            lenodjs = len(selected_objects)
            print('lenodjs:', lenodjs)
            for i in range(0, lenodjs):
                for j in range(0, lenodjs):
                    if j != i:
                        bpy.ops.object.select_all(action='DESELECT')
                        selected_objects[i].select_set(True)
                        selected_objects[j].select_set(True)
            
                        if selected_objects[i].type == 'CURVE' and selected_objects[j].type == 'CURVE':
                            curveIntersector = CurveIntersections.CurvesIntersector.FromSelection()
                            rvIntersectionNrs = curveIntersector.CalcAndApplyIntersections()
    
                            self.report({'INFO'}, "Active curve points: %d; other curve points: %d" % (rvIntersectionNrs[0], rvIntersectionNrs[1]))
            
            for obj in selected_objects:
                obj.select_set(True)
            
            return {'FINISHED'}
    
    
    class OperatorLoftCurves(bpy.types.Operator):
        bl_idname = "curvetools2.operatorloftcurves"
        bl_label = "Loft"
        bl_description = "Lofts selected curves"
    
    
        @classmethod
        def poll(cls, context):
            return Util.Selected2Curves()
    
    
        def execute(self, context):
            #print("### TODO: OperatorLoftCurves.execute()")
    
            loftedSurface = Surfaces.LoftedSurface.FromSelection()
            loftedSurface.AddToScene()
    
            self.report({'INFO'}, "OperatorLoftCurves.execute()")
    
            return {'FINISHED'}
    
    
    
    class OperatorSweepCurves(bpy.types.Operator):
        bl_idname = "curvetools2.operatorsweepcurves"
        bl_label = "Sweep"
        bl_description = "Sweeps the active curve along to other curve (rail)"
    
    
        @classmethod
        def poll(cls, context):
            return Util.Selected2Curves()
    
    
        def execute(self, context):
            #print("### TODO: OperatorSweepCurves.execute()")
    
            sweptSurface = Surfaces.SweptSurface.FromSelection()
            sweptSurface.AddToScene()
    
            self.report({'INFO'}, "OperatorSweepCurves.execute()")
    
            return {'FINISHED'}
    
    
    
    # 3 CURVES SELECTED
    # #################
    class OperatorBirail(bpy.types.Operator):
        bl_idname = "curvetools2.operatorbirail"
        bl_label = "Birail"
        bl_description = "Generates a birailed surface from 3 selected curves -- in order: rail1, rail2 and profile"
    
    
        @classmethod
        def poll(cls, context):
            return Util.Selected3Curves()
    
    
        def execute(self, context):
            birailedSurface = Surfaces.BirailedSurface.FromSelection()
            birailedSurface.AddToScene()
    
            self.report({'INFO'}, "OperatorBirail.execute()")
    
            return {'FINISHED'}
    
    
    
    # 1 OR MORE CURVES SELECTED
    # #########################
    class OperatorSplinesSetResolution(bpy.types.Operator):
        bl_idname = "curvetools2.operatorsplinessetresolution"
        bl_label = "SplinesSetResolution"
        bl_description = "Sets the resolution of all splines"
    
    
        @classmethod
        def poll(cls, context):
            return Util.Selected1OrMoreCurves()
    
    
        def execute(self, context):
            splRes = context.scene.curvetools.SplineResolution
            selCurves = Util.GetSelectedCurves()
    
            for blCurve in selCurves:
                for spline in blCurve.data.splines:
                    spline.resolution_u = splRes
    
            return {'FINISHED'}
    
    
    
    class OperatorSplinesRemoveZeroSegment(bpy.types.Operator):
        bl_idname = "curvetools2.operatorsplinesremovezerosegment"
        bl_label = "SplinesRemoveZeroSegment"
        bl_description = "Removes splines with no segments -- they seem to creep up, sometimes.."
    
    
        @classmethod
        def poll(cls, context):
            return Util.Selected1OrMoreCurves()
    
    
        def execute(self, context):
            selCurves = Util.GetSelectedCurves()
    
            for blCurve in selCurves:
                curve = Curves.Curve(blCurve)
                nrSplines = curve.nrSplines
    
                splinesToRemove = []
                for spline in curve.splines:
                    if len(spline.segments) < 1: splinesToRemove.append(spline)
                nrRemovedSplines = len(splinesToRemove)
    
                for spline in splinesToRemove: curve.splines.remove(spline)
    
                if nrRemovedSplines > 0: curve.RebuildInScene()
    
                self.report({'INFO'}, "Removed %d of %d splines" % (nrRemovedSplines, nrSplines))
    
            return {'FINISHED'}
    
    
    
    class OperatorSplinesRemoveShort(bpy.types.Operator):
        bl_idname = "curvetools2.operatorsplinesremoveshort"
        bl_label = "SplinesRemoveShort"
        bl_description = "Removes splines with a length smaller than the threshold"
    
    
        @classmethod
        def poll(cls, context):
            return Util.Selected1OrMoreCurves()
    
    
        def execute(self, context):
            threshold = context.scene.curvetools.SplineRemoveLength
            selCurves = Util.GetSelectedCurves()
    
            for blCurve in selCurves:
                curve = Curves.Curve(blCurve)
                nrSplines = curve.nrSplines
    
                nrRemovedSplines = curve.RemoveShortSplines(threshold)
                if nrRemovedSplines > 0: curve.RebuildInScene()
    
                self.report({'INFO'}, "Removed %d of %d splines" % (nrRemovedSplines, nrSplines))
    
            return {'FINISHED'}
    
    
    
    class OperatorSplinesJoinNeighbouring(bpy.types.Operator):
        bl_idname = "curvetools2.operatorsplinesjoinneighbouring"
        bl_label = "SplinesJoinNeighbouring"
        bl_description = "Joins neighbouring splines within a distance smaller than the threshold"
    
    
        @classmethod
        def poll(cls, context):
            return Util.Selected1OrMoreCurves()
    
    
        def execute(self, context):
            selCurves = Util.GetSelectedCurves()
    
            for blCurve in selCurves:
                curve = Curves.Curve(blCurve)
                nrSplines = curve.nrSplines
    
                threshold = context.scene.curvetools.SplineJoinDistance
                startEnd = context.scene.curvetools.SplineJoinStartEnd
                mode = context.scene.curvetools.SplineJoinMode
    
                nrJoins = curve.JoinNeighbouringSplines(startEnd, threshold, mode)
                if nrJoins > 0: curve.RebuildInScene()
    
                self.report({'INFO'}, "Applied %d joins on %d splines; resulting nrSplines: %d" % (nrJoins, nrSplines, curve.nrSplines))
    
            return {'FINISHED'}
            
    def SurfaceFromBezier(surfacedata, points, center):
        
        len_points = len(points) - 1
        
        if len_points % 2 == 0:
            h = Math.subdivide_cubic_bezier(
                            points[len_points].co, points[len_points].handle_right,
                            points[0].handle_left, points[0].co, 0.5
                            )
            points.add(1)
            len_points = len(points) - 1
            points[len_points - 1].handle_right = h[0]
            points[len_points].handle_left = h[1]
            points[len_points].co =  h[2]
            points[len_points].handle_right = h[3]
            points[0].handle_left =  h[4]
            
        half = round((len_points + 1)/2) - 1
        # 1
        surfacespline1 = surfacedata.splines.new(type='NURBS')
        surfacespline1.points.add(3)
        surfacespline1.points[0].co = [points[0].co.x, points[0].co.y, points[0].co.z, 1]
        surfacespline1.points[1].co = [points[0].handle_left.x, points[0].handle_left.y, points[0].handle_left.z, 1]
        surfacespline1.points[2].co = [points[len_points].handle_right.x,points[len_points].handle_right.y, points[len_points].handle_right.z, 1]
        surfacespline1.points[3].co = [points[len_points].co.x, points[len_points].co.y, points[len_points].co.z, 1]
        for p in surfacespline1.points:
            p.select = True
        surfacespline1.use_endpoint_u = True
        surfacespline1.use_endpoint_v = True
    
        for i in range(0, half):
         
            if center:
                # 2
                surfacespline2 = surfacedata.splines.new(type='NURBS')
                surfacespline2.points.add(3)
                surfacespline2.points[0].co = [points[i].co.x, points[i].co.y, points[i].co.z, 1]
                surfacespline2.points[1].co = [(points[i].co.x + points[len_points - i].co.x)/2,
                                               (points[i].co.y + points[len_points - i].co.y)/2,
                                               (points[i].co.z + points[len_points - i].co.z)/2, 1]
                surfacespline2.points[2].co = [(points[len_points - i].co.x + points[i].co.x)/2,
                                               (points[len_points - i].co.y + points[i].co.y)/2,
                                               (points[len_points - i].co.z + points[i].co.z)/2, 1]
                surfacespline2.points[3].co = [points[len_points - i].co.x, points[len_points - i].co.y, points[len_points - i].co.z, 1]
                for p in surfacespline2.points:
                    p.select = True
                surfacespline2.use_endpoint_u = True
                surfacespline2.use_endpoint_v = True
            
            # 3
            surfacespline3 = surfacedata.splines.new(type='NURBS')
            surfacespline3.points.add(3)
            surfacespline3.points[0].co = [points[i].handle_right.x, points[i].handle_right.y, points[i].handle_right.z, 1]
            surfacespline3.points[1].co = [(points[i].handle_right.x + points[len_points - i].handle_left.x)/2,
                                           (points[i].handle_right.y + points[len_points - i].handle_left.y)/2,
                                           (points[i].handle_right.z + points[len_points - i].handle_left.z)/2, 1]
            surfacespline3.points[2].co = [(points[len_points - i].handle_left.x + points[i].handle_right.x)/2,
                                           (points[len_points - i].handle_left.y + points[i].handle_right.y)/2,
                                           (points[len_points - i].handle_left.z + points[i].handle_right.z)/2, 1]
            surfacespline3.points[3].co = [points[len_points - i].handle_left.x, points[len_points - i].handle_left.y, points[len_points - i].handle_left.z, 1]
            for p in surfacespline3.points:
                p.select = True
            surfacespline3.use_endpoint_u = True
            surfacespline3.use_endpoint_v = True
        
            # 4
            surfacespline4 = surfacedata.splines.new(type='NURBS')
            surfacespline4.points.add(3)
            surfacespline4.points[0].co = [points[i + 1].handle_left.x, points[i + 1].handle_left.y, points[i + 1].handle_left.z, 1]
            surfacespline4.points[1].co = [(points[i + 1].handle_left.x + points[len_points - i - 1].handle_right.x)/2,
                                           (points[i + 1].handle_left.y + points[len_points - i - 1].handle_right.y)/2,
                                           (points[i + 1].handle_left.z + points[len_points - i - 1].handle_right.z)/2, 1]
            surfacespline4.points[2].co = [(points[len_points - i - 1].handle_right.x + points[i + 1].handle_left.x)/2,
                                           (points[len_points - i - 1].handle_right.y + points[i + 1].handle_left.y)/2,
                                           (points[len_points - i - 1].handle_right.z + points[i + 1].handle_left.z)/2, 1]
            surfacespline4.points[3].co = [points[len_points - i - 1].handle_right.x, points[len_points - i - 1].handle_right.y, points[len_points - i - 1].handle_right.z, 1]
            for p in surfacespline4.points:
                p.select = True
            surfacespline4.use_endpoint_u = True
            surfacespline4.use_endpoint_v = True
            
            if center:
                # 5
                surfacespline5 = surfacedata.splines.new(type='NURBS')
                surfacespline5.points.add(3)
                surfacespline5.points[0].co = [points[i + 1].co.x, points[i + 1].co.y, points[i + 1].co.z, 1]
                surfacespline5.points[1].co = [(points[i + 1].co.x + points[len_points - i - 1].co.x)/2,
                                               (points[i + 1].co.y + points[len_points - i - 1].co.y)/2,
                                               (points[i + 1].co.z + points[len_points - i - 1].co.z)/2, 1]
                surfacespline5.points[2].co = [(points[len_points - i - 1].co.x + points[i + 1].co.x)/2,
                                               (points[len_points - i - 1].co.y + points[i + 1].co.y)/2,
                                               (points[len_points - i - 1].co.z + points[i + 1].co.z)/2, 1]
                surfacespline5.points[3].co = [points[len_points - i - 1].co.x, points[len_points - i - 1].co.y, points[len_points - i - 1].co.z, 1]
                for p in surfacespline5.points:
                    p.select = True
                surfacespline5.use_endpoint_u = True
                surfacespline5.use_endpoint_v = True
            
        # 6
        surfacespline6 = surfacedata.splines.new(type='NURBS')
        surfacespline6.points.add(3)
        surfacespline6.points[0].co = [points[half].co.x, points[half].co.y, points[half].co.z, 1]
        surfacespline6.points[1].co = [points[half].handle_right.x, points[half].handle_right.y, points[half].handle_right.z, 1]
        surfacespline6.points[2].co = [points[half+1].handle_left.x, points[half+1].handle_left.y, points[half+1].handle_left.z, 1]
        surfacespline6.points[3].co = [points[half+1].co.x, points[half+1].co.y, points[half+1].co.z, 1]
        for p in surfacespline6.points:
            p.select = True
        surfacespline6.use_endpoint_u = True
        surfacespline6.use_endpoint_v = True
        
        bpy.ops.object.mode_set(mode = 'EDIT') 
        bpy.ops.curve.make_segment()
            
        for s in surfacedata.splines:
            s.resolution_u = 4
            s.resolution_v = 4
            s.order_u = 4
            s.order_v = 4
            for p in s.points:
                p.select = False
    
    class ConvertSelectedFacesToBezier(bpy.types.Operator):
        bl_idname = "curvetools2.convert_selected_face_to_bezier"
        bl_label = "Convert selected faces to Bezier"
        bl_description = "Convert selected faces to Bezier"
        bl_options = {'REGISTER', 'UNDO'}
    
        @classmethod
        def poll(cls, context):
            return Util.Selected1Mesh()
    
        def execute(self, context):
            # main function
            bpy.ops.object.mode_set(mode = 'OBJECT')
            active_object = context.active_object
            meshdata = active_object.data
            curvedata = bpy.data.curves.new('Curve' + active_object.name, type='CURVE')
            curveobject = object_utils.object_data_add(context, curvedata)
            curvedata.dimensions = '3D'
            
            for poly in meshdata.polygons:
                if poly.select:
                    newSpline = curvedata.splines.new(type='BEZIER')
                    newSpline.use_cyclic_u = True
                    newSpline.bezier_points.add(poly.loop_total - 1)
                    npoint = 0
                    for loop_index in range(poly.loop_start, poly.loop_start + poly.loop_total):
                        newSpline.bezier_points[npoint].co = meshdata.vertices[meshdata.loops[loop_index].vertex_index].co
                        newSpline.bezier_points[npoint].handle_left_type = 'VECTOR'
                        newSpline.bezier_points[npoint].handle_right_type = 'VECTOR'
                        newSpline.bezier_points[npoint].select_control_point = True
                        newSpline.bezier_points[npoint].select_left_handle = True
                        newSpline.bezier_points[npoint].select_right_handle = True
                        npoint += 1
                                      
            return {'FINISHED'}
            
    class ConvertBezierToSurface(bpy.types.Operator):
        bl_idname = "curvetools2.convert_bezier_to_surface"
        bl_label = "Convert Bezier to Surface"
        bl_description = "Convert Bezier to Surface"
        bl_options = {'REGISTER', 'UNDO'}
    
        Center : BoolProperty(
                name="Center",
                default=False,
                description="Consider center points"
                )
                
        Resolution_U: IntProperty(
                name="Resolution_U",
                default=4,
                min=1, max=64,
                soft_min=1,
                description="Surface resolution U"
                )
                
        Resolution_V: IntProperty(
                name="Resolution_V",
                default=4,
                min=1, max=64,
                soft_min=1,
                description="Surface resolution V"
                )
                
        def draw(self, context):
            layout = self.layout
    
             # general options
            col = layout.column()
            col.prop(self, 'Center')
            col.prop(self, 'Resolution_U')
            col.prop(self, 'Resolution_V')
        
        @classmethod
        def poll(cls, context):
            return (context.object is not None and
                    context.object.type == 'CURVE')
    
        def execute(self, context):
            # main function
            bpy.ops.object.mode_set(mode = 'OBJECT') 
            active_object = context.active_object
            curvedata = active_object.data
            
            surfacedata = bpy.data.curves.new('Surface', type='SURFACE')
            surfaceobject = object_utils.object_data_add(context, surfacedata)
            surfaceobject.matrix_world = active_object.matrix_world
            surfaceobject.rotation_euler = active_object.rotation_euler
            surfacedata.dimensions = '3D'
            surfaceobject.show_wire = True
            surfaceobject.show_in_front = True
            
            for spline in curvedata.splines:
                SurfaceFromBezier(surfacedata, spline.bezier_points, self.Center)
                
            for spline in surfacedata.splines:
                len_p = len(spline.points)
                len_devide_4 = round(len_p / 4) + 1
                len_devide_2 = round(len_p / 2)
                bpy.ops.object.mode_set(mode = 'EDIT')
                for point_index in range(len_devide_4, len_p - len_devide_4):
                    if point_index != len_devide_2 and point_index != len_devide_2 - 1:
                        spline.points[point_index].select = True
                    
                surfacedata.resolution_u = self.Resolution_U
                surfacedata.resolution_v = self.Resolution_V
    
            return {'FINISHED'}