/// <summary> /// Create color legend on view with the specific color fill scheme /// </summary> /// <param name="scheme"></param> /// <param name="view"></param> public void CreateAndPlaceLegend(ColorFillScheme scheme, Autodesk.Revit.DB.View view) { using (Transaction transaction = new Transaction(document)) { transaction.Start("Create legend"); var origin = view.Origin.Add(view.UpDirection.Multiply(20)); if (view.CanApplyColorFillScheme(schemeCategoryId, scheme.Id)) { view.SetColorFillSchemeId(schemeCategoryId, scheme.Id); var legend = ColorFillLegend.Create(document, view.Id, schemeCategoryId, origin); legend.Height = legend.Height / 2; transaction.Commit(); } else { throw new Exception("The scheme can not be applied on the view."); } } }