Copy link to clipboard
Copied
Hey gurus,
Can anyone give an example how to draw a line, a circle, a square and other polygons on a layer using VB.NET? I already found how to create a document, a new layer in it, but I cannot figure out how to handle PathPointInfo & SubPathInfo which I guess should be used.
PS. Do not ask me to use vbs instead 🙂
Thanks.
Copy link to clipboard
Copied
Yes we won't, no worries Just use Javascript
Copy link to clipboard
Copied
I wish nobody will answer you like this when you need help.
Copy link to clipboard
Copied
Dim coord_array1 = New Double() {100, 100} ' NB integer gives an error!
Dim coord_array2 = New Double() {100, 200}
Dim coord_array3 = New Double() {200, 100}
Dim coord_array4 = New Double() {200, 100}
Dim all_coords = New Array() {coord_array1, coord_array2, coord_array3, coord_array4}
Dim lineArray(4)
For counter_a = 1 To 4
Dim a_line As New PathPointInfo
a_line = CreateObject("Photoshop.PathPointInfo") ' ?? remove?
a_line.Kind = 2 ' psCornerPoint
Dim an_array As Array
an_array = all_coords(counter_a - 1)
a_line.Anchor = an_array
a_line.LeftDirection = a_line.Anchor
a_line.RightDirection = a_line.Anchor
lineArray(counter_a - 1) = a_line
Next
Dim line_subpath As New Photoshop.SubPathInfo()
line_subpath = CreateObject("Photoshop.SubPathInfo")
line_subpath.Closed = True
line_subpath.Operation = 1 ' SHAPEADD
line_subpath.EntireSubPath = lineArray
Dim mpi As Photoshop.PathItem
mpi = the_doc.PathItems.Add("A line", line_subpath)
the very last line gives this:
System.Runtime.InteropServices.COMException: 'Illegal argument - argument 2
- Array expected'
How can I fix this, please?
Copy link to clipboard
Copied
JSX example of drawing an ellipse
preferences.rulerUnits = Units.POINTS;
var k = 4 * (Math.sqrt(2) - 1) / 3;
// bounding box
var x0 = 10;
var y0 = 20;
var x1 = 110;
var y1 = 120;
var w = x1-x0;
var h = y1-y0;
// 4 points
var a = [x0, (y0+y1)/2];
var b = [(x0+x1)/2, y0];
var c = [x1, (y0+y1)/2];
var d = [(x0+x1)/2, y1];
// anchors
var al = [a[0], a[1] - h/2*k];
var ar = [a[0], a[1] + h/2*k];
var bl = [b[0] + w/2*k, b[1]];
var br = [b[0] - w/2*k, b[1]];
var cl = [c[0], c[1] + h/2*k];
var cr = [c[0], c[1] - h/2*k];
var dl = [d[0] - w/2*k, d[1]];
var dr = [d[0] + w/2*k, d[1]];
var pth = new Array();
var p = new Array();
p[0] = new PathPointInfo;
p[0].kind = PointKind.CORNERPOINT;
p[0].anchor = a;
p[0].leftDirection = al;
p[0].rightDirection = ar;
p[1] = new PathPointInfo;
p[1].kind = PointKind.CORNERPOINT;
p[1].anchor = b;
p[1].leftDirection = bl;
p[1].rightDirection = br;
p[2] = new PathPointInfo;
p[2].kind = PointKind.CORNERPOINT;
p[2].anchor = c;
p[2].leftDirection = cl;
p[2].rightDirection = cr;
p[3] = new PathPointInfo;
p[3].kind = PointKind.CORNERPOINT;
p[3].anchor = d;
p[3].leftDirection = dl;
p[3].rightDirection = dr;
pth[0] = new SubPathInfo();
pth[0].operation = ShapeOperation.SHAPEADD;
pth[0].closed = true;
pth[0].entireSubPath = p;
activeDocument.pathItems.add("Ellipse", pth);
Option translated to VBS
dim app
set app = CreateObject("Photoshop.Application")
app.preferences.rulerUnits = 5
k = 4 * (sqr(2) - 1) / 3
''''''''''''''''''''''''''''
' bounding box
''''''''''''''''''''''''''''
x0 = 10.0
y0 = 20.0
x1 = 110.0
y1 = 120.0
w = x1-x0
h = y1-y0
''''''''''''''''''''''''''''
' 4 points
''''''''''''''''''''''''''''
a = Array(x0, (y0+y1)/2)
b = Array((x0+x1)/2, y0)
c = Array(x1, (y0+y1)/2)
d = Array((x0+x1)/2, y1)
''''''''''''''''''''''''''''
' 4 pairs of anchors
''''''''''''''''''''''''''''
al = Array(a(0), a(1) - h/2*k)
ar = Array(a(0), a(1) + h/2*k)
bl = Array(b(0) + w/2*k, b(1))
br = Array(b(0) - w/2*k, b(1))
cl = Array(c(0), c(1) + h/2*k)
cr = Array(c(0), c(1) - h/2*k)
dl = Array(d(0) - w/2*k, d(1))
dr = Array(d(0) + w/2*k, d(1))
''''''''''''''''''''''''''''
' 4 PathPointInfo
''''''''''''''''''''''''''''
dim p(3)
set p(0) = CreateObject("Photoshop.PathPointInfo")
p(0).Kind = 2
p(0).Anchor = a
p(0).LeftDirection = al
p(0).RightDirection = ar
set p(1) = CreateObject("Photoshop.PathPointInfo")
p(1).Kind = 2
p(1).Anchor = b
p(1).LeftDirection = bl
p(1).RightDirection = br
set p(2) = CreateObject("Photoshop.PathPointInfo")
p(2).Kind = 2
p(2).Anchor = c
p(2).LeftDirection = cl
p(2).RightDirection = cr
set p(3) = CreateObject("Photoshop.PathPointInfo")
p(3).Kind = 2
p(3).Anchor = d
p(3).LeftDirection = dl
p(3).RightDirection = dr
''''''''''''''''''''''''''''
' 1 SubPathInfo
''''''''''''''''''''''''''''
dim pth(0)
set pth(0) = CreateObject("Photoshop.SubPathInfo")
pth(0).operation = 1
pth(0).Closed = true
pth(0).entireSubPath = p
call app.ActiveDocument.PathItems.Add("Ellipse", pth)
''''''''''''''''''''''''''''
' alternative call
''''''''''''''''''''''''''''
rem dim ret
rem set ret = app.ActiveDocument.PathItems.Add("Ellipse", pth)
Copy link to clipboard
Copied
Thank you for the sample, but the question is about VB.NET not VBScript.
Copy link to clipboard
Copied
I think the syntax is the same everywhere, try it.
In your case, you send the second argument is not an array of objects, but just one object.
Compare with my code.
P.S. (VB) Basic is evil
Copy link to clipboard
Copied
That's what I mostly read on this forum when someone comes with other programming language problem than Javascript.
Copy link to clipboard
Copied
Kukurykus Excuse me lady, please leave this topic.
Copy link to clipboard
Copied
You are really touchy my last sentence wasn't to offend you but an simple explanation to my previous comment. It seems your imagination is bigger than your common sense. Keep it up and you'll end in fantasy world... and just look at smileys I added in that post - they weren't meant to say nothing offensive, but something like WELCOME to this forum
Find more inspiration, events, and resources on the new Adobe Community
Explore Now