我可以使用Javascript来绘制Adobe Illustrator吗?
问题描述:
我有一个客户希望将命令脚本编写到Adobe Illustrator。我相信这很容易,但是当谈到js 时,我基本上是使用excel电子表格上的接入点,并使用deminsions和说明。可以根据要求提供样品和更多细节。 Bob我可以使用Javascript来绘制Adobe Illustrator吗?
答
是的,您可以使用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
欢迎来到StackOverflow,Bob。这里的人很乐意提供帮助,但需要预先详细说明。请复习['我如何提出一个好问题?](https://stackoverflow.com/help/how-to-ask),并更新您的文章以获取更多详细信息。另外,考虑添加一个['Minimal,Complete和Verifiable示例'](https://stackoverflow.com/help/mcve),以显示您的进度的当前状态以及迄今为止尝试的内容。 – TheJim01
感谢您的有用建议 –
是的,您可以使用JS:http://www.adobe.com/devnet/illustrator/scripting.html –