Why does the component change the appearance?

unhandled

(Andrealu2012) #1

I have a custom component written by c# like this:

i just want to double the component and show a window
but when i write the double click & add window code,the result is this:
%E5%9B%BE%E7%89%87
the component is totally has nothing! but good thing is :when i double click it ,window shows:joy:
Who can help me to explain this…Thank you!
code is:


(David Rutten) #2

You mean the message string on the component shows only zeroes?

If so, you just need to assign a new message to the component, and make sure the attributes are expired after you do so.


(Andrealu2012) #3

no…the whole big component with 5 input(P,E1~E5) suddenly change into a green small component. without input…as the picture,but the small green component canbe double click to show a window…


(David Rutten) #4

Then you must be replacing the attributes of your component after it already has attributes. Plus your attributes class doesn’t inherit from Grasshopper.Kernel.Attributes.GH_ComponentAttributes, so it wouldn’t look like a component.

You should only ever assign attributes once, from within an overridden CreateAttributes() method. Here you can assign a new instance of your custom attributes to the m_attributes field of the component.


(Andrealu2012) #5


David,i have the code of m_attributes…may be should it upload the code…

public class FromPlToMovLinKRLAttributes:GH_Attributes<FromPlToMovLinKRL>
{
    public FromPlToMovLinKRLAttributes(FromPlToMovLinKRL owner) : base(owner) {}

    public override Grasshopper.GUI.Canvas.GH_ObjectResponse RespondToMouseDoubleClick(Grasshopper.GUI.Canvas.GH_Canvas sender,Grasshopper.GUI.GH_CanvasMouseEvent e)
    {
        FormGetKRLDoc f1 = new FormGetKRLDoc();
        Grasshopper.GUI.GH_WindowsFormUtil.CenterFormOnCursor(f1, true);
        f1.ShowDialog();

        Owner.ExpireSolution(true);

        return Grasshopper.GUI.Canvas.GH_ObjectResponse.Handled;

    }
    //public override void ExpireLayout()
    //{
    //    base.ExpireLayout();
    //}
}

public class FromPlToMovLinKRL : GH_Component
{

    public override void CreateAttributes()
    {
        m_attributes = new FromPlToMovLinKRLAttributes(this);

    }

(David Rutten) #6

At the very least this:

public class FromPlToMovLinKRLAttributes:GH_Attributes<FromPlToMovLinKRL>

should be:

public class FromPlToMovLinKRLAttributes:GH_ComponentAttributes<FromPlToMovLinKRL>

But I find it very suspicious. Someone is assigning standard GH_ComponentAttributes to your component, otherwise it would not look correct at first. I understand why your component looks like a blue/green box, but typically the only way Grasshopper assigns attributes to objects is by calling the CreateAttributes method, which in your case should always result in your blue/green box.

I’m digging through the entire code-base now, trying to find a way in which different attributes might be assigned by some object other than the component. It will take a while.


(David Rutten) #8

I’m not seeing what could be going wrong. Can you create an attribute/component pair of classes that do not require any of the assembly references yet still show the problem? I’ll need to debug this here and I don’t have access to all that KUKA stuff.


(Andrealu2012) #9

David,i try your method change into componentAttribute,it works!Thank you very much!
I think the attribute is very difficult, so as to I cannot know how to raise a question…:joy:
I need to learning more and more about API and C#.Thank you again David!


(David Rutten) #10

Yeah but there’s still the underlying problem that the wrong kind of attributes are assigned initially. It may work now, but it just masks the underlying problem. Still, maybe it’s a rare and unimportant issue…


(Andrealu2012) #11

David,i am not very understand you,but seems it very very difficult …
i have another question:
i try:


failed…
then i change it into:

:GH_ComponentAttributes

it works......

(David Rutten) #12

yeah my bad, I remembered GH_ComponentAttributes to be a generic class, but it abstracts the generics of the underlying GH_Attributes by just using GH_Component all the time.