Exemple #1
0
        static public void SetBrushSettings(double diameter, double hardness, int flow, double opacity)
        {
            if (!IsActive())
            {
                return;
            }

            for (int i = 0; i < 1; i++)
            {
                try
                {
                    var currentToolOptions = AppDescriptor.GetObjectValue(App.StringIDToTypeID("currentToolOptions"));
                    var currentTool        = AppDescriptor.GetEnumerationType(App.StringIDToTypeID("tool"));
                    var currentBrush       = currentToolOptions.GetObjectValue(App.StringIDToTypeID("brush"));

                    var toolRef = new ActionReference();
                    toolRef.PutClass(currentTool);

                    if (currentBrush.HasKey(App.StringIDToTypeID("diameter")) && diameter != -1)
                    {
                        currentBrush.PutDouble(App.StringIDToTypeID("diameter"), diameter);
                    }

                    if (currentBrush.HasKey(App.StringIDToTypeID("hardness")) && hardness != -1)
                    {
                        currentBrush.PutDouble(App.StringIDToTypeID("hardness"), hardness);
                    }

                    if (currentToolOptions.HasKey(App.StringIDToTypeID("flow")) && flow != -1)
                    {
                        currentToolOptions.PutInteger(App.StringIDToTypeID("flow"), flow);
                    }

                    if (currentToolOptions.HasKey(App.StringIDToTypeID("opacity")) && opacity != -1)
                    {
                        currentToolOptions.PutDouble(App.StringIDToTypeID("opacity"), opacity);
                    }

                    currentToolOptions.PutObject(App.StringIDToTypeID("brush"), App.StringIDToTypeID("null"), currentBrush);

                    var setBrush = new ActionDescriptor();
                    setBrush.PutReference(App.StringIDToTypeID("null"), toolRef);
                    setBrush.PutObject(App.StringIDToTypeID("to"), App.StringIDToTypeID("null"), currentToolOptions);

                    App.ExecuteAction(App.StringIDToTypeID("set"), setBrush, PsDialogModes.psDisplayNoDialogs);

                    return;
                }
                catch (COMException ex)
                {
                    switch ((PhotoshopExceptionResult)ex.ErrorCode)
                    {
                    case PhotoshopExceptionResult.RPCERR:
                        Trace.WriteLine("Photoshop handle is outdated.");
                        Trace.WriteLine(ex.ErrorCode);
                        Trace.WriteLine(ex.Message);

                        break;

                    case PhotoshopExceptionResult.NOTAVAIL:
                        Trace.WriteLine("Tool does not have brush settings.");
                        break;
                    }
                }
            }
        }