3D model STEP, WRL downloader/updater per Board requirements

Hi,
I developed this tool following some users need in relation to download or update 3D models on a KiCad pcb board.

This tool, after a small configuration, will automatically download WRL and STEP files placing them to the relative local folder.
The nice thing is that the tool will download/update ONLY the 3D models needed by the selected kicad_pcb board, as defined in the board footprints.
This can be handful when using standard KiCad footprints, that have pre-configured 3D models.
The tool could be also improved to allow a server proxieā€¦

No git versioning or svn support, just a simple downloader/updater for the required 3D models of a single project.
Feedback welcome.

Plese note that is a very initial release (not deeply tested):

The script can be launched ATM only on win OS.
Just configure your parameters inside the ā€˜.batā€™ file and launch collect3Dmod.bat

For Linux or Osx one must use the command line as for example:
python list_models.py your_kicad_3D_folder 4 your_kicad_board_full_file_path

README

7 Likes

Nice! Iā€™d love to see such a concept integrated directly into KiCad. I imagine it would still have to be a python script rather than being compiler in, for 2 reasons:

  1. Python is a much better tool for doing this than C++
  2. If the library links ever change, you want to be able to quickly tweak the scripts rather than have to recompile KiCad.

Iā€™ve been trying for ages to think of a better way to download models than the raw.github approach. Iā€™m not sure there is one.

I played with uploading a .7z file for each model onto kicad.github.io but it takes too long to compile the library data and also creates a LOT of extra data.

Edit: phone autocorrect betrays me

Is there a way for a python script to be ā€œintegratedā€ into the main KiCad window instead of just pcbnew?

I donā€™t think so but Iā€™m not 100% sure. I know nothing about how the Python scripting interface works. Iā€™d love to see a tighter python integration, thereā€™s a lot of functionality that further scripting would provide

You keep writing the core code. Iā€™ll try to come up with an interface prototype.

There are at least two problems ATM to integrate this script into Kicad:

  1. pcbnew python API have little functions exposedā€¦ (I couldnā€™t even search for 3D models inside a board)
  2. there is no easy way to write on default standard 3D packages folders from inside pcbnew because those folders are under Administrator permissionā€¦

There is already a better kicad-python implementation, but it is outside the standard installation of KiCad

If you want to download the zipped version of a file there is the DownGit approach ā€¦
Download the zipped dynamically generated file and then you can unzip it and place it to the desired folderā€¦

Iā€™ve updated the program to be a pcbnew Tools menu item. It has the issue of not being able to write to system libraries (unless presumably you start KiCad as administrator). And the library paths are hard coded for Windows.

Itā€™s available as a fork on GitHub, and thereā€™s an outstanding pull request.

I havenā€™t tested it except for the menu item. I tried to modify the original as little as possible.

Why not use $KISYS3DMOD?

The easy answer is ā€œI didnā€™t know about itā€.

THANK YOU for mentioning this, the fork and pull request are updated to use the environment variable.

Hi @HiGreg
thank you for your contribution but unfortunately it would be useless on most user caseā€¦

I started my code as an external script exactly because of the system libraries standard location ā€¦ they are as default located where Administrator rights are requiredā€¦
You can see that on my previous post.

Launching the script from inside KiCad would be most useless because of administrative rights.
So unless the libraries folder location would change (that I donā€™t thint it will happen) this tool will not be useful as an action script.

ATM the script is already considering:

  • KISYS3DMOD
  • KIPRJMOD
    to place locally the 3D downloaded models, but the var has to be manually configured at first run.

KISY3DMOD var is available safety only inside pcbnew (not all users are setting environment variables in the OS, but just internally in kicad)
It could be read from kicad userā€™s profile configuration files, but atm it is not done.

Can the library location be changed manually to user space?

The user can define whatever they want in KISYS3DMOD.

Might be a good idea for the download script to ask the user where they want the libs to be stored and set KISYS3DMOD to point to this location.

KIPRJMOD might not work for users using the default libs. We require that the 3d path includes KISYS3DMOD

yes, but the average user is not expected to do it.
Moreover if you have followed the dev mailing list, the probability that the actual location may vary is very very littleā€¦

it is easier to just use the script with administrative right in that caseā€¦
I never used this library location, but this is aimed to help users that are not familiar to kicad environment.

the script will substitute the internal {$KISYS3DMOD} with the configured pathā€¦
If instead {$KIPRJMOD} is present, the script will save the 3D model to a relative path
This is the case when someone is saving a project to GitHub, using explicitly this var inside the pcbnew file, for a real 3D feature portability.
In that case instead of {$KISYS3DMOD} the user will put {$KIPRJMOD} for each modelā€¦
Icezum board is an example

Iā€™ve figured out how to elevate privileges in Windows python and can run the ā€œupdate 3d modelsā€ script as admin. I think this would be very useful as a menu item within KiCad, where it can automatically know the project and the library. I can come up with modifications that will enable this on Windows KiCad. It will require a little more investigation to get it working under Linux.

thatā€™s good!

So I would create a new repo of the same script, but as an action scriptā€¦ then we could work on that, leaving this as standalone scriptā€¦

here my action_plugins repo


Iā€™ve added the basic script to work on here but ATM it is just a WIPā€¦ use the basic python script above instead.
https://github.com/easyw/kicad-action-plugins/blob/master/action_menu_get3D_models.py

In Linux the utility fakeroot replaces sudo. It let your script overtake all the administrative priviledges.
Mbeh

from stackoverflow

As long as you are within the fakeroot shell, it looks like if you are root - as long as you do not try to do anything that really needs root privileges. And this is exactly what a packaging tool need to make packages that will make sense on any machine.

So the subprocess.Popen should be the candidate for Win and Unix

The library script actually needs root for access to the directory. And I havenā€™t seen Popen used for process elevation on windows, only ShellExecute.

Popen works fine with PowerShell, and it can be used to ask for Administrator rightā€¦
Probably Popen could be used also in Unix to ask for Admin rightsā€¦ I need to have some spare time to check itā€¦

1 Like

Iā€™m fully agree and support for relative paths. It more useful for me. It do not require to monkey with KISYS3DMOD variables. I personally still have hard time to see KISYS3DMOD work for may case.