freecadcmd doesn't produce Arch objects

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
martnaum
Posts: 1
Joined: Fri Dec 03, 2021 2:26 pm

freecadcmd doesn't produce Arch objects

Post by martnaum »

Hey together,

I just experimented with FreeCAD, it's GUI and its headless freecadcmd. I observed, that the headless execution of the following script leads to a model that differs from the model created when the script is executed within the FreeCAD UI. Is this due to the lack of GUI-concepts within the headless execution? On the other hand I read the response from yorik here (https://forum.freecadweb.org/viewtopic.php?t=28559, "both should work perfectly without the GUI") which gives me the feeling that I am doing something wrong.
The script:

Code: Select all

import FreeCAD, Draft, Arch

FreeCAD.newDocument("test")

p1 = FreeCAD.Vector(0, 0, 0)
p2 = FreeCAD.Vector(2000, 0, 0)
baseline = Draft.makeLine(p1, p2)

Arch.makeWall(baseline, length=None, width=200, height=2000)

FreeCAD.activeDocument().recompute()
FreeCAD.ActiveDocument.saveAs("test_arch.FCStd")
Executed with

Code: Select all

/c/"Program Files"/"FreeCAD 0.19"/bin/FreeCAD.exe -P . test_arch.py
(we can see Arch objects here as modelled in the script):
freecad.png
freecad.png (58.15 KiB) Viewed 1078 times
Executed with

Code: Select all

/c/"Program Files"/"FreeCAD 0.19"/bin/FreeCADCmd.exe -P . test_arch.py
, opened the test_arch.FCStd in FreeCAD afterwards:
freecadcmd.png
freecadcmd.png (58.95 KiB) Viewed 1078 times
Any ideas what I am missing here?
Last edited by martnaum on Mon Dec 06, 2021 11:49 am, edited 1 time in total.
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: freecadcmd doesn't produce Arch objects

Post by onekk »

Code: Select all

"""
Test file copyright 2021 Dormeletti Carlo

This file is an example and could not be used in a 
commercial product without expplicit consent
"""

import FreeCAD
from FreeCAD import Vector, Rotation

import Arch
import Draft
import Part

DOC = None
DOC_NAME = "test"

def clear_doc():
    """
    Clear the active document deleting all the objects
    """
    for obj in DOC.Objects:
        try:
            DOC.removeObject(obj.Name)
        except Exception:
           pass

def setview():
    """Rearrange View"""

    FreeCAD.Gui.activeDocument().activeView().viewAxometric()
    FreeCAD.Gui.activeDocument().activeView().setAxisCross(True)
    DOC.recompute()
    FreeCAD.Gui.SendMsgToActiveView("ViewFit")

if DOC is None:
    FreeCAD.newDocument(DOC_NAME)
    FreeCAD.setActiveDocument(DOC_NAME)
    DOC = FreeCAD.activeDocument()

else:

    clear_doc()


# EPS= tolerance to uset to cut the parts
EPS = 0.10
EPS_C = EPS * -0.5
VZOR = Vector(0,0,0)

p1 = VZOR
p2 = Vector(2000, 0, 0)
baseline = Draft.makeLine(p1, p2)

Arch.makeWall(baseline, length=None, width=200, height=2000)

DOC.recompute()
DOC.saveAs("test_arch.FCStd")

setview()
Using the code in a script is correctly created, but:

OS: Artix Linux (openbox)
Word size of FreeCAD: 64-bit
Version: 0.20.26498 (Git) AppImage
Build type: Release
Branch: (HEAD detached at 1895593)
Hash: 18955931c7f0926a4cd9d2719be5a433b49ae56e
Python version: 3.9.7
Qt version: 5.12.9
Coin version: 4.0.0
OCC version: 7.5.3
Locale: Italian/Italy (it_IT)

Also a little note, the commands lines you reported seems identical, maybe using then in a code tag will preserve spaces and other things that maybe are missing when putting them as "normal text".

Something things are different with a missing or an added space.

Hope it could help.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
paullee
Veteran
Posts: 5098
Joined: Wed May 04, 2016 3:58 pm

Re: freecadcmd doesn't produce Arch objects

Post by paullee »

Seem the Class object Line and Wall are not successfully created? Recompute the baseline object before Arch.makeWall()?
yorik wrote: Ping
See if @yorik has a gap to have a look?
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: freecadcmd doesn't produce Arch objects

Post by yorik »

This is normal. When you create objects via the python (no-GUI) interface, only the App part of objects is handled. Everything that is GUI-related is simply not used at all. As a result, no view providers are used or saved to the file.

If you look at your two "blue cubes" objects in the FreeCAD UI, they are still functional Line and Wall. The App properties are there and they work. Only all the visual part (including the icon) is not there. Which makes sense, as it was all created without it.

This, for example, adds a ViewProvider to the wall object afterwards (in the GUI):

Code: Select all

wall = FreeCAD.ActiveDocument.getObject("Wall")
import ArchWall
ArchWall._ViewProviderWall(wall.ViewObject)
One needs to hide/show the wall in the tree afterwards to update the icon.

What we could do is add some code to Draft and Arch objects that, on load, in case GUI is available but no ViewProvider is present, add a ViewProvider to the object. I think in principle that should be simple to do, but requires some testing to be sure everything works and no race condition exists...
Post Reply