我可以在Adobe Illustrator中使用Javascript进行绘制吗?



我有一个客户端想要将命令脚本编写给Adobe Illustrator。我确定这很容易,但是对于js来说,我是一个基本的 我正在使用 excel 电子表格上的访问点,带有说明和描述。可以根据要求提供样品和更多详细信息。 鲍勃

是的,您可以使用 js 在 Adobe Illustrator 中绘制。

但是,如果您打算从MS Excel应用程序绘制,则VBA更可取。

下面的代码是用 VBA 编写的,用于绘制一个 Lemniscate。 您可以将其用作示例:

Option Explicit
Option Base 0
Private ai_Doc As Illustrator.Document
Private Function Get_Lemniscate(ByVal Point_Count As Long) As Variant
Const PI As Double = 3.14159265358979
Dim t As Double
Dim t3 As Double
Dim t4 As Double
Dim i As Long
Dim ret As Variant
ReDim ret(Point_Count)
For i = LBound(ret) To UBound(ret)
t = Math.Tan(PI * ((i / Point_Count) - 0.5))
t3 = t * t * t
t4 = t * t3
ret(i) = Array( _
500 + 300 * (t + t3) / (1 + t4), _
300 + 300 * (t - t3) / (1 + t4))
Next
Get_Lemniscate = ret
End Function
Private Function Get_AI_Document() As Illustrator.Document
With New Illustrator.Application
' It may be necessary to make AI visible here - it is a small trick 
If (.Documents.Count = 0) Then
.Documents.Add
End If
Set Get_AI_Document = .ActiveDocument
End With
End Function
Private Sub Draw_AI_Path(ByRef Point_Array As Variant)
Dim New_Path As Illustrator.PathItem
Set New_Path = ai_Doc.PathItems.Add
New_Path.SetEntirePath Point_Array
' Do some other stuff (colors, line stroke etc)
End Sub

Sub Test()
Set ai_Doc = Get_AI_Document
Draw_AI_Path Get_Lemniscate(6000)
End Sub

最新更新