Blender Underground

Away from the watchful eye of The Man
It is currently Wed May 22, 2013 2:12 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Anybody wants to make my script as a plug-in?
PostPosted: Mon Jan 02, 2012 7:01 pm 
Offline
Associate
User avatar

Joined: Sun Jan 30, 2011 5:43 pm
Posts: 86
I've written a script and didn't manage to make it as plug-in. I've already received some helps in this forum:
viewtopic.php?f=2&t=6387&start=0
I tried out different things and I still can't get it work. So, I thought this could be an easy job for people who have done that before.
My script allows users to select alternatively edges/vertices. I want to be able to enter following parameters from GUI:
selOffset
selNum
unselNum

Code:
import bpy
# retrieve the active object
bpy.ops.object.mode_set(mode = 'OBJECT')
cur_obj = bpy.context.active_object

selOffset= 0
selNum= 1
unselNum= 2


if bpy.context.tool_settings.mesh_select_mode[0]:
   vertexUsed= True
else:
   vertexUsed= False
   bpy.context.tool_settings.mesh_select_mode=( False, True, False)

cur_obj= bpy.context.active_object 
sel_edges=[i.index for i in cur_obj.data.edges if i.select]
print( sel_edges)
sel_vertices=[ ( cur_obj.data.edges[i].vertices[0], cur_obj.data.edges[i].vertices[1], i) for i in sel_edges]
#print( sel_vertices)

sel_loop=[]
vFrom= sel_vertices[0]
sel_vertices.remove( vFrom)
sel_loop.append( vFrom)
for i in range( len( sel_vertices)):
   vTo=(-1,-1)
   for v in sel_vertices:
      # If edge connects to 1st vertex
      if vFrom[1]== v[0]:
         vTo= v
      # If edge connects to 2nd vertex
      if vFrom[1]== v[1]:
         vTo=( v[1], v[0], v[2])
         
      if vTo[0] >= 0 and vTo[1] >= 0:
         sel_vertices.remove( v)
         sel_loop.append( vTo)
         break
         
   vFrom= vTo
print( sel_loop)

selOffset%= len( sel_loop)
for i in range( selOffset):
   sel_loop.append( sel_loop[0])
   sel_loop.remove( sel_loop[0])
   
   
selCnt= selNum
unselCnt= 0

for iLoop in sel_loop:
   if selCnt > 0:
      selCnt-=1
      if selCnt== 0:
         unselCnt= unselNum
   else:
      if unselCnt > 0:
         if vertexUsed:
            cur_obj.data.vertices[ iLoop[0]].select= False
         else:
            cur_obj.data.edges[ iLoop[2]].select= False
         unselCnt-= 1
         print( iLoop)
         if unselCnt== 0:
            selCnt= selNum

bpy.ops.object.mode_set(mode = 'EDIT')


It would be great if someone can do that for me. My header would look like this (some parameters not too sure):
Code:
bl_info = {
   "name": "Saw Blade",
   "author": "Phuoc Can HUA",
   "version": (1, 0, 0),
   "blender": (2, 6, 1),
   "api": 36147,
   "location": "View3D>Edit Mode>Specials (W-key)",
   "category": "Mesh",
   "description": "Select nth edges/vertices of a loop, e.g. circle.",
   "warning": "It's my first script!",
   "wiki_url": "",
   "tracker_url": ""
}


Many many thanks
Phuoc

_________________
Blender 2.65


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: Google [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Translated by Xaphos © 2007, 2008, 2009 phpBB.fr