コード例 #1
0
    /// <summary>
    /// Change an object's color based on it's handle
    /// </summary>
    public static bool SetColor(Document document, string handle, int red, int green, int blue)
    {
        if (document == null)
        {
            return(false);
        }
        if (string.IsNullOrEmpty(handle))
        {
            return(false);
        }

        var db = document.AcDocument.Database;

        // And attempt to get an ObjectId for the Handle
        var id = DocumentContext.GetObjectId(db, handle);

        using (var ctx = new DocumentContext(document.AcDocument))
        {
            var selected = (Entity)ctx.GetTransaction().GetObject(id, OpenMode.ForWrite, false, true);
            selected.Color = Color.FromRgb((byte)red, (byte)green, (byte)blue);
        }

        return(true);
    }