Where am I wrong with Yorik’s Addon “Blender Importer” ?

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
User avatar
markko martin
Posts: 27
Joined: Tue Aug 09, 2016 5:51 pm
Location: Italy

Where am I wrong with Yorik’s Addon “Blender Importer” ?

Postby markko martin » Thu Aug 23, 2018 1:55 pm

Hi, I would play with Freecad and Blender 2,79.

I downloaded blender-2.79.0-git.53527ac10f2-windows64.
https://builder.blender.org/download/

I downloaded blender importer and I installed it from blender.
I set location of FreeCAD.pyd in the addon's preferences.

When I tried to import a Freecad file nothing happened.

Where am I wrong?

Thank you !



From Yorik guestbook:

“ You can already use the importer, it is pretty stable already, but you'll need to get your hands on (or compile yourself) a version of FreeCAD
compiled with the same Python version you use in Blender. The minor version number must match too, so if for example Blender uses 3.6.1, FreeCAD must use also 3.6 (the third digit can be different) ”



OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.14315 (Git)
Build type: Release
Branch: master
Hash: 5f8f26824486b55b2bf72c579e95f0f6d4a19284
Python version: 3.6.6
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.2.0
Locale: Italian/Italy (it_IT)
Attachments
Blender 2.79 daily build.jpg
Blender 2.79 daily build.jpg (131.71 KiB) Viewed 383 times
Loris
User avatar
yorik
Site Admin
Posts: 11458
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: Where am I wrong with Yorik’s Addon “Blender Importer” ?

Postby yorik » Thu Aug 23, 2018 3:19 pm

Hi,
Things to try:

- in Blender's python console: import FreeCAD
- If no error message appears, everything is fine and FreeCAD is correctly detected by Blender.
- If so, and you don't have the FreeCAD option in File->Import menu, then FreeCAD is correctly installed but the Blender addon is not. MAke sure your addon (the .py file downloaded from gist is at a correct location and has been enabled in Blender's addon preferences
- If "import FreeCAD" gives an error, then either the FreeCAD.pyd file is not found by Blender, or it is a wrong python version. In the addon settings, it allows you to specify a path to FreeCAD.pyd. But that will only work for the addon, not in the blender py console. To reproduce that in the console, for testing, you can do this:

Code: Select all

import sys
sys.path.append("C:\path\to\your\FreeCAD.pyd")
import FreeCAD
(replace C:\path\to\your\FreeCAD.pyd with your actual path, of course).
User avatar
markko martin
Posts: 27
Joined: Tue Aug 09, 2016 5:51 pm
Location: Italy

Re: Where am I wrong with Yorik’s Addon “Blender Importer” ?

Postby markko martin » Thu Aug 23, 2018 4:38 pm

I have the FreeCAD option in File->Import menu.

"import FreeCAD" doesn't give any error.

But Blender gives this error:

Traceback (most recent call last):
File "C:\Users\USER\AppData\Roaming\Blender Foundation\Blender\2.79\scripts\addons\io_import_fcstd.py", line 476, in execute
sharemats=self.option_sharemats)
File "C:\Users\USER\AppData\Roaming\Blender Foundation\Blender\2.79\scripts\addons\io_import_fcstd.py", line 398, in import_fcstd
diffshader.inputs['Color'].default_value = rgba
AttributeError: 'NoneType' object has no attribute 'inputs'

location: <unknown location>:-1


My freecad file contains 2 walls without materials.
Loris
User avatar
yorik
Site Admin
Posts: 11458
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: Where am I wrong with Yorik’s Addon “Blender Importer” ?

Postby yorik » Fri Aug 24, 2018 1:26 pm

Okay, that's much clearer. Everything works, but there is a bug in the importer code.

But it's strange, on my Blender version here, a cycles diffuse shader is automatically created for new materials, apparently in your case not (blender materials are created from freecad object color). I now updated the code on github, you won't have automatic cycles materials, but at least you won't get this error anymore. Later on I'll add some more code to create the needed cycles nodes if they are not present.
User avatar
markko martin
Posts: 27
Joined: Tue Aug 09, 2016 5:51 pm
Location: Italy

Re: Where am I wrong with Yorik’s Addon “Blender Importer” ?

Postby markko martin » Fri Aug 24, 2018 3:22 pm

Ok I found the problem! (with the old code of the addon)
If Blender Render is set, Blender gives error.

The right steps are:
- Open Blender.
- Set Cycles as renderer.
- File - Import - FreeCAD file.

With this procedure all is working and blender automatically creates new diffuse material.

Thank you Yorik!
I'm very happy :D
Loris
User avatar
yorik
Site Admin
Posts: 11458
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: Where am I wrong with Yorik’s Addon “Blender Importer” ?

Postby yorik » Fri Aug 24, 2018 9:32 pm

Glad you have it working! The mystery is solved, then, cycles materials are only created if you are in Cycles render mode... Good to know.