Skip to main content
Participating Frequently
November 27, 2017
Answered

Mismatch type Illustrator 32bit and 64 bit

  • November 27, 2017
  • 2 replies
  • 1175 views

I am running a script for the last 10 years without problem and suddenly it doesn't work

This script do not work on Illustrator 64 bit but no problem on illustrator 32 bit until last week, no library or reference missing.

Maybe somebody may help me to solve this problem below, in reality I have hundred of script with the same mismatch type error

THE ERROR IS ON THIS LINE BELOW            set FirstMi2 = PointMi2(Ligne) ' ERROR MISMATCH TYPE

Sub length2()

Dim Ligne As Long

Dim FirstMi2 As Illustrator.PathPoint    'if I write only  Dim FirstMi2   then the same error will be at the next line  Set NextMi2 = PointMi2(Ligne + 1)

Dim NextMi2 As Illustrator.PathPoint   'if I write only  Dim NextMi2  then the same error will be at the next line   dPoint1X = FirstMi2.Anchor(0)

Dim numPointMi2 As Double

Dim EachLength As Double

Dim TotalLength As Double

Dim dPoint1X As Double    'if I write only Dim dPoint1X  then the same error will be at the next line  dPoint1Y = FirstMi2.Anchor(1)

                                            'If I do not dim all point as Double then I cannot use my        Public Function BezierLength(dPoint1X As Double, ....

Dim dPoint1Y As Double

Dim dPoint2X As Double

Dim dPoint2Y As Double

Dim dPoint3X As Double

Dim dPoint3Y As Double

Dim dPoint4X As Double

Dim dPoint4Y As Double

Dim appRef

Set appRef = CreateObject("Illustrator.Application.CS6")

Set docRef = appRef.ActiveDocument

Set LayerRef1 = docRef.ActiveLayer()

If Not IsEmpty(appRef.Selection) Then

mySelection = appRef.Selection

endIndex = UBound(mySelection)

startIndex = LBound(mySelection)

TotalLength = 0

For i = startIndex To endIndex

Set MyPathItem = mySelection(i)

Set PointMi2 = MyPathItem.PathPoints

numPointMi2 = PointMi2.Count

        For Ligne = 1 To (numPointMi2 - 1) Step 1

            Set FirstMi2 = PointMi2(Ligne)                '  ERROR MISMATCH TYPE

            Set NextMi2 = PointMi2(Ligne + 1)

            dPoint1X = FirstMi2.Anchor(0)

            dPoint1Y = FirstMi2.Anchor(1)

            dPoint2X = FirstMi2.RightDirection(0)

            dPoint2Y = FirstMi2.RightDirection(1)

            dPoint3X = NextMi2.LeftDirection(0)

            dPoint3Y = NextMi2.LeftDirection(1)

            dPoint4X = NextMi2.Anchor(0)

            dPoint4Y = NextMi2.Anchor(1)

            EachLength = BezierLength(dPoint1X, dPoint1Y, dPoint2X, dPoint2Y, dPoint3X, dPoint3Y, dPoint4X, dPoint4Y)

            TotalLength = TotalLength + EachLength

        Next Ligne

Next

MsgBox "Longeur " & (Round((TotalLength / 72), 4)) & "   " & "Nombre de points " & numPointMi2 & "   " & i & " de " & endIndex

End If

End Sub

Thanks Marcel

This topic has been closed for replies.
Correct answer OMOTI

My pleasure. The slightly edited following script is fine in my environment. Unfortunately I don't have Excel, so I can't specify data types. Can you try to debug this via Excel Visual Basic editor?

Execution environment:

    Windows 7 64-bit

    Illustrator CS6 Version 16.0.3(64-bit)

    Use the menu or doubleclick the VBS file

Sub Test()

    Dim appRef

    Dim FirstPointX 'As Double

    Dim FirstPointY 'As Double

    Dim FirstPathPoint 'As Illustrator.PathPoint

   

    Set appRef = CreateObject("Illustrator.Application.CS6")

    Set docRef = appRef.Documents.Add

    Set smoothPath = appRef.ActiveDocument.PathItems.Add

    smoothPath.Closed = False

    smoothPath.Stroked = True

    smoothPath.StrokeWidth = 2

    smoothPath.Filled = False

    smoothPath.Name = "MyPath"

    Set newPathPoint = smoothPath.PathPoints.Add

    newPathPoint.Anchor = Array(100, 200)

    newPathPoint.LeftDirection = Array(100, 20)

    newPathPoint.RightDirection = Array(100, 180)

    newPathPoint.PointType = 2

    Set newPathPoint = smoothPath.PathPoints.Add

    newPathPoint.Anchor = Array(300, 400)

    newPathPoint.LeftDirection = Array(330, 250)

    newPathPoint.RightDirection = Array(270, 350)

    newPathPoint.PointType = 2

    'It's enough that remove the three lines below and append this.

    'Set PathBase = docRef.PathItems("MyPath")

    Set docRef = appRef.ActiveDocument

    Set LayerRef = docRef.ActiveLayer '() isn't needed.

    Set PathBase = LayerRef.PathItems("MyPath")

    Set PointBase = PathBase.PathPoints

    Set FirstPathPoint = PointBase(1)

    FirstPointX = FirstPathPoint.Anchor(0)(0) 'The dimensions of the array are different.

    FirstPointY = FirstPathPoint.Anchor(0)(1) 'The dimensions of the array are different.

    MsgBox "My first point  " & FirstPointX & " X  " & FirstPointY & " Y  "

End Sub

Test()

2 replies

OMOTI
Inspiring
December 4, 2017

I also wonder why is .Anchor(0)(0) going well, not .Anchor(0).

In javascript, .anchor returns array of 2 numbers. Additionally, "Illustrator - Scripting - Reference - VBScript - cs 6" also says that Anchor will return Variant Array of 2 Doubles. Umm...

OMOTI
Inspiring
December 1, 2017

Hi, Marcel Leclerc.

I couldn't run your script. There is something to worry about.

I think that VBScript is a typeless language. Is there no problem if the script is executed via application like Excel?

Microsoft Windows 2000 Scripting Guide - VBScript Data Types

Also, there is no process in the script to verify whether each selected object is a pathItem. So if an object other than pathItem is included, an error will occur.

And I tried it by writing a similar script. All of the following ways are fine. But the process of subroutine "BezierLength" is my expectation.

Execution environment:

  • Windows 7 64-bit
  • Illustrator CS6 Version 16.0.0(32-bit)
  • Illustrator CS6 Version 16.0.3(64-bit)

How to run this script in Illustrator CS6 Version 16.0.0(32-bit):

  • via CUI "Command Line".(C:\Windows\SysWow64\cscript.exe length2.vbs)

How to run this script in Illustrator CS6 Version 16.0.3(64-bit):

  • via menu. (File > Scripts > Other Script and choose the file "length2.vbs")
  • via doubleclick the file "length2.vbs" in explorer.

This is my script named "length2.vbs":

Sub length2()

    Dim totalLength

    Dim pathPointCount

    Dim endIndex

    Dim i

    Dim app

    Dim doc

    Dim sel

    Dim pathItem

   

    Set app = CreateObject("Illustrator.Application.CS6")

    Set doc = app.ActiveDocument

   

    If IsEmpty(app.Selection) Then

        Exit Sub

    End If

   

    sel = app.Selection

    endIndex = UBound(sel)

    totalLength = 0

    pathPointCount = 0

   

    For i = 0 To endIndex

        Set pathItem = sel(i)

        If pathItem.Typename = "PathItem" Then

            totalLength = totalLength + pathItem.Length

            pathPointCount = pathPointCount + pathItem.PathPoints.Count

        End If

    Next

   

    MsgBox "Longeur " & (Round((totalLength / 72), 4)) & "   " & "Nombre de points " & pathPointCount & "   " & i & " de " & endIndex

   

End Sub

length2()

Participating Frequently
December 3, 2017

Thanks for your help,

I should have been more explicit; all my scripts are in Excel Visual Basic editor.

I do not use the      menu. (File > Scripts > Other Script and choose the file "MyScript")

Here is a very basic script which is still working in all my computers.

Last week only the “Window 10” has stop to accept this script.

Sub Test()

Dim appRef

Set appRef = CreateObject("Illustrator.Application.CS6")

Set docRef = appRef.Documents.Add

Set smoothPath = appRef.ActiveDocument.PathItems.Add

smoothPath.Closed = False

smoothPath.Stroked = True

smoothPath.StrokeWidth = 2

smoothPath.Filled = False

smoothPath.Name = "MyPath"

Set newPathPoint = smoothPath.PathPoints.Add

newPathPoint.Anchor = Array(100, 200)

newPathPoint.LeftDirection = Array(100, 20)

newPathPoint.RightDirection = Array(100, 180)

newPathPoint.PointType = 2 ' aiSmooth

Set newPathPoint = smoothPath.PathPoints.Add

newPathPoint.Anchor = Array(300, 400)

newPathPoint.LeftDirection = Array(330, 250)

newPathPoint.RightDirection = Array(270, 350)

newPathPoint.PointType = 2 ' aiSmooth

Dim FirstPointX As Double

Dim FirstPointY As Double

Set docRef = appRef.ActiveDocument

Set LayerRef = docRef.ActiveLayer()

Dim FirstPathPoint As Illustrator.PathPoint

Set PathBase = LayerRef.PathItems("MyPath")

Set PointBase = PathBase.PathPoints

Set FirstPathPoint = PointBase(1)      '  ERROR MISMATCH TYPE

FirstPointX = FirstPathPoint.Anchor(0)

FirstPointY = FirstPathPoint.Anchor(1)

MsgBox "My first point  " & FirstPointX & " X  " & FirstPointY & " Y  "

End Sub

OMOTI
OMOTICorrect answer
Inspiring
December 3, 2017

My pleasure. The slightly edited following script is fine in my environment. Unfortunately I don't have Excel, so I can't specify data types. Can you try to debug this via Excel Visual Basic editor?

Execution environment:

    Windows 7 64-bit

    Illustrator CS6 Version 16.0.3(64-bit)

    Use the menu or doubleclick the VBS file

Sub Test()

    Dim appRef

    Dim FirstPointX 'As Double

    Dim FirstPointY 'As Double

    Dim FirstPathPoint 'As Illustrator.PathPoint

   

    Set appRef = CreateObject("Illustrator.Application.CS6")

    Set docRef = appRef.Documents.Add

    Set smoothPath = appRef.ActiveDocument.PathItems.Add

    smoothPath.Closed = False

    smoothPath.Stroked = True

    smoothPath.StrokeWidth = 2

    smoothPath.Filled = False

    smoothPath.Name = "MyPath"

    Set newPathPoint = smoothPath.PathPoints.Add

    newPathPoint.Anchor = Array(100, 200)

    newPathPoint.LeftDirection = Array(100, 20)

    newPathPoint.RightDirection = Array(100, 180)

    newPathPoint.PointType = 2

    Set newPathPoint = smoothPath.PathPoints.Add

    newPathPoint.Anchor = Array(300, 400)

    newPathPoint.LeftDirection = Array(330, 250)

    newPathPoint.RightDirection = Array(270, 350)

    newPathPoint.PointType = 2

    'It's enough that remove the three lines below and append this.

    'Set PathBase = docRef.PathItems("MyPath")

    Set docRef = appRef.ActiveDocument

    Set LayerRef = docRef.ActiveLayer '() isn't needed.

    Set PathBase = LayerRef.PathItems("MyPath")

    Set PointBase = PathBase.PathPoints

    Set FirstPathPoint = PointBase(1)

    FirstPointX = FirstPathPoint.Anchor(0)(0) 'The dimensions of the array are different.

    FirstPointY = FirstPathPoint.Anchor(0)(1) 'The dimensions of the array are different.

    MsgBox "My first point  " & FirstPointX & " X  " & FirstPointY & " Y  "

End Sub

Test()