Quantcast
Channel: Rhino Developer - McNeel Forum
Viewing all articles
Browse latest Browse all 8620

ETO Form Cancel Button

$
0
0

Hi

Please can you advise how I should code the eto form “Cancel” button so the script stops immediately it is pressed at present the script continues with the layer dialogue box opening up and then having to “Cancel” again.

Please keep any answer simple as I have limited Python knowledge.

#Imports
import Rhino
import Rhino.UI
import scriptcontext as sc
import System
import Eto.Drawing as drawing
import Eto.Forms as forms
import rhinoscriptsyntax as rs
from System.Drawing import Color

from decimal import Decimal
import math
pi = math.pi 

#Geo Vectors Points dialog class
class GeoMovePointsDialog(forms.Dialog[bool]):
    
    # Dialog box Class initializer
    def __init__(self):

        #call base class initializer
        super().__init__()

        # Initialize dialog box
        self.Title = "Geo Move Points"
        self.Padding = drawing.Padding(10)
        self.Resizable = False
        
        self.m_label6 = forms.Label()
        self.m_label6.Text = "Dist X mm:"

        self.m_DistX_textbox = forms.TextBox()
        self.m_DistX_textbox.Text = "0"        
        
        self.m_label7 = forms.Label()
        self.m_label7.Text =  "Dist Y mm:"

        self.m_DistY_textbox = forms.TextBox()
        self.m_DistY_textbox.Text = "0"      
        
        self.m_label8 = forms.Label()
        self.m_label8.Text = "Dist Z mm:"

        self.m_DistZ_textbox = forms.TextBox()
        self.m_DistZ_textbox.Text = "0" 
        
        
        # Create the default button
        self.DefaultButton = forms.Button()
        self.DefaultButton.Text = "OK"
        self.DefaultButton.Click += self.OnOKButtonClick
        
        # Create the abort button
        self.AbortButton = forms.Button()
        self.AbortButton.Text = "Cancel"
        self.AbortButton.Click += self.OnCloseButtonClick
        
        
        # Create a table layout and add all the controls
        layout = forms.DynamicLayout()
        layout.Spacing = drawing.Size(5, 5)
        
        layout.AddRow(self.m_label6, self.m_DistX_textbox)
        
        layout.AddRow(self.m_label7, self.m_DistY_textbox)
        
        layout.AddRow(self.m_label8, self.m_DistZ_textbox)
        
        layout.AddRow(None) # spacer
        layout.AddRow(self.DefaultButton, self.AbortButton)
        
        # Set the dialog content
        self.Content = layout
        self.Load += self.OnFormLoad
        self.Closing += self.OnFormClosing
        

    
    # Start of the class functions
    
    # Get the value of the textbox
        
    def GetText6(self):
        return self.m_DistX_textbox.Text

    def GetText7(self):
        return self.m_DistY_textbox.Text

    def GetText8(self):
        return self.m_DistZ_textbox.Text
    
    # Close button click handler
    def OnCloseButtonClick(self, sender, e):
        self.Close(False)
        
    # OK button click handler
    def OnOKButtonClick(self, sender, e):
        self.Close(True)
        
        
        
        
    def OnFormLoad(self, sender, e):
        # set previous or default text for "Job Number"
            
        if sc.sticky.has_key("Dist X"):
            # set last used text if found in sticky
            self.m_DistX_textbox.Text = sc.sticky["Dist X"]
        else:
            # set default text if not not found in sticky
            self.m_DistX_textbox.Text = "0"
       
        if sc.sticky.has_key("Dist Y"):
            # set last used text if found in sticky
            self.m_DistY_textbox.Text = sc.sticky["Dist Y"]
        else:
            # set default text if not not found in sticky
            self.m_DistY_textbox.Text = "0"
            
        if sc.sticky.has_key("Dist Z"):
            # set last used text if found in sticky
            self.m_DistZ_textbox.Text = sc.sticky["Dist Z"]
        else:
            # set default text if not not found in sticky
            self.m_DistZ_textbox.Text = "0"
            
    
    def OnFormClosing(self, sender, e):
        
        # store the text from the text box in sticky (it can be empty)
        sc.sticky["Dist X"] = self.m_DistX_textbox.Text
        
       # store the text from the text box in sticky (it can be empty)
        sc.sticky["Dist Y"] = self.m_DistY_textbox.Text
        
        # store the text from the text box in sticky (it can be empty)
        sc.sticky["Dist Z"] = self.m_DistZ_textbox.Text
        
def GeoMovePoints():
    # Utility function to show the dialog box
    # The script that will be using the dialog
    dialog = GeoMovePointsDialog();
    
    #Open the dialogue
    rc = dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)
    
    
    DistX = float(dialog.m_DistX_textbox.Text)
    #print TolDX
    
    DistY = float(dialog.m_DistY_textbox.Text)
    #print TolDY
    
    DistZ = float(dialog.m_DistZ_textbox.Text)
    #print TolDZ
    
    
    def ClosestPointEx(brep, pt, TolR):
        info = brep.ClosestPoint(pt, TolR)
        return info[0], info[1], info[5]
        
    Parentlayers = []
    NLpoints =[]
    Npoints = []
    
    
    Lobjs = []
    Sobjs = []
    Pobjs = []
    Gobjs = []
    
    dsurfIds = []
    Cids = []
    gName = []
    groupN = []
    cpoints = []
    Players = []
    Root = []
    objectIds =[]
    NCids = []
    NPids = []

    
    translation = [float(dialog.m_DistX_textbox.Text),float(dialog.m_DistY_textbox.Text),float(dialog.m_DistZ_textbox.Text)]
    #sxform = rs.XformTranslation([0,0,0])
    xform = rs.XformTranslation([float(dialog.m_DistX_textbox.Text),float(dialog.m_DistY_textbox.Text),float(dialog.m_DistZ_textbox.Text)])
    
    
    
    Players = rs.GetLayers("Select Point Layers")
    if not Players: Rhino.Commands.Result.Cancel
    
    
    if Players:
    #count = sc.doc.Layers.Count
        for Player in Players:
            
            
            #oldname = Player + " - Copy"
            #Player + " - Copy"
            newname = str(Player) + " - Copy " + str(translation)
            #newLayer = rs.RenameLayer(oldname, newname)
            #rs.LayerColor(newname, (0,0,0))
            rs.AddLayer(newname)
            rs.LayerColor(newname, (0,0,0))
            
            Lobjs = rs.ObjectsByLayer(Player, True)
            CLobjs = rs.CopyObjects( Lobjs, translation=None)

            
            
            for clobj in CLobjs:
                if rs.ObjectType(clobj) == 8:
                    Sobjs.append(clobj)
                    rs.ObjectLayer(clobj, str(newname))
                    rs.SetUserText(clobj,"New Layer",str(newname))

                elif rs.ObjectType(clobj) == 1:
                    Pobjs.append(clobj)
                    rs.ObjectLayer(clobj, str(newname))
                    
                    
                    
            print("sobjs =",len(Sobjs))
            print( "pobjs =",len(Pobjs))
            
            
            #rs.TransformObjects( Sobjs, sxform, copy=True )
        rs.TransformObjects( Pobjs, xform, copy=False )
            
       

        
        rs.EnableRedraw(True) 
        print( "End of Move Points Vector Routine")
    
        # Check to see if this file is being executed as the "main" python
        # script instead of being used as a module by some other python script
        # This allows us to use the module which ever way we want.
        
if __name__ == "__main__":
    
    rc =  GeoMovePoints()

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 8620

Trending Articles