convert class to addon

(flokkievids) #1

after 2 days this code works, but i’d like to add the Surface plane from the add menu. i know how to do something in the toolbar, but not within the add menu.

class MakeSurfacePlane(bpy.types.Operator):
    bl_idname = 'object.add_surface_plane'
    bl_label = 'add a surface plane'
    bl_space_type = 'VIEW_3D'
     

    def execute(self,context):
 

        bpy.ops.surface.primitive_nurbs_surface_surface_add() #add the base mesh, a NURBS Surface 

        bpy.ops.transform.resize(value=(1,1,0.0001),constraint_axis=(False,False,True)) # make it flat
        ao = bpy.context.active_object.name # get the active object' s name
        #added surface has 16 points

        #deleting points to get plane shape.
        bpy.ops.object.mode_set(mode='EDIT')  
        bpy.ops.curve.select_all(action='DESELECT')
         
        bpy.context.active_object.data.splines[0].points[0].select = True
        bpy.context.active_object.data.splines[0].points[1].select = True
        bpy.context.active_object.data.splines[0].points[2].select = True
        bpy.context.active_object.data.splines[0].points[3].select = True
        bpy.ops.curve.delete(type='SELECTED')

        bpy.context.active_object.data.splines[0].points[8].select = True
        bpy.context.active_object.data.splines[0].points[9].select = True
        bpy.context.active_object.data.splines[0].points[10].select = True
        bpy.context.active_object.data.splines[0].points[11].select = True
        bpy.ops.curve.delete(type='SELECTED')

        bpy.context.active_object.data.splines[0].points[0].select = True
        bpy.context.active_object.data.splines[0].points[4].select = True
        bpy.ops.curve.delete(type='SELECTED')
        bpy.context.active_object.data.splines[0].points[2].select = True
        bpy.context.active_object.data.splines[0].points[5].select = True
        bpy.ops.curve.delete(type='SELECTED')

        #assigning name
        bpy.context.active_object.name = 'SurfacePlane'
        #select all
        bpy.ops.curve.select_all(action = 'SELECT')
        #bringing origin to center:
        bpy.ops.object.mode_set(mode='OBJECT')  
        bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY', center='MEDIAN')
        #transform scale
        bpy.ops.object.transform_apply(scale = True)
        #bring object to 3d cursor.
        bpy.ops.object.mode_set(mode='OBJECT')
        bpy.context.active_object.location  = bpy.context.scene.cursor_location


        return('FINISHED')
0 Likes

(RickyBlender) #2

see the pipe script for the add menu

happy 2.5

0 Likes

(flokkievids) #3

ahh thanks, that works. now writing more surface’s code. irritating you have to construct them from primitives…

0 Likes

(RickyBlender) #4

you can make your own primitives
or edit an existing one

your choice

happy 2.5

0 Likes

(flokkievids) #5

ok got this now
link
and it works. but i’d like to get the scale, resolution and align to view things in the toolbar. tips for that?

0 Likes

(Meta-Androcto) #6


hi, i get this error with current svn, it’s in a few scripts atm.
btw, thanks fot the cool script! your the first add_surface script!

0 Likes

(flokkievids) #7

ty, it was realy difficult to find what i needed… luckily it’s there(thanks dev’s). and you can’t just make a nurbs surface, most of the times a ‘face’ can not be created, and you have to start from a base mesh and delete/scale/rotate things from that to get certain things.

for the error, i think it’s not my fault then, and that’s good. i got the lates official build of 2.59, and it works. currently i want to get the align to view and resolution in the toolbar. seems difficult.

all tips welcome :slight_smile:
btw, is there a 'remove doubles’function for curves/Nurbs surfaces?

0 Likes

(flokkievids) #8

for most things, but with nurbs i always get a nurbs curve, and not a nurbs surface(different thing). and i think modifying existing ones is easier, since most of the time a face cannot be created.

0 Likes

(Meta-Androcto) #9

hi, to fix this error change return(‘FINISHED’) should be return{‘FINISHED’} in line 86

0 Likes

(flokkievids) #10

thanks, did that. in my search for other usefull things i made a star shape too :slight_smile:
link
now i realy want to know how to make settings adjustable in the tool shelf/panel

edit:
ok that is about done, just have to add ‘align to view’ to it, but that seems a problem, and i haven’t seen other script doing this. anybody knows?

0 Likes

(flokkievids) #11

new version
link
you can now adjust the u and v resolution, and the scale. plz post tips :slight_smile:

0 Likes

(flokkievids) #12

ok new version again, get it here.
you can now also:
add a wedge
smooth x times in both surface and curve edit mode(a feature i was missing, and handy to have. since curves and surfaces use the same specials panel, it’s accesable from curve edit mode too.)

and i added some more comments to make it clearer what’s hapening :).

still missing:
requests
the ‘align to view’, i guess i need to work around it :slight_smile:

0 Likes

(flokkievids) #13

i saw the thread, and could use it, but it doesn’t seem to work when scripting…

0 Likes

(Meta-Androcto) #14

hi, a few fixes here: http://blenderpython.svn.sourceforge.net/viewvc/blenderpython/scripts_library/scripts/addons_extern/add_surface_plane_cone.py

0 Likes

(flokkievids) #15

thanks, the file is looking so clean now :o

0 Likes