Ejemplo n.º 1
0
 static private void GetSolidFillColor()
 {
     Photoshop.ActionReference reference = new Photoshop.ActionReference();
     reference.PutEnumerated(PhotoshopApplication.StringIDToTypeID("contentLayer"), PhotoshopApplication.CharIDToTypeID("Ordn"), PhotoshopApplication.CharIDToTypeID("Trgt"));
     Photoshop.ActionDescriptor descriptor      = PhotoshopApplication.ExecuteActionGet(reference);
     Photoshop.ActionList       actionList      = descriptor.GetList(PhotoshopApplication.CharIDToTypeID("Adjs"));
     Photoshop.ActionDescriptor solidColorLayer = actionList.GetObjectValue(0);
     Photoshop.ActionDescriptor color           = solidColorLayer.GetObjectValue(PhotoshopApplication.CharIDToTypeID("Clr "));
     double red   = color.GetDouble(PhotoshopApplication.CharIDToTypeID("Rd  "));
     double green = color.GetDouble(PhotoshopApplication.CharIDToTypeID("Grn "));
     double blue  = color.GetDouble(PhotoshopApplication.CharIDToTypeID("Bl  "));
 }
Ejemplo n.º 2
0
 static private void UpdateSolidFillColor(Color color)
 {
     Photoshop.ActionDescriptor descriptor = new Photoshop.ActionDescriptor();
     Photoshop.ActionReference  reference  = new Photoshop.ActionReference();
     reference.PutEnumerated(PhotoshopApplication.StringIDToTypeID("contentLayer"), PhotoshopApplication.CharIDToTypeID("Ordn"), PhotoshopApplication.CharIDToTypeID("Trgt"));
     descriptor.PutReference(PhotoshopApplication.CharIDToTypeID("null"), reference);
     Photoshop.ActionDescriptor fillDescriptor  = new Photoshop.ActionDescriptor();
     Photoshop.ActionDescriptor colorDescriptor = new Photoshop.ActionDescriptor();
     colorDescriptor.PutDouble(PhotoshopApplication.CharIDToTypeID("Rd  "), color.R);
     colorDescriptor.PutDouble(PhotoshopApplication.CharIDToTypeID("Grn "), color.G);
     colorDescriptor.PutDouble(PhotoshopApplication.CharIDToTypeID("Bl  "), color.B);
     fillDescriptor.PutObject(PhotoshopApplication.CharIDToTypeID("Clr "), PhotoshopApplication.CharIDToTypeID("RGBC"), colorDescriptor);
     descriptor.PutObject(PhotoshopApplication.CharIDToTypeID("T   "), PhotoshopApplication.StringIDToTypeID("solidColorLayer"), fillDescriptor);
     PhotoshopApplication.ExecuteAction(PhotoshopApplication.CharIDToTypeID("setd"), descriptor);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Exports the smart objects.
        /// </summary>
        /// <param name="__docRef">Document refrence</param>
        /// <param name="_layers">Layers</param>
        /// <returns></returns>
        private bool exportSmartObjects(Photoshop.Document __docRef, object _layers)
        {
            Photoshop.Layers __layers;
            Photoshop.ArtLayer __alayer = null;
            Photoshop.LayerSet __slayer;
            bool __isArtLayer = false;
            object __layer;
            int __j;
            string __soType;

            __layers = (Photoshop.Layers)_layers;

            for (__j = 1; __j <= __layers.Count; __j++)
            {
                __layer = __layers[__j];

                try
                {
                    __alayer = (Photoshop.ArtLayer)__layer;
                    __isArtLayer = true;
                }
                catch
                {
                    __isArtLayer = false;
                }

                if (__isArtLayer) // Everything as Layer goes here
                {
                    __appRef.ActiveDocument.ActiveLayer = __layer;

                    if (__alayer.Kind == Photoshop.PsLayerKind.psSmartObjectLayer)
                    {

                        int __idplacedLayerExportContents;
                        __idplacedLayerExportContents = __appRef.StringIDToTypeID("placedLayerExportContents");

                        Photoshop.ActionDescriptor __desc4;
                        __desc4 = new Photoshop.ActionDescriptor();

                        int __idnull;
                        __idnull = __appRef.CharIDToTypeID("null");

                        if (!Directory.Exists(__docRef.Path + "+ SmartObjects\\"))
                        {
                            Directory.CreateDirectory(__docRef.Path + "+ SmartObjects\\");
                        }

                        __soType = getSmartObjectType(__appRef);
                        if (__soType != "")
                        {
                            __desc4.PutPath(__idnull, __docRef.Path + "+ SmartObjects\\" + wipeName(__alayer.Name) + __soType);
                            __appRef.ExecuteAction(__idplacedLayerExportContents, __desc4, Photoshop.PsDialogModes.psDisplayNoDialogs);
                        }
                    }
                }
                else // Everything as LayerSet goes here
                {
                    __slayer = (Photoshop.LayerSet)__layer;
                    __appRef.ActiveDocument.ActiveLayer = __layer;

                    if (__slayer.LayerType == Photoshop.PsLayerType.psLayerSet)
                    {
                        bool __test = exportSmartObjects(__docRef, __slayer.Layers);
                    }
                }
            }
            return true;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Exports the images rights.
        /// </summary>
        /// <param name="__docRef">Document</param>
        /// <param name="_layers">Layers</param>
        /// <returns></returns>
        private bool exportImagesRights(Photoshop.Document __docRef, object _layers)
        {
            Photoshop.Layers __layers;
            Photoshop.ArtLayer __alayer = null;
            Photoshop.LayerSet __slayer;
            bool __isArtLayer = false;
            object __layer;
            int __j;
            string __soType;
            ImageRight __ir;

            __ir = new ImageRight();

            __layers = (Photoshop.Layers)_layers;

            for (__j = 1; __j <= __layers.Count; __j++)
            {
                __layer = __layers[__j];

                try
                {
                    __alayer = (Photoshop.ArtLayer)__layer;
                    __isArtLayer = true;
                }
                catch
                {
                    __isArtLayer = false;
                }

                if (__isArtLayer) // Everything as Layer goes here
                {
                    __appRef.ActiveDocument.ActiveLayer = __layer;

                    if (__alayer.Kind == Photoshop.PsLayerKind.psNormalLayer)
                    {
                        __ir.parse(__alayer.Name);
                        if (__ir.isValidURL)
                        {
                            __ir.createLink(__docRef.Path);
                        }
                    }
                    else if (__alayer.Kind == Photoshop.PsLayerKind.psSmartObjectLayer)
                    {
                        __ir.parse(__alayer.Name);
                        if (__ir.Code != null)
                        {
                            if (__ir.isValidURL)
                            {
                                __ir.createLink(__docRef.Path);
                            }
                        }
                        else
                        {
                            __soType = getSmartObjectType(__appRef);
                            if (__soType == ".psd")
                            {

                                int __opn;
                                __opn = __appRef.StringIDToTypeID("placedLayerEditContents");

                                Photoshop.ActionDescriptor __desc4;
                                __desc4 = new Photoshop.ActionDescriptor();

                                try
                                {
                                    __appRef.ExecuteAction(__opn, __desc4, Photoshop.PsDialogModes.psDisplayNoDialogs);
                                }
                                catch (InvalidOperationException ex)
                                {
                                    MessageBox.Show(ex.Message);
                                }
                                bool __test = exportImagesRights(__docRef, __appRef.ActiveDocument.Layers);
                                __appRef.ActiveDocument.Close(2);
                            }
                        }
                    }

                }
                else // Everything as LayerSet goes here
                {
                    __slayer = (Photoshop.LayerSet)__layer;
                    __appRef.ActiveDocument.ActiveLayer = __layer;

                    if (__slayer.LayerType == Photoshop.PsLayerType.psLayerSet)
                    {
                        bool __test = exportImagesRights(__docRef, __slayer.Layers);
                    }
                }
            }
            return true;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Deselects the layers.
        /// </summary>
        private void deselectLayers()
        {
            Photoshop.ActionDescriptor __desc = new Photoshop.ActionDescriptor();
            Photoshop.ActionReference __ref = new Photoshop.ActionReference();

            __ref.PutEnumerated(__appRef.CharIDToTypeID("Lyr "), __appRef.CharIDToTypeID("Ordn"), __appRef.CharIDToTypeID("Trgt"));
            __desc.PutReference(__appRef.CharIDToTypeID("null"), __ref);
            __appRef.ExecuteAction(__appRef.StringIDToTypeID("selectNoLayers"), __desc, Photoshop.PsDialogModes.psDisplayNoDialogs);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Deselects the layer.
        /// </summary>
        /// <param name="__name">Name</param>
        private void deselectLayer(string __name)
        {
            Photoshop.ActionDescriptor __desc = new Photoshop.ActionDescriptor();
            Photoshop.ActionReference __ref = new Photoshop.ActionReference();

            __ref.PutName(__appRef.CharIDToTypeID("Lyr "), __name);
            __desc.PutReference(__appRef.CharIDToTypeID("null"), __ref);
            __desc.PutEnumerated(__appRef.StringIDToTypeID("selectionModifier"), __appRef.StringIDToTypeID("selectionModifierType"), __appRef.StringIDToTypeID("removeFromSelection"));
            __desc.PutBoolean(__appRef.CharIDToTypeID("MkVs"), false);
            __appRef.ExecuteAction(__appRef.CharIDToTypeID("slct"), __desc, Photoshop.PsDialogModes.psDisplayNoDialogs);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Changes the layer colour.
        /// </summary>
        /// <param name="__col">Color</param>
        private void ChangeLayerColour(Colors __col)
        {
            string __colour;
            Photoshop.ActionDescriptor __desc;
            Photoshop.ActionReference __ref;
            Photoshop.ActionDescriptor __desc2;

            switch (__col)
            {
                case Colors.RED:
                    __colour = "Rd  ";
                    break;
                case Colors.ORANGE:
                    __colour = "Orng";
                    break;
                case Colors.YELLOW:
                    __colour = "Ylw ";
                    break;
                case Colors.GREEN:
                    __colour = "Grn ";
                    break;
                case Colors.BLUE:
                    __colour = "Bl  ";
                    break;
                case Colors.VIOLET:
                    __colour = "Vlt ";
                    break;
                case Colors.GRAY:
                    __colour = "Gry ";
                    break;
                case Colors.NONE:
                    __colour = "None";
                    break;
                default:
                    __colour = "None";
                    break;
            }

            __desc = new Photoshop.ActionDescriptor();
            __ref = new Photoshop.ActionReference();
            __ref.PutEnumerated(__appRef.CharIDToTypeID("Lyr "), __appRef.CharIDToTypeID("Ordn"), __appRef.CharIDToTypeID("Trgt"));
            __desc.PutReference(__appRef.CharIDToTypeID("null"), __ref);

            __desc2 = new Photoshop.ActionDescriptor();
            __desc2.PutEnumerated(__appRef.CharIDToTypeID("Clr "), __appRef.CharIDToTypeID("Clr "), __appRef.CharIDToTypeID(__colour));
            __desc.PutObject(__appRef.CharIDToTypeID("T   "), __appRef.CharIDToTypeID("Lyr "), __desc2);
            __appRef.ExecuteAction(__appRef.CharIDToTypeID("setd"), __desc, Photoshop.PsDialogModes.psDisplayNoDialogs);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Saves the screen selection.
        /// </summary>
        /// <param name="__docRef">Document Refrence</param>
        /// <param name="__doc">Document</param>
        /// <param name="__idx">Layer Comp Index</param>
        /// <param name="__options">JPEG options</param>
        private void saveScreenSelection(Photoshop.Document __docRef, Photoshop.Document __doc, int __idx, Photoshop.JPEGSaveOptions __options)
        {
            Photoshop.Channel __selChannel;
            object __selBounds;
            string __fileNameBody;
            bool __hasSelection = false;
            Photoshop.ActionDescriptor __desc = new Photoshop.ActionDescriptor();
            Photoshop.ActionReference __ref = new Photoshop.ActionReference();
            Photoshop.ArtLayer __layer;
            int __j;

            try
            {
                __selChannel = getScreenSelectionChannel(__doc);
                __hasSelection = true;
                //MessageBox.Show(__selChannel.Name)
                __doc.Selection.Load(__selChannel, null, null);
                __selBounds = __doc.Selection.Bounds;
                __doc.Crop(__selBounds, null, null, null);
            }
            catch (Exception)
            {
                __hasSelection = false;

            }
            if (!__hasSelection)
            {
                /*try
                {

                    __ref.PutName(__appRef.CharIDToTypeID("Lyr "), "@screen");
                    __desc.PutReference(__appRef.CharIDToTypeID("null"), __ref);
                    __desc.PutEnumerated(__appRef.StringIDToTypeID("selectionModifier"), __appRef.StringIDToTypeID("selectionModifierType"), __appRef.StringIDToTypeID("removeFromSelection"));
                    __desc.PutBoolean(__appRef.CharIDToTypeID("MkVs"), true);
                    //__appRef.ExecuteAction(__appRef.CharIDToTypeID("slct"), __desc, Photoshop.PsDialogModes.psDisplayNoDialogs);
                    __desc = __appRef.ExecuteActionGet(__ref);

                    //__layer = (Photoshop.ArtLayer)__docRef.ActiveLayer;
                    //__selBounds = __layer.Bounds;
                    //__doc.Crop(__selBounds, null, null, null);
                    //__hasSelection = true;

                    string __res = __desc.GetString(__appRef.CharIDToTypeID("Nm  "));

                    if (__res == "@screen")
                    {
                        //int __index = __desc.GetInteger(__appRef.CharIDToTypeID("ItmI"));
                        MessageBox.Show(__desc.GetReference(__appRef.CharIDToTypeID("ItmI")).ToString());

                        //__docRef.ActiveLayer = __docRef.ArtLayers[__index];
                        //MessageBox.Show(__index.ToString());
                        //__layer = (Photoshop.ArtLayer)__doc.ArtLayers[__index];
                        //__selBounds = __layer.Bounds;
                        //__doc.Crop(__selBounds, null, null, null);
                        __hasSelection = true;
                    }
                    else
                    {
                        __hasSelection = false;
                    }
                }
                catch (Exception __e)
                {
                    MessageBox.Show(__e.Message);
                    __hasSelection = false;
                }
                */

                for (__j = 1; __j <= __docRef.Layers.Count; __j++)
                {
                    try
                    {
                        __layer = (Photoshop.ArtLayer)__docRef.Layers[__j];
                        //MessageBox.Show(__layer.Name);
                        if (__layer.Name == "@screen")
                        {
                            __selBounds = __layer.Bounds;
                            __doc.Crop(__selBounds, null, null, null);
                            __hasSelection = true;
                            break;
                        }
                    }
                    catch
                    {
                        __hasSelection = false;
                    }
                }
            }

            if (__hasSelection)
            {
                __fileNameBody = (__docRef.Name.LastIndexOf(".") > -1) ? __docRef.Name.Substring(0, __docRef.Name.LastIndexOf(".")) : __docRef.Name;
                __fileNameBody += (__idx <= -1) ? "_screen" : "." + __idx + "_screen";
                __fileNameBody += ".jpg";
                __doc.SaveAs(__docRef.Path + __fileNameBody, __options, true, null);
            }
            else
            {
                MessageBox.Show("You have to create a selection named \"screen\" or a layer named \"@screen\"", "No selection found", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                Application.Exit();
            }

            if (__idx > 0)
                __doc.Close(2);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Resizes the image.
        /// </summary>
        /// <param name="__width">Width</param>
        private void resizeImage(double __width)
        {
            Photoshop.ActionDescriptor __desc = new Photoshop.ActionDescriptor();

            __desc.PutUnitDouble(__appRef.CharIDToTypeID("Wdth"), __appRef.CharIDToTypeID("#Pxl"), __width);
            __desc.PutBoolean(__appRef.StringIDToTypeID("scaleStyles"), true);
            __desc.PutBoolean(__appRef.CharIDToTypeID("CnsP"), true);
            __desc.PutEnumerated(__appRef.CharIDToTypeID("Intr"), __appRef.CharIDToTypeID("Intp"), __appRef.CharIDToTypeID("Bcbc"));
            __appRef.ExecuteAction(__appRef.CharIDToTypeID("ImgS"), __desc, Photoshop.PsDialogModes.psDisplayNoDialogs);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Moves the layer.
        /// </summary>
        /// <param name="__name">Name</param>
        private void moveLayer(string __name)
        {
            Photoshop.ActionReference __ref = new Photoshop.ActionReference();
            Photoshop.ActionDescriptor __desc = new Photoshop.ActionDescriptor();
            __ref.PutProperty( __appRef.CharIDToTypeID("Prpr") , __appRef.CharIDToTypeID("NmbL"));
            __ref.PutEnumerated(__appRef.CharIDToTypeID("Dcmn"), __appRef.CharIDToTypeID("Ordn"), __appRef.CharIDToTypeID("Trgt"));
            int __nblayers = __appRef.ExecuteActionGet(__ref).GetInteger(__appRef.CharIDToTypeID("NmbL"));

            Photoshop.ActionDescriptor __desc1 = new Photoshop.ActionDescriptor();
            Photoshop.ActionReference __ref1 = new Photoshop.ActionReference();
            Photoshop.ActionReference __ref2 = new Photoshop.ActionReference();

            __ref1.PutEnumerated(__appRef.CharIDToTypeID("Lyr "), __appRef.CharIDToTypeID("Ordn"), __appRef.CharIDToTypeID("Trgt"));
            __desc1.PutReference(__appRef.CharIDToTypeID("null"), __ref1);

            __ref2.PutIndex(__appRef.CharIDToTypeID("Lyr "), __nblayers);
            __desc1.PutReference(__appRef.CharIDToTypeID("T   "), __ref2);

            __desc1.PutBoolean(__appRef.CharIDToTypeID("Adjs"), false);
            __desc1.PutInteger(__appRef.CharIDToTypeID("Vrsn"), 5);
            __appRef.ExecuteAction(__appRef.CharIDToTypeID("move"), __desc1, Photoshop.PsDialogModes.psDisplayNoDialogs);
        }
Ejemplo n.º 11
0
        private void listFonts(Photoshop.Document __docRef, string __filename, bool __messageWhenDone)
        {
            //MessageBox.Show(__filename);

            Photoshop.ActionReference __ref = new Photoshop.ActionReference();
            Photoshop.ActionDescriptor __desc = new Photoshop.ActionDescriptor();
            Regex __RegexObj = new Regex("^</Layer group");
            List<string> __fonts = new List<string>();

            __ref.PutEnumerated(__appRef.CharIDToTypeID("Dcmn"), __appRef.CharIDToTypeID("Ordn"), __appRef.CharIDToTypeID("Trgt") );
            int __count = __appRef.ExecuteActionGet(__ref).GetInteger(__appRef.CharIDToTypeID("NmbL")) + 1;
            //MessageBox.Show(__count.ToString());
            for(int i = 1; i < __count; i++)
            {
                __ref = new Photoshop.ActionReference();
                __ref.PutIndex( __appRef.CharIDToTypeID("Lyr "), i);
                __desc = __appRef.ExecuteActionGet(__ref);
                string __layerName = __desc.GetString(__appRef.CharIDToTypeID("Nm  "));
                string __layerType = __appRef.TypeIDToStringID(__desc.GetEnumerationValue( __appRef.StringIDToTypeID("layerSection")));

                if (__RegexObj.IsMatch(__layerName))
                    continue;

                if( __desc.HasKey(__appRef.StringIDToTypeID("textKey")))
                {
                    Photoshop.ActionDescriptor __list = __desc.GetObjectValue(__appRef.CharIDToTypeID("Txt "));
                    Photoshop.ActionList __tsr = __list.GetList(__appRef.CharIDToTypeID("Txtt"));
                    //MessageBox.Show(__tsr.Count.ToString());
                    for(var j = 0; j < __tsr.Count; j++)
                    {
                        //MessageBox.Show("ok");
                        Photoshop.ActionDescriptor __tsr0 = __tsr.GetObjectValue(j);
                        Photoshop.ActionDescriptor __textStyle = __tsr0.GetObjectValue(__appRef.CharIDToTypeID("TxtS"));
                        string __font = __textStyle.GetString(__appRef.CharIDToTypeID("FntN"));
                        string __style = __textStyle.GetString(__appRef.CharIDToTypeID("FntS"));
                        //MessageBox.Show(__font + "-" + __style);
                        if (!__fonts.Contains(__font + "-" + __style))
                            __fonts.Add(__font + "-" + __style);
                    }
                }
            }
            //MessageBox.Show(__fonts.Count.ToString());
            addFont(__docRef, __fonts, __filename, __messageWhenDone);
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Hides all layers.
 /// </summary>
 private void hideAllLayers()
 {
     Photoshop.ActionReference __ref = new Photoshop.ActionReference();
     __ref.PutEnumerated(__appRef.CharIDToTypeID("Lyr "), __appRef.CharIDToTypeID("Ordn"), __appRef.CharIDToTypeID("Trgt"));
     Photoshop.ActionList __list = new Photoshop.ActionList();
     __list.PutReference(__ref);
     Photoshop.ActionDescriptor __desc = new Photoshop.ActionDescriptor();
     __desc.PutList(__appRef.CharIDToTypeID("null"), __list);
     __appRef.ExecuteAction(__appRef.CharIDToTypeID("Hd  "), __desc, Photoshop.PsDialogModes.psDisplayNoDialogs);
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Determines whether [has screen selection] [the specified __doc].
        /// </summary>
        /// <param name="__doc">The __doc.</param>
        /// <returns>
        ///   <c>true</c> if [has screen selection] [the specified __doc]; otherwise, <c>false</c>.
        /// </returns>
        private bool hasScreenSelection(Photoshop.Document __doc)
        {
            bool __value;
            Photoshop.ActionDescriptor __desc = new Photoshop.ActionDescriptor();
            Photoshop.ActionReference __ref = new Photoshop.ActionReference();

            __value = (getScreenSelectionChannel(__doc) != null) ? true : false;

            /*try
            {
                __selChannel = __doc.Channels["screen"];
                __value = true;
            }
            catch (Exception)
            {
                __value = false;
            }*/

            if (!__value)
            {
                try
                {
                    __ref.PutName(__appRef.CharIDToTypeID("Lyr "), "@screen");
                    __desc.PutReference(__appRef.CharIDToTypeID("null"), __ref);
                    __desc.PutEnumerated(__appRef.StringIDToTypeID("selectionModifier"), __appRef.StringIDToTypeID("selectionModifierType"), __appRef.StringIDToTypeID("removeFromSelection"));
                    __desc.PutBoolean(__appRef.CharIDToTypeID("MkVs"), true);
                    __appRef.ExecuteAction(__appRef.CharIDToTypeID("slct"), __desc, Photoshop.PsDialogModes.psDisplayNoDialogs);
                    __value = true;
                }
                catch (Exception)
                {
                    __value = false;
                }
            }

            return __value;
        }