1 Reply Latest reply: Apr 19, 2015 7:02 PM by Loïc Formont RSS

    Change Background Macro

      Hello!

       

      I try to make a macro to change background image of TextObject from another TextObject.

      I use example from APIGuide 11

       

      'Set the background image of an object from another

      set mybox1 = ActiveDocument.GetSheetObject("LB01")

      dim MyBlob

      mbp1 = mybox1.GetProperties

      MyBlob = mbp1.Layout.Frame.Background.ImageBlob

       

      set mybox2 = ActiveDocument.GetSheetObject("LB02")

      mbp2 = mybox2.GetProperties

      mbp2.Layout.Frame.Background.UseImage=true

      mbp2.Layout.Frame.Background.UseColor=false

      mbp2.Layout.Frame.Background.ImageBlob = MyBlob

      mybox2.SetProperties mbp2

       

      I change Just "LB01" to "TX01" and "LB02" to "TX02" and code not work. But with ListBox code work perfectly.

      Also i trying this code

       

      'Set the background image of an object from another

      set mybox1 = ActiveDocument.GetSheetObject("TX01")

      dim MyBlob

      mbp1 = mybox1.GetProperties

      fbp1 = mybox1.GetFrameDef

      MyBlob = fbp1.Background.ImageBlob

       

      set mybox2 = ActiveDocument.GetSheetObject("TX02")

      mbp2 = mybox2.GetProperties

      fbp2 = mybox2.GetFrameDef

      fbp2.Background.UseImage=true

      fbp2.Background.UseColor=false

      fbp2.Background.ImageBlob = MyBlob

      mybox2.SetFrameDef fbp2

      mybox2.SetProperties mbp2


      No effect. Also, same situation with Button.

      Anyone help?

        • Re: Change Background Macro
          Loïc Formont

          Hello,

           

          the ImageBlob property does not seem to work.

           

          You can make this work by extracting the imagefile using the WriteXmlPropertiesFile property (Bmp node)

           

          And setting it to the new object using the applytheme method

           

          In c# :

          XElement bmp = new XElement("Bmp");

          bmp.Add(new XAttribute("enctype", "base64"));

          bmp.Value = base64encodedFile;

           

          XElement root = new XElement("QVTheme", new XElement("TextObjectProperties", new XElement("Layout", bmp)));

           

          string objFileName = Path.GetTempFileName();

          root.Save(objFileName);

           

          newObj.ApplyTheme(objFileName);

          File.Delete(objFileName);

           

          It's the only solution that I have found.

           

          Oh and don't forget to set the UserSized property to true BEFORE applying the theme or else the object will resize to the image original size.

           

          Best regards,

          Loic