Parameter container does not land where awaited on the canvas


for some reason, when I do that (in BeforeSolveInstance):

_doc = OnPingDocument();
var test = new Param_Curve();
_doc.AddObject(test, false);
test.Attributes.Pivot = new PointF(100, 150);

the container lands on the origin of the canvas (top/left).


It does contain though its correct cooordinates as it goes straight to its place, when I add something else onto the canvas, so when the canvas gets somehow refreshed. But why should be a refresh needed? And can I do it programmaticaly?

For ComboBoxes (GH_ValueList) or Scribbles (GH_Scribble) it works as expected, looks like this behavior is specific to the GH_PersistentGeometryParam objects. Am I right? Why is it so?



well it seem like you’re adding the element before setting the pivot.

not sure if I tell some really stupid thing, but I remember having something like this to keep the element in place:

//Our object is always the same size, but it needs to be anchored to the pivot.
        protected override void Layout()
            //Lock this object to the pixel grid. 
            //I.e., do not allow it to be position in between pixels.
            Pivot = GH_Convert.ToPoint(Pivot);
            Bounds = new RectangleF(Pivot, new SizeF((float)(ButtonSize * 2.5), ButtonSize));
        /// <summary>
        /// This method returns the button at the given column and row offsets.
        /// </summary>
        private RectangleF TextBound()
            int x = Convert.ToInt32(Pivot.X);
            int y = Convert.ToInt32(Pivot.Y);
            return new RectangleF(new PointF(x + 27, y), new SizeF(55, ButtonSize));
        private Rectangle Button()
            int x = Convert.ToInt32(Pivot.X);
            int y = Convert.ToInt32(Pivot.Y);
            return new Rectangle(x + 4 , y + 4, ButtonSize - 8, ButtonSize - 8);

we had made some experience in this post, it MIGHT be helpful:

Hello Ben, thank you for the answer.
yes I did try to set the pivot first and then add the element to the doc, but I then get a NullReferenceException: the Attributes property of the IGH_Param is first initialised, when the IGH_Param is added to the document.

I did not find something in relation to that topic in your link by the way… Not sure what you meant there.

So I still don t know why the Param_Curve (or any container type) lands at (0;0) allthough its pivot shows somewhere else but saw that if you set its source, its position on the canvas gets somehow updated (?!).
So I worked around my problem adding the container a dummy source which I then delete. Not elegant but it works…

Call test.Attributes.ExpireLayout(); after update its pivot.

Much better! That was the missing thing, thanks!