Rhino c# problem - visual studio

Hello,

I’m new to c# and I’ve been following a long tutorial and I’ve hit a bit of a dead end. I can’t figure out why my script isn’t colouring the blocks correctly. The ObjectAttributes and ObjectColorSource aren’t appearing correctly in Visual Studio - what am I missing?

System.Drawing.Color bldCol = System.Drawing.Color.White;

            if (actBuildingHeight < 6)
                bldCol = System.Drawing.Color.FromArgb(168, 126, 198);
            else if (actBuildingHeight < 12)
                bldCol = System.Drawing.Color.FromArgb(255, 173, 194);
            else if (actBuildingHeight < 36)
                bldCol = System.Drawing.Color.FromArgb(243, 104, 75);
            else if (actBuildingHeight < 92)
                bldCol = System.Drawing.Color.FromArgb(225, 164, 24);
            else if (actBuildingHeight > 92)
                bldCol = System.Drawing.Color.FromArgb(254, 255, 51);

            
            **ObjectAttributes** oa = new **ObjectAttributes**();
            oa.ColorSource = **ObjectColorSource**.ColorFromObject;
            oa.ObjectColor = bldCol;

            Curve border = Curve.JoinCurves(this.plotSrf.DuplicateNakedEdgeCurves(true, false))[0];

            this.buildingOutline = Curve.JoinCurves(border.Offset(Plane.WorldXY, -4, RhinoDoc.ActiveDoc.ModelAbsoluteTolerance, CurveOffsetCornerStyle.None))[0]; //dimension for building offset from plot border is list as 2                   

            this.building = Extrusion.Create(this.buildingOutline, actBuildingHeight, true);

            RhinoDoc.ActiveDoc.Objects.AddCurve(buildingOutline);
            RhinoDoc.ActiveDoc.Objects.AddExtrusion(this.building);

Thanks,
Iain

Hi @iain.mcquin

Hum… your ObjectAttributes is in the Rhino.DocObjects namespace which you should have referenced correctly if you are not having issues with the rest of that class. I assume you’re referencing RhinoCommon.dll from your rhino 5 or rhino 6 folder? You could try to access ObjectAttributes more directly by typing out the full path such as Rhino.DocObjects.ObjectAttributes oa = new Rhino.DocObjects.ObjectAttributes();

After thats up and referencing properly you can just tack them onto the end when adding them to the doc.

RhinoDoc.ActiveDoc.Objects.AddCurve(buildingOutline,oa);
RhinoDoc.ActiveDoc.Objects.AddExtrusion(this.building,oa);

Also, if you happen to be editing an existing RhinoObject and want to change the object attributes you need to call CommitChanges() after setting the new object attributes. That part is not always obvious but needs to happen.

Hopefully that helps.

1 Like

Hello, this has seemed to remove all the errors from the scriptand highlighted the ObjectAttributes and ColorFromSource correctly - much thanks.