GHpython/Color the vector

Hello
I color the vector but even if I change the parameter, the vector display will keep.
What is the cause of this?

Thanks
Cusutom Display.gh (6.6 KB)

Dear Reo,

This can be fixed by checking if your display object is in ‘globals()’ already:

if "my_display" not in globals():
        my_display = rd.CustomDisplay(True)

please see file attached Cusutom Display.gh (12.7 KB)

1 Like

Hi David
Thank you very much!!

Hello @DavidLeon
i have the same problem; with python it work fine but if i convert it to component the problem happen again

from ghpythonlib.componentbase import executingcomponent as component
import Grasshopper, GhPython
import System
import Rhino as rh
import rhinoscriptsyntax as rs
import ghpythonlib.components as gh
import scriptcontext
import Rhino.Display as rd

class MyComponent(component):
    
    def RunScript(self, C):
        if "my_display" not in globals():
            
              my_display = rd.CustomDisplay(True)
        
        my_display.Clear()
        
        if C:
            c = rs.coercecurve(C)
            i = rh.Geometry.Interval(0,1)
            rh.Geometry.Curve.Domain.SetValue(C,i)
            d = rs.CurveDomain(C)
            lnt = (rs.CurveLength(C))/6
        
            drct = []
            pnts = []
            for i in range(3):
                n = i * 0.5
                pl = rs.CurveFrame(C,n)
                x_axis = pl.XAxis
                pt = rs.EvaluateCurve(C,n)
                drct.append(x_axis)
                pnts.append(pt)
                
            V = drct
            P = pnts
            clr = rh.Display.ColorXYZ(255,255,255)

            for i in range(len(V)):
                my_display.AddVector(P[i], V[i],clr)

        else:
           V = None

        return

@seghierkhaled for compiled components, I suggest you try overriding the DrawViewportWires method of the component class. Here’s an example:

1 Like

Thank you very much your script help me; i will try the compiled component

1 Like

The generated image, even if the parameters (point position) are changed, the original image cannot be cleared.