FreeCAD .FCStd importer for Blender 2.80

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
s-light
Posts: 119
Joined: Thu Feb 12, 2015 11:39 am
Location: Germany, Hofheim am Taunus
Contact:

Re: FreeCAD .FCStd importer for Blender 2.80

Post by s-light »

s-light wrote: Wed Oct 30, 2019 9:47 pm this one i can fix easily
or at least i thought so.. :lol:
you would need to rename the folder that is stored inside the zip...

now i have fixed the addon itself -
so it should work now!
(was issues/9)
and updated the readme.

sunny greetings
stefan
alxscott
Posts: 8
Joined: Mon Oct 28, 2019 5:38 pm

Re: FreeCAD .FCStd importer for Blender 2.80

Post by alxscott »

s-light wrote: Thu Oct 31, 2019 1:47 pm
s-light wrote: Wed Oct 30, 2019 9:47 pm this one i can fix easily
or at least i thought so.. :lol:
you would need to rename the folder that is stored inside the zip...

now i have fixed the addon itself -
so it should work now!
(was issues/9)
and updated the readme.

sunny greetings
stefan
lol!! Worked perfectly, thank you very much! :)

Alex
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: FreeCAD .FCStd importer for Blender 2.80

Post by vocx »

s-light wrote: Fri Oct 25, 2019 6:28 pm ...
so in the external listing i get 2 objects less - and this are:
* Body_Hex Body PartDesign::Body
* Pad Pad PartDesign::Pad
...
Do you still have this problem? I think we can call realthunder to take a look at why the objects aren't created.

What exactly is the "external listing"? Is it using FreeCAD as a library?
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
User avatar
s-light
Posts: 119
Joined: Thu Feb 12, 2015 11:39 am
Location: Germany, Hofheim am Taunus
Contact:

Re: FreeCAD .FCStd importer for Blender 2.80

Post by s-light »

vocx wrote: Sat Dec 21, 2019 12:35 am
s-light wrote: Fri Oct 25, 2019 6:28 pm ...
so in the external listing i get 2 objects less - and this are:
* Body_Hex Body PartDesign::Body
* Pad Pad PartDesign::Pad
...
Do you still have this problem? I think we can call realthunder to take a look at why the objects aren't created.

What exactly is the "external listing"? Is it using FreeCAD as a library?
yes - i import with
(source)

Code: Select all

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
List Objects.
Stand-alone
"""

import sys
import os


path_to_freecad = "/usr/lib/freecad-daily-python3/lib/FreeCAD.so"


def append_freecad_path():
    """Append the FreeCAD path."""
    global path_to_freecad
    if os.path.exists(path_to_freecad):
        if os.path.isfile(path_to_freecad):
            path_to_freecad = os.path.dirname(path_to_freecad)
        print("Configured FreeCAD path:", path_to_freecad)
        if path_to_freecad not in sys.path:
            sys.path.append(path_to_freecad)
    else:
        print("FreeCAD path is not correct.")


try:
    try:
        import FreeCAD
    except ModuleNotFoundError:
        append_freecad_path()
    import FreeCAD  # noqa
    print("FreeCAD version:", FreeCAD.Version())
except ModuleNotFoundError as e:
    print("FreeCAD import failed.", e)


# ******************************************
and i just checked - with
`FreeCAD version: ['0', '19', '', 'https://code.launchpad.net/~vcs-imports/freecad/trunk', '2020/01/14 16:28:39']`
its the same.

i think this is not 'a realthunder thing' but more a real FreeCAD *core* thing...
yorik wrote: Wed Oct 09, 2019 6:56 pm Regarding your issues with bodies and not having the same number of objects in a same file, internally and externally: That's pretty worrying! Can you share a test file?

@yorik: what do you mean?

in
https://forum.freecadweb.org/viewtopic. ... 05#p343205
i have some test files linked.
you can directly find theme at:
- https://github.com/s-light/io_import_fc ... dy_objects BodyTest.FCStd
- https://github.com/s-light/io_import_fc ... ittleWorld MyLittleWorld.FCStd
- https://github.com/s-light/io_import_fc ... ng_example assembly_export.FCStd
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: FreeCAD .FCStd importer for Blender 2.80

Post by vocx »

s-light wrote: Wed Jan 15, 2020 5:09 pm i think this is not 'a realthunder thing' but more a real FreeCAD *core* thing...
Yes, but since August last year, realthunder has been changing a lot of the core code. This could be solved by him in a matter of minutes if he identifies the problem.
i have some test files linked.
I've been very lazy on this topic, which admitedly looks serious. However, your first test files and code seemed to me cumbersome. Too much information.

I'd like to ask you to prepare the absolutely simplest test file that you can think of. A single Body, a single feature, and a simple way to show the error.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
User avatar
s-light
Posts: 119
Joined: Thu Feb 12, 2015 11:39 am
Location: Germany, Hofheim am Taunus
Contact:

Re: FreeCAD .FCStd importer for Blender 2.80

Post by s-light »

ok - as you requested -
i stripped all the nice formatting off ;-)
here is the *minimal* version:


Image

BodyTest_Minimal.FCStd
and also attached:
BodyTest_Minimal.FCStd
(14.1 KiB) Downloaded 67 times
copy & paste for FreeCAD python console:
(source)

Code: Select all

import FreeCAD
print("FreeCAD version:", FreeCAD.Version())

objects = FreeCAD.ActiveDocument.Objects

print("doc.Objects", len(objects))

for o in objects:
    print(o, o.Name)
copy & paste for python3 REPL:
(source)

Code: Select all

import sys
path_to_freecad = "/usr/lib/freecad-daily-python3/lib/"
sys.path.append(path_to_freecad)

import FreeCAD
print("FreeCAD version:", FreeCAD.Version())

doc = FreeCAD.open("./BodyTest_Minimal.FCStd")
docname = doc.Name
objects = FreeCAD.ActiveDocument.Objects

print("doc.Objects", len(objects))

for o in objects:
    print(o, o.Name)

FreeCAD.closeDocument(docname)
User avatar
s-light
Posts: 119
Joined: Thu Feb 12, 2015 11:39 am
Location: Germany, Hofheim am Taunus
Contact:

Re: FreeCAD .FCStd importer for Blender 2.80

Post by s-light »

i just retested this with the current stable version

Code: Select all

OS: Ubuntu 20.04.2 LTS (KDE/plasma)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.
Build type: Release
Branch: unknown
Hash: 9e3b630bbfb6807e93eeffb655e6c20f218644fc
Python version: 3.8.5
Qt version: 5.12.8
Coin version: 4.0.0
OCC version: 7.5.1
Locale: English/United States (en_US)
Test:
Freecad GUI

Code: Select all

>>> import FreeCAD
>>> print("FreeCAD version:", FreeCAD.Version())
FreeCAD version: ['0', '19', '', 'git://github.com/FreeCAD/FreeCAD.git unknown', '2021/03/01 00:28:00', 'unknown', '9e3b630bbfb6807e93eeffb655e6c20f218644fc']
>>> 
>>> objects = FreeCAD.ActiveDocument.Objects
>>> 
>>> print("doc.Objects", len(objects))
doc.Objects 10
>>> 
>>> for o in objects:
...     print(o, o.Name)
... 
<body object> Body
<App::Origin object> Origin001
<GeoFeature object> X_Axis001
<GeoFeature object> Y_Axis001
<GeoFeature object> Z_Axis001
<GeoFeature object> XY_Plane001
<GeoFeature object> XZ_Plane001
<GeoFeature object> YZ_Plane001
<Sketcher::SketchObject> Sketch
<PartDesign::Pad> Pad
>>> 
console

Code: Select all

Cstefan@stefan-Zen:~/mydata/github/blender/io_import_fcstd/dev/freecad_test_body_objects (master $)$ python3
Python 3.8.10 (default, Jun  2 2021, 10:49:15) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> path_to_freecad = "/usr/lib/freecad/lib/"
>>> sys.path.append(path_to_freecad)
>>> 
>>> import FreeCAD
Sheet Metal workbench loaded
Loading Assembly4 WorkBench
Interlocking laser cut workbench loaded
>>> print("FreeCAD version:", FreeCAD.Version())
FreeCAD version: ['0', '19', '', 'git://github.com/FreeCAD/FreeCAD.git unknown', '2021/07/21 08:10:00', 'unknown', '0d9536ed3e8c7f40197b5606e1b7873625e1d6fe']
>>> 
>>> doc = FreeCAD.open("./BodyTest_Minimal.FCStd")
>>> docname = doc.Name
>>> objects = FreeCAD.ActiveDocument.Objects
>>> 
>>> print("doc.Objects", len(objects))
doc.Objects 8
>>> 
>>> for o in objects:
...     print(o, o.Name)
... 
<App::Origin object> Origin001
<GeoFeature object> X_Axis001
<GeoFeature object> Y_Axis001
<GeoFeature object> Z_Axis001
<GeoFeature object> XY_Plane001
<GeoFeature object> XZ_Plane001
<GeoFeature object> YZ_Plane001
<Sketcher::SketchObject> Sketch
>>> FreeCAD.closeDocument(docname)
>>> 

still the body object is missing.



to test the same with appimage weekly build i first have to find ways to get it to work... details later
User avatar
s-light
Posts: 119
Joined: Thu Feb 12, 2015 11:39 am
Location: Germany, Hofheim am Taunus
Contact:

Re: FreeCAD .FCStd importer for Blender 2.80

Post by s-light »

i just found the missing thing:

i need to add the Mod subfolder to the sys paths
then the Body Objects are there :-)

Code: Select all

import sys
import os

path = "/usr/lib/freecad/lib"
sys.path.append(path)

import FreeCAD
print("FreeCAD version:", FreeCAD.Version())

path_base = FreeCAD.getResourceDir()
path = os.path.join(path_base, "Mod")
sys.path.append(path)

doc = FreeCAD.open("./BodyTest_Minimal.FCStd")
docname = doc.Name
objects = FreeCAD.ActiveDocument.Objects

print("doc.Objects", len(objects))

for o in objects:
    print(o, o.Name)

FreeCAD.closeDocument(docname)

output

Code: Select all

io_import_fcstd/dev/freecad_test_body_objects (master *$%)$ python3
Python 3.8.10 (default, Jun  2 2021, 10:49:15) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> import os
>>> 
>>> path = "/usr/lib/freecad/lib"
>>> sys.path.append(path)
>>> 
>>> import FreeCAD
Sheet Metal workbench loaded
Loading Assembly4 WorkBench
Interlocking laser cut workbench loaded
>>> print("FreeCAD version:", FreeCAD.Version())
FreeCAD version: ['0', '19', '', 'git://github.com/FreeCAD/FreeCAD.git unknown', '2021/07/21 08:10:00', 'unknown', '0d9536ed3e8c7f40197b5606e1b7873625e1d6fe']
>>> 
>>> path_base = FreeCAD.getResourceDir()
>>> path = os.path.join(path_base, "Mod")
>>> sys.path.append(path)
>>> 
>>> doc = FreeCAD.open("./BodyTest_Minimal.FCStd")
>>> docname = doc.Name
>>> objects = FreeCAD.ActiveDocument.Objects
>>> 
>>> print("doc.Objects", len(objects))
doc.Objects 10
>>> 
>>> for o in objects:
...     print(o, o.Name)
... 
<body object> Body
<App::Origin object> Origin001
<GeoFeature object> X_Axis001
<GeoFeature object> Y_Axis001
<GeoFeature object> Z_Axis001
<GeoFeature object> XY_Plane001
<GeoFeature object> XZ_Plane001
<GeoFeature object> YZ_Plane001
<Sketcher::SketchObject> Sketch
<PartDesign::Pad> Pad
>>> FreeCAD.closeDocument(docname)
>>> 
>>> 

drmacro
Veteran
Posts: 8982
Joined: Sun Mar 02, 2014 4:35 pm

Re: FreeCAD .FCStd importer for Blender 2.80

Post by drmacro »

In reading the Readme on the github repository, it says use git clone to get the code.

I cloned into the Blender scripts/addon directory and then can see it in Blender Preferences Addons.

But, when I check the activate, I get a trace back.

Code: Select all

raceback (most recent call last):
  File "/usr/share/blender/scripts/modules/addon_utils.py", line 331, in enable
    mod = __import__(module_name)
  File "/usr/share/blender/scripts/addons/io_import_fcstd/__init__.py", line 9, in <module>
    from . import import_fcstd
  File "/usr/share/blender/scripts/addons/io_import_fcstd/import_fcstd/__init__.py", line 18, in <module>
    from .material import MaterialManager
  File "/usr/share/blender/scripts/addons/io_import_fcstd/import_fcstd/material.py", line 7, in <module>
    from bpy_extras.node_shader_utils import PrincipledBSDFWrapper
ModuleNotFoundError: No module named 'bpy_extras.node_shader_utils'

I build FreeCAD from source. Is this messing with the workings of the addon process?
(I have confirmed both my FreeCAD 0.20 and Blender 2.79 are using 3.7 Python.)
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
Syres
Veteran
Posts: 2899
Joined: Thu Aug 09, 2018 11:14 am

Re: FreeCAD .FCStd importer for Blender 2.80

Post by Syres »

drmacro wrote: Thu Aug 26, 2021 1:22 pm I build FreeCAD from source. Is this messing with the workings of the addon process?
(I have confirmed both my FreeCAD 0.20 and Blender 2.79 are using 3.7 Python.)
It's not the FreeCAD side that's the problem, it's your using Blender 2.79, you should be using the last official Python 3.7.x Blender build which is 2.92. @Yorik originally rewrote the importer code because to the best of my knowledge the registering of Addons changed too much between 2.79 and 2.80 that they weren't compatible, Is there something in 2.79 that you specifically need???
Post Reply