Skip to main content
Inspiring
February 6, 2018
Answered

Using Interop.Illustrator with VS2017 aand C# PlaceItem.File property throwing exception

  • February 6, 2018
  • 3 replies
  • 2778 views

C# code as example of problem:

        private void Run_OnCLick(object sender, RoutedEventArgs e)

        {

            Document doc = null;

            Illustrator.Application app = null;

            try

            {

                // open AI, init

                app = new Illustrator.Application();

           

                // open doc

                doc = app.Open("D:\\Test\\Vintage\\Package_Test.ait", Illustrator.AiDocumentColorSpace.aiDocumentRGBColor, null);

                // insert image

                PlacedItem img = doc.PlacedItems.Add();

                int cnt = doc.PlacedItems.Count;

                String file = "D:\\Dev\\Vinatage\\00_Coaster.png";

                img.File = file; //throw exception

                img.Top = 0;

                img.Left = 0;

                img.Height = 5.4;

                img.Width = 5.4;

            }

            catch (COMException ce)

            {

                string msg = ce.StackTrace;

                string errorCode = String.Format("0x{0:X}", ce.HResult);

                MessageBoxResult result = MessageBox.Show(msg, ce.Source, MessageBoxButton.OK, MessageBoxImage.Error);

            }

            finally

            {

                doc.Close(AiSaveOptions.aiDoNotSaveChanges);

                app.Quit();

            }

        }

msg =

   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)

   at Illustrator.PlacedItem.set_File(String )

   at WpfApplication1.MainWindow.Run_OnCLick(Object sender, RoutedEventArgs e) in D:\projects\WpfApplication1\WpfApplication1\MainWindow.xaml.cs:line 46

I am hoping someone has an idea what is causing this.

If I use the AI menu File->Place it works fine ...

This topic has been closed for replies.
Correct answer Silly-V

You are setting a string, try to set instead your code's version of the File object type variable.

Just kidding, in your code it appears the String is the required type of input. But, it's got a typo "Vinatage".

3 replies

Participant
October 13, 2018

Hi Sir,

    If I want to export the bmp file with 1693 dpi, what can I do in C#?

Inspiring
February 6, 2018

I modified my code as follows and it no works .... yeah

                String file = "D:\\Dev\\Vintage\\00_Coaster.png";

                // insert image

                if (File.Exists(file))

                {

                    PlacedItem img = doc.PlacedItems.Add();

                    int cnt = doc.PlacedItems.Count;

                    img.File = "D:\\Dev\\Vintage\\00_Coaster.png";

                    img.Embed();

                    img.Top = 0;

                    img.Left = 0;

                    img.Height = 5.4;

                    img.Width = 5.4;

                }

Silly-V
Legend
February 6, 2018

you might as well say img.File = file;

Silly-V
Silly-VCorrect answer
Legend
February 6, 2018

You are setting a string, try to set instead your code's version of the File object type variable.

Just kidding, in your code it appears the String is the required type of input. But, it's got a typo "Vinatage".

Inspiring
February 6, 2018

You are awesome, added this code:

                String file = "D:\\Dev\\Vintage\\00_Coaster.png";

                // insert image

                if (File.Exists(file))

                {

                    ...

               }