Home Forums Bug Reports Import Library Dialog with many sNp files failes.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #2948
    ddieterle
    Keymaster

      According to the forum topic How create a library (or user library) of sNp-files ? I tried to create a new user library with many (=1060) sNp files:

      Unfortunately the text entry field can not hold all the file names to create the new library. It truncates the file list after 32767 characters:

      Obviously the conversion stops with an error message:

       

      Is there a way of modifying the import dialog, so that a folder, instead of a set of single files, can be selected?

      For testing purposes the sNp library can be downloaded here: GJM

      # For a workaround I created a quick-n-dirty python script generation the QucsStudio library:

      import sys
      import os
      from pathlib import Path
      import shutil

      if len(sys.argv) <= 1:
      print(“Syntax: python create_user_qucs_library.py library_directory_containing_the_data_files number_description_lines {capacitor|coil|BJT|FET} new_library_name”)

      library_directory_containing_the_data_files = sys.argv[1]
      number_description_lines = int(sys.argv[2])
      sNp_component_type = sys.argv[3]
      new_library_name = sys.argv[4]
      new_library_file_name = new_library_name+”.lib”

      hs = open(new_library_file_name, ‘w’, newline=”)
      hs.write(“<QucsStudio Library 4.2.2 \””+new_library_name+”\”>\n\n”)

      # 1. Create library XML File
      for sNp_file in os.scandir(library_directory_containing_the_data_files):
      component_name = Path(sNp_file.name).stem
      hs.write(“<Component “+component_name+”>\n”)
      hs.write(” <Description>\n”)
      with open(sNp_file) as current_component_sNp_file:
      for description_line_idx in range(number_description_lines):
      intendet_description_line = ” “+next(current_component_sNp_file)[1:]
      hs.write(intendet_description_line)
      hs.write(” </Description>\n”)
      hs.write(” <Model>\n”)
      hs.write(” SPfile _”+component_name+”_ 1 280 320 -26 -40 0 0 \”*/”+new_library_name+”#”+sNp_file.name+”\” 0 \”2\” 0 \”polar\” 0 \”linear\” 0 \”open\” 0 \”none\” 0 \””+sNp_component_type+”\” 0\n”)
      hs.write(” </Model>\n”)
      hs.write(“</Component>\n\n”)
      hs.close()

      # 2. Move library XML File to qucs library user directory
      user_home_dir = str(Path.home())
      qucs_user_lib_dir = os.path.join(user_home_dir, “.qucs\\user_lib”)
      shutil.move(new_library_file_name, qucs_user_lib_dir)

      # 3. Move and Rename sNp files
      for sNp_file in os.scandir(library_directory_containing_the_data_files):
      library_name_extended_sNp_file_name = new_library_name+”#”+sNp_file.name
      shutil.copy(sNp_file, os.path.join(qucs_user_lib_dir, library_name_extended_sNp_file_name))

      The result is a successful created library (below the 1060th component is selected) 🙂

    Viewing 1 post (of 1 total)
    • You must be logged in to reply to this topic.