Exemple #1
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;
        }
Exemple #2
0
        /// <summary>
        /// Cleans the name of the layers.
        /// </summary>
        /// <param name="_layers">layers</param>
        /// <param name="__idx">Depth Index</param>
        /// <returns></returns>
        private string cleanLayersName(object _layers, int __idx)
        {
            string returnValue;
            Photoshop.Layers __layers = null;
            object __layer;
            Photoshop.LayerSet __slayer;
            Photoshop.ArtLayer __alayer = null;
            bool __isVisible;
            int __j;
            ImageRight __ir;
            bool __isArtLayer = false;

            string __xmlDoc;
            string __FistLayerText = "";

            Regex __reg = new Regex("Group\\s*\\d*", RegexOptions.IgnoreCase);

            __ir = new ImageRight();

            //MessageBox.Show(_layers.GetType().ToString());
            __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
                {
                    __isVisible = __alayer.Visible;
                    __appRef.ActiveDocument.ActiveLayer = __layer;

                    __ir.parse(__alayer.Name);
                    if (__ir.isValidCode)
                    {
                        __alayer.Name = "#" + Regex.Replace(__alayer.Name, "#", "");
                    }
                    if (__alayer.Kind == Photoshop.PsLayerKind.psSmartObjectLayer) //SMARTOBJECT
                    {
                        try
                        {
                            __xmlDoc = __appRef.ActiveDocument.XMPMetadata.RawData;
                            if (__xmlDoc != "")
                            {
                                __alayer.Name = new string(Convert.ToChar("+"), __idx) + " " + Regex.Replace(__alayer.Name, "(\\+)+\\s*", "");
                                ChangeLayerColour(Colors.VIOLET);
                            }
                        }
                        catch
                        {
                        }
                    }
                    else if (__alayer.Kind == Photoshop.PsLayerKind.psTextLayer)
                    {
                        if (__FistLayerText == "")
                        {
                            __FistLayerText = __alayer.Name;
                        }
                    }

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

                    if (__slayer.LayerType == Photoshop.PsLayerType.psLayerSet)
                    {
                        __slayer.Name = new string(Convert.ToChar("+"), __idx) + " " + Regex.Replace(__slayer.Name, "(\\+)+\\s*", "");
                        //MessageBox.Show(__slayer.Name);
                        string __NewLayerName = cleanLayersName(__slayer.Layers, __idx + 1);
                        if (__NewLayerName != "" && __reg.IsMatch(__slayer.Name))
                        {
                            __slayer.Name = new string(Convert.ToChar("+"), __idx) + " " + __NewLayerName;
                        }
                    }

                    __slayer.Visible = __isVisible;
                }
            }
            returnValue = __FistLayerText;
            return returnValue;
        }