Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Custom gfx not (always) copied during importing addon

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Custom gfx not (always) copied during importing addon

    Hi Ninja

    I've made a custom drawing tool package which has a few custom gfx.
    During installation these gfx should be copied automatically into the C:\Users\[USERNAME]\Documents\NinjaTrader 8\templates folder
    Strange thing is.. this works fine when i import it on some machines.. but on other pcs, the tools itself get installed but the gfx are not copied..

    Here's how my addon-zip file looks internally. As you can see i added a templates folder

    Click image for larger version

Name:	Capture.JPG
Views:	209
Size:	45.3 KB
ID:	1040108

    And within the templates folder is a subfolder called TDU in which all the gfx are placed.
    After zipping, i can import the addon fine in ninja and the drawing tool gets installed fine.
    However the gfx in the templates\TDU dont get copied into C:\Users\[USERNAME]\Documents\NinjaTrader 8\templates\TDU


    Click image for larger version

Name:	Capture2.JPG
Views:	178
Size:	73.9 KB
ID:	1040109
    EB Worx
    NinjaTrader Ecosystem Vendor - EB Worx

    #2
    Hello Erwin Beckers,

    Thanks for your inquiry.

    When I test on my end with NinjaTrader 8 Release 16.3, I'm able to place png files in a "templates" folder of the export as well as within a sub folder of the templates folder and I am not encountering any issue.

    Could you confirm if you are hitting the issue with the test package I have attached and you are on the latest version of NinjaTrader 8?

    Is there any other detail that you could provide on the machines where this does not work? If we can identify some specific differences that create this behavior we could use the information to report the issue for a fix.

    I look forward to being of further assistance.
    Attached Files
    JimNinjaTrader Customer Service

    Comment


      #3
      Yes you zip file works fine. But mine doesnt,, In my case the gfx files are not copied , and my folder structure inside the zip looks the same as yours

      Could it be that it fails since my package

      1) is a drawing tool, not an indicator
      2) the gfx is used for the Icon.. (see below) and not for drawing something on the chart


      Code:
         public abstract class MeasuredMove: DrawingTool
          {
              protected BitmapImage _iconBitmapImage = new BitmapImage();
              protected override void OnStateChange()
              {
                  ...
                  if (State == State.Configure)
                  {
                      _iconBitmapImage.BeginInit();
                      var folder = Path.Combine(NinjaTrader.Core.Globals.UserDataDir, "templates");
                      folder = Path.Combine(folder, "TDU");
                      folder = Path.Combine(folder, "wolf.png");
                      _iconBitmapImage.UriSource = new Uri(folder);
                      _iconBitmapImage.EndInit();
                 }
            }
      
            public override object Icon
              {
                  get
                  {
                      // Instantiate a Grid on which to place the image
                      var myCanvas = new Grid { Height = 16, Width = 16 };
      
                      // Instantiate an Image to place on the Grid
                      var image = new Image
                      {
                          Height = 16,
                          Width = 16,
                          Source = _iconBitmapImage
                      };
      
                      // Add the image to the Grid
                      myCanvas.Children.Add(image);
      
                      return myCanvas;
                  }
              }
      EB Worx
      NinjaTrader Ecosystem Vendor - EB Worx

      Comment


        #4
        Hello Erwin,

        I would not expect how the resource is used in code to effect how that resource is imported when it is added in the templates folder of an export.

        When I test using a blank drawing tool that does not use the file at all and then add the resources to an export of that drawing tool, I can import both png files from "templates" and the subfolder.

        There still seems to be some unknown which is causing the difference in behavior for your export.

        If you create a blank drawing tool similar to the dummy scripts attached, are you able to import both resource files for both source code exports and compiled assembly exports?

        If you swap resources between using the SampleDrawBitmap.png and wolf.png does your script or the test script import differently?

        I look forward to being of further assistance.
        Attached Files
        JimNinjaTrader Customer Service

        Comment


          #5
          Finally figured it out.. Ninja locks the icon files on disk when the drawingtool is loaded.
          This means that if you want to install a newer version of the drawing tool then the installation fails since it cannot overwrite the icons.

          To fix this i had to rewrite the part which loads the icon from disk.
          Basicly it now loads the icon from a stream instead of directly from the file. That way Ninjatrader cannot lock the file anymore;

          Code:
                  public override object Icon
                  {
                      get
                      {
                          var grid= new Grid { Height = 16, Width = 16 };
                          var image = new Image
                          {
                              Height = 16,
                              Width = 16,
                              Source = GetImageSource("myicon.png")
                          };
          
                          grid.Children.Add(image);
                          return grid;
                      }
                  }
          
                  private BitmapImage GetImageSource(string fileName)
                  {
                      var folder = Path.Combine(NinjaTrader.Core.Globals.UserDataDir, "templates");
                      folder = Path.Combine(folder, "mysubfolder");
                      folder = Path.Combine(folder, fileName);
                      if (!File.Exists(folder)) return null;
          
                      using (var stream = File.OpenRead(folder))
                      {
                          var bitmap = new BitmapImage();
                          bitmap.BeginInit();
                          bitmap.CacheOption = BitmapCacheOption.OnLoad;
                          bitmap.StreamSource = stream;
                          bitmap.EndInit();
                          bitmap.Freeze();
          
                          return bitmap;
                      }
                  }
          EB Worx
          NinjaTrader Ecosystem Vendor - EB Worx

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by love2code2trade, 04-17-2024, 01:45 PM
          4 responses
          36 views
          0 likes
          Last Post love2code2trade  
          Started by alifarahani, Today, 09:40 AM
          2 responses
          13 views
          0 likes
          Last Post alifarahani  
          Started by junkone, Today, 11:37 AM
          3 responses
          15 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by pickmyonlineclass, Today, 12:23 PM
          0 responses
          1 view
          0 likes
          Last Post pickmyonlineclass  
          Started by frankthearm, Yesterday, 09:08 AM
          12 responses
          44 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Working...
          X