Proper way to convert ghpy method compiling to Rhino 8 method

Hi I have series components created using Rhino 7 and the method below compiling the python codes to ghpy. Seems like now Rhino 8 have Rhino Script Editor and all-Rhino Python compiler what is the proper process of converting what I created using the old ghpy compiling method? I tried doing some digging but couldn’t find anything specific that outlines the process.

Closest one I was able to locate was this below. But I’m still a little confused on how I can take what was written in pythonSDK mode and properly convert it to the new method.

Obviously this is just stripped dumb version but previous generated source codes before compiling looks in the somewhat like this. Any insights or guidelines how I might approach this is greatly appreciated.


@piac Sorry I’m also tagging you into this as the original guide I followed is written by you and hoping you can help…

@User_aaa

You’d need to convert your GHPython script components into the new IronPython 2 component for it to be recognized in the Script Editor project. It doesn’t matter if they are SDK-mode or plain scripts.

Let me know if you have specific questions on the process and I can help

Hi thank you for your response. So far things have been working pretty well but I had couple question as I’m slowly converting them to the Rhino 8 IronPython 2 component which I’m hoping you have answer to

  1. Previously I had a unique guid set for each of the component when using the GHPY compiling method and it was through that I was able to make updates to the component. Is that something possible via this method? or how would I update the component so that any updates will be applied to files using those components?
  2. Maybe this might be tied to the above. In the script editor, how do I refresh the reference source file without needing to reimport the file? Especially if I’m setting icons, descriptions, subcategory in the script editor, it’d be great if I can refresh the reference file without needing to delete and re-add in the file which would eliminate the step of needed to re-enter those information.
  3. How would I repath a reference file if the source folder got re-named, file got moved etc. Currently if I were to move the file to a different location it will give me a warning, which makes sense as the reference is gone.
  4. This may be not directly related to the conversion from ghpy to scriptEditor question but I was also referencing your video of using the script editor(really helpful btw. thank you for putting it together) how would I put description, assign nicknames to inputs created through contextual inputs and context print.

Thank you very much for your help in advance. I really appreciate it!

@eirannejad Do you have any insights by any chance? Any info is greatly appreciated!

@eirannejad
One additional question as I play around with the script editor which I’m hoping you have answer to.

I had couple code that inherited the original component methods and modified it which was working fine in the old compiling method but seems to have issue rendering using the new script editor method. Do you know why this might be happening? Below is one example where it inherits and creates a physical button but seems like this does not work anymore with the R8 script edidtor

from ghpythonlib.componentbase import executingcomponent as component
import Grasshopper, GhPython
import System

class Button_UI(Grasshopper.Kernel.Attributes.GH_ComponentAttributes): # inherits all methods of GH_ComponentAttributes
    def __init__(self, owner):
        super(Button_UI, self).__init__(owner)
        self.component = owner
        self.button_down = False
                
    def Layout(self): # override inherited method Layout
        Grasshopper.Kernel.Attributes.GH_ComponentAttributes.Layout(self)
        component_rect = Grasshopper.Kernel.GH_Convert.ToRectangle(self.Bounds) 
        component_rect.Height += 22
        self.button_rect = System.Drawing.Rectangle(component_rect.X, component_rect.Bottom-22, component_rect.Width, 22)
        self.button_rect.Inflate(-2, -2)
        Bounds = component_rect
        self.Bounds=Bounds
        ButtonBounds = self.button_rect
        self.ButtonBounds=ButtonBounds
            
    def Render(self,canvas, graphics, channel): # Override Render method
        Grasshopper.Kernel.Attributes.GH_ComponentAttributes.Render(self, canvas, graphics, channel)
        if channel == Grasshopper.GUI.Canvas.GH_CanvasChannel.Objects:
            color = Grasshopper.GUI.Canvas.GH_Palette.Grey if self.button_down else Grasshopper.GUI.Canvas.GH_Palette.Black
            button = Grasshopper.GUI.Canvas.GH_Capsule.CreateTextCapsule(self.ButtonBounds, self.ButtonBounds, color, "Button", 2, 0)
            button.Render(graphics, self.Selected, self.Owner.Locked, False)
            button.Dispose()
            
    def RespondToMouseDown(self,sender,e):
        if e.Button == System.Windows.Forms.MouseButtons.Left:
            rec = self.button_rect
            pt = System.Drawing.Point.Round(e.CanvasLocation)
            if not self.button_down:
                if pt.X > rec.X and pt.X < rec.X+rec.Width and pt.Y > rec.Y and pt.Y < rec.Y+rec.Height:
                    self.button_down = True
                    self.component.OnDisplayExpired(False)
                    return  Grasshopper.GUI.Canvas.GH_ObjectResponse.Capture
        return super(Button_UI, self).RespondToMouseDown(sender, e)
        
    def RespondToMouseUp(self,sender,e):
        if e.Button == System.Windows.Forms.MouseButtons.Left:
            if self.button_down:
                self.button_down = False
                self.component.OnDisplayExpired(False)
                rec = self.button_rect
                pt = System.Drawing.Point.Round(e.CanvasLocation)
                if pt.X > rec.X and pt.X < rec.X+rec.Width and pt.Y > rec.Y and pt.Y < rec.Y+rec.Height:
                    self.component.click_response()
            return  Grasshopper.GUI.Canvas.GH_ObjectResponse.Release
        return super(Button_UI, self).RespondToMouseUp(sender, e)
        
class MyComponent(component):
    def __init__(self):
        self.click_count = 0
    
    def CreateAttributes(self): # Override inherited method create attributes
        self.m_attributes=Button_UI(self) 
            
    def RunScript(self, x, y):
        return self.click_count
        
    def click_response(self):
        self.click_count += 1
        self.ExpireSolution(True)

In R7 the inherit and override after compiling seems to work

But in R8 the override does not take effect

I’m I missing something here? Than you in advance again!

@eirannejad Hi sorry to bug again but do you have insights into any of the above? I’ll be great if I can resolve the above mentioned issues as it’s pretty critical for my workflow. Thank you in advance