Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to use PsDotNet automation components in QM
#1
I often use photoshop for image processing. I saw a PS automation component in a forum. It seems that I need to use C#, but I may need to install visual studio. It is too large. Can I use QM to run this automation component? I hope that developers can create an example and let more people use QM+PS automation components to work, thanks in advance.  Smile

Component download address( I have downloaded it, below):
http://psdotnet.com/downloads/

Component instructions

Note: PsDotNet is currently considered in a beta state. More information can be found at psdotnet.com or by emailing me at davidwright@psdotnet.com

1. INTRODUCTION
PsDotnet is a strongly typed .net library used to automate Adobe Photoshop. It currently supports CS3, CS4, CS5, CS6, CC, CC2014, CC2015, CC2017, and CC2018. 

2. KNOWN ISSUES
None

3. RELEASE INFO
This is a beta release. All of the features I wanted to get in for the initial release are in and tested as much as possible. If you encounter any issues let me know and I will fix it ASAP.

Release contents:
PsDotNet.dll
PsDotNet.pdb
readme.txt

4. USAGE
1) Add a reference to the PsDotNet.dll to your project. Make sure that it does not have prefer 32-bit checked in the project settings.
2) At the appropriate initialization place in your code, add one of the following:

PsConnection.StartAndConnect(); // Will start the highest version installed

PsConnection.StartAndConnect(EPsVersion.CS6); // Will start a specific version (if installed)

This only needs to be done once. If Photoshop is already started it will try to attach, otherwise it will start Photoshop and attach.

After initialization you can get the application by using the following code:

var app = PsConnection.Application;

Once you have the application you can do things like the following:

app.BackgroundColor = Color.Black.ToPsSolidColor();
app.ForegroundColor = Color.FromArgb(0, 0, 0, 128).ToPsSolidColor();

// Create a new document
IPsDocument document = app.Documents.Add(1024, 256, 72, "Welcome", EPsDocumentMode.psRGB);
//IPsDocument document = app.ActiveDocument;

//  Add an alpha channel
document.Channels.Add("ExtraChannel", EPsChannelType.psMaskedAreaAlphaChannel);

// Create a new layer
IPsArtLayer cloudLayer = document.ArtLayers.AddNormalLayer("Clouds");

//  Apply a few filters with default settings
cloudLayer.ApplyClouds();
cloudLayer.ApplyTwirl();
cloudLayer.ApplyAngledStrokes();
cloudLayer.ApplyAccentedEdges();

// Get a list of all of the available fonts
IEnumerable<IPsTextFont> fonts = app.Fonts.Cast<IPsTextFont>().ToList();

// Create a new text layer
IPsArtLayer textLayer = document.ArtLayers.AddTextLayer("Text");
textLayer.TextItem.Contents = ("Welcome to PsDotNet, " + Environment.UserName + "!");
var fontSize = 70;
textLayer.TextItem.Size = fontSize;
textLayer.TextItem.Position = new PointF((float)document.Width / 2, (float)document.Height / 2 + (float)fontSize / 2);
textLayer.TextItem.Justification = EPsJustification.psCenter;
textLayer.TextItem.Color = Color.OrangeRed.ToPsSolidColor();
textLayer.TextItem.Font = fonts.Skip(26).First();
textLayer.TextItem.HorizontalScale = 150;

// Create a layerStyle to apply to the Text layer
IPsLayerStyle layerStyle = app.CreateLayerStyle();

//  Get the opposite color used from the foreground        
IPsSolidColor pixelColor = app.ForegroundColor;
pixelColor.HSB.OffsetHue(180);
pixelColor.HSB.Saturation = 100;
pixelColor.HSB.Brightness = 100;

// Apply a glowStyle
IPsOuterGlowStyle glowStyle = layerStyle.AddOuterGlowStyle(pixelColor);
glowStyle.BlendMode = EPsLayerStyleBlendMode.Normal;
glowStyle.Opacity = 100;
glowStyle.Spread = 5;
glowStyle.Size = 50;

// Apply a strokeStyle
IPsStrokeStyleColorFillType strokeFill = app.CreateStrokeStyleColorFillType(Color.Black.ToPsSolidColor());
IPsStrokeStyle stroke = layerStyle.AddStrokeStyle(strokeFill);
stroke.Size = 2;
stroke.Position = EStrokePosition.Outside;

// Apply to the text layer
textLayer.ApplyLayerStyle(layerStyle);

// Flatten
document.Flatten();


Attached Files
.zip   PsDotNet_Beta2.1.zip (Size: 1.24 MB / Downloads: 20)
.zip   PsDotNet.QuickStart_2.1.zip (Size: 1.26 MB / Downloads: 17)
#2
example

Macro Scripting C#, PsDotNet
Code:
Select All      Help
str R=CsFunc("" "test" 5)
out R


#ret
//C# code
using System;
using PsDotNet;

public class Test
{
public static int TestFunction(string s, int i)
{
,PsConnection.StartAndConnect();
,//...
,return 1;
}

//add private functions here if need
}
PsDotNet.dll must be in QM folder or in .exe folder.
#3
I don't quite understand the above code. Can you write a few examples?  Smile

For example: Convert the following code to QM code?  Tongue

I think this is very helpful for some friends who are designing.

____________________________________________________________

This only needs to be done once. If Photoshop is already started it will try to attach, otherwise it will start Photoshop and attach.

After initialization you can get the application by using the following code:

var app = PsConnection.Application;

Once you have the application you can do things like the following:

app.BackgroundColor = Color.Black.ToPsSolidColor();
app.ForegroundColor = Color.FromArgb(0, 0, 0, 128).ToPsSolidColor();

// Create a new document
IPsDocument document = app.Documents.Add(1024, 256, 72, "Welcome", EPsDocumentMode.psRGB);
//IPsDocument document = app.ActiveDocument;

//  Add an alpha channel
document.Channels.Add("ExtraChannel", EPsChannelType.psMaskedAreaAlphaChannel);

// Create a new layer
IPsArtLayer cloudLayer = document.ArtLayers.AddNormalLayer("Clouds");

I registered the dll file and prompted an error.   Huh


Attached Files Image(s)
   
#4
Add your code in C# function TestFunction. Don't need to convert to QM.

Code:
Select All      Help
,PsConnection.StartAndConnect();
,PsConnection.StartAndConnect(EPsVersion.CS6); // Will start a specific version (if installed)
,var app = PsConnection.Application;
,//...
#5
Where is the dll file placed?
#6
Don't need to register. Unzip PsDotNet.dll to the QM folder and run the example macro.


Forum Jump:


Users browsing this thread: 1 Guest(s)