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!
Post Reply
User avatar
markko martin
Posts: 64
Joined: Tue Aug 09, 2016 5:51 pm
Location: Italy

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

Post by markko martin »

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 2579 times
Loris
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

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

Post by yorik »

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: 64
Joined: Tue Aug 09, 2016 5:51 pm
Location: Italy

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

Post by markko martin »

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
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

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

Post by yorik »

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: 64
Joined: Tue Aug 09, 2016 5:51 pm
Location: Italy

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

Post by markko martin »

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
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

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

Post by yorik »

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.
Valafenn
Posts: 3
Joined: Fri Jun 01, 2018 8:52 pm

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

Post by Valafenn »

Hi

I've encountered the same problem with Freecad-daily and Blender 2.8 (normal install for xubuntu 19.10).

Python console import FreeCAD clear

Render on Cycles

bpy.context.space_data.context = 'RENDER'
bpy.context.scene.render.engine = 'CYCLES'
bpy.context.object.hide_viewport = True
bpy.data.window_managers["WinMan"].(null) = 1
bpy.ops.import_fcstd.import_freecad(directory="/home/gwen/", files=[{"name":"hsfg.FCStd", "name":"hsfg.FCStd"}], option_scale=1)
bpy.data.window_managers["WinMan"].(null) = False

The tree in blender show the Freecad import tag, but empty

But with a trial whitout skip hidden
bpy.ops.import_fcstd.import_freecad(directory="/home/gwen/", files=[{"name":"hsfg.FCStd", "name":"hsfg.FCStd"}], option_skiphidden=False)
It appears the sketch.

A second ask is , how can we choose the mesh size ? (this is why i test this method, .obj give a very huge amount of surfaces, which gives a large file (around 10 Mo for a not complex part) ?

Cheers and thx
AMD FX-6350 (6 core)
32 Go RAM
AMD RX 470 8 Go
Xubuntu 18.04 LTS
FreeCAD Daily (0.19)
Post Reply