#----------------------------------------------------------------------------- # Facet Lister # Simplified from Group2Morph parts.... # April 10, 2006 # Copyright (c) 2006 by David G. Drumright (ockham) #----------------------------------------------------------------------------- import poser import string import math from Tkinter import * scene = poser.Scene() #----------------------------------------------------------------------------- # Global vars #----------------------------------------------------------------------------- global OneActor global OneGeom global SelectedGroups OneActor=0 OneGeom=0 SelectedGroups={} # index is number in list, content is name. #----------------------------------------------------------------------------- def InitFirst(): # Check the basics before putting anything up. global OneActor global OneGeom OneActor = scene.CurrentActor() # There's always a CurrentActor try: # Get the Geom of the chosen actor: OneGeom = OneActor.Geometry() except: raise "Chosen part doesn't have a mesh." # Get the group list so we can let you select. # You may want to use one of the pre-existing # groups, or you may have made your own. if OneGeom.Groups() == None: raise "No groups in this actor" #------------------------------------------------------------ #------------------------------------------------------------ # Next section is TK #------------------------------------------------------------ class App: def __init__(self, master, textMessage): self.master = master self.master.title("Facet lister") # Status goes on top self.StatusEntry=Entry(self.master,width=40) self.StatusEntry.grid(row=0,column=0,columnspan=3) self.StatusEntry.insert(0,"Select groups then hit Go to print list.") # Frames for list and buttons self.ListFrame = Frame(self.master,borderwidth=2,relief=RIDGE) self.ListFrame.grid(row=1,column=0,pady=1) self.BottomFrame = Frame(self.master,borderwidth=2,relief=RIDGE) self.BottomFrame.grid(row=6,column=0,pady=1) # List and scroll self.GroupScroll = Scrollbar(self.ListFrame, orient=VERTICAL) self.GroupScroll.grid( row=0, column=0,sticky=N+S+E) self.GroupBox = Listbox(self.ListFrame, height=5, selectmode=MULTIPLE,yscrollcommand = self.GroupScroll.set) self.GroupBox.grid( row=0, column=1) # Fill with names of Groups for OneName in OneGeom.Groups(): self.GroupBox.insert(END,OneName) # Set the scrollbar to work self.GroupScroll["command"] = self.GroupBox.yview # Name and Go buttons, in Bottom frame self.buttonNormGo = Button(self.BottomFrame, text="Go", command=self.handleNormGo) self.buttonNormGo.grid(row=1, column=0) self.buttonCancel = Button(self.BottomFrame, text="Cancel", command=self.handleCancel) self.buttonCancel.grid(row=1, column=2) self.master.protocol('WM_DELETE_WINDOW', self.handleCancel) # - - - - - - - - - - - - - - - - - - def LocateAllVerts(self): # Get the list: SelectedIndexes = self.GroupBox.curselection() SelectedGroups={} for N in SelectedIndexes: intN = int(N) SelectedGroups[intN] = self.GroupBox.get(intN) if len(SelectedGroups.keys())<1: self.ShowStatus("No groups selected. Try again.") return # Start the Facets and Verts lists with just the basics, # and the default markings for Group and Layer. # Reminder: use only the group-list index, not the group name, # in places where group needs to be an index. group = -1 # default index: real one will be >=0 dist = -1.0 # default net distance: real will be >=0.0 X = 0.0 Y = 0.0 Z = 0.0 # Go through the Polygons (facets) of the Geom, by Groups. # Reminder: this will give dups of V index. This is what we # want at this stage so we can spot Ridges. When we sort for # non-Ridge we eliminate the dups. fp=open("facets.txt","wt") scene.DrawAll() SetList = OneGeom.Sets() for GroupIndex in SelectedGroups.keys(): GroupName = SelectedGroups[GroupIndex] # optimize for FacetIndex in range(OneGeom.NumPolygons()): OneFacet = OneGeom.Polygon(FacetIndex) if OneFacet.InGroup(GroupName): print 'Facet %d includes:' % (FacetIndex + 1) fp.write('Facet %d includes:\n' % (FacetIndex + 1)) First = OneFacet.Start() Last = First + OneFacet.NumVertices() for V in SetList[First:Last]: # This is a list of vertex indexes in the poly # Get the values: OneVert = OneGeom.Vertex(V) OneWorld = OneGeom.WorldVertex(V) X = OneVert.X() Y = OneVert.Y() Z = OneVert.Z() wX = OneWorld.X() wY = OneWorld.Y() wZ = OneWorld.Z() print 'Vertex %d basic locs x %f y %f z %f\n' % (V+1,X,Y,Z) print ' world locs x %f y %f z %f\n' % (wX,wY,wZ) fp.write('Vertex %d basic locs x %f y %f z %f\n' % (V+1,X,Y,Z)) fp.write(' world locs x %f y %f z %f\n' % (wX,wY,wZ)) fp.close() # - - - - - - - - - - - - - - - - - - def ShowStatus(self,S): # Just saving repetition self.StatusEntry.delete(0,END) self.StatusEntry.insert(0,S) self.StatusEntry.update_idletasks() # - - - - - - - - - - - - - - - - - - def Update(self): scene.ProcessSomeEvents(1) root.lift() root.after(100, self.Update) # - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - def handleNormGo(self): self.LocateAllVerts() # - - - - - - - - - - - - - - - - - - def handleCancel(self): self.master.destroy() #------------------------------------------------------------ # End defs, begin action here. #------------------------------------------------------------ InitFirst() root = Tk() app = App(root,'') app.Update() root.mainloop() #------------------------------------------------------------ # End TK loop. #-----------------------------------------------------------------------------