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


#1

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


Update 3d model to all identical footprints at once
#2

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


#3

Is there a way for a python script to be “integrated” into the main KiCad window instead of just pcbnew?


#4

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


#5

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


#6

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…


#7

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.


#8

Why not use $KISYS3DMOD?


#9

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.


#10

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.


#11

Can the library location be changed manually to user space?


#12

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


#13

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


#14

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.


#15

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.


#16

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


#17

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


#18

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.


#19

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…