Git Product home page Git Product logo

Comments (4)

howetuft avatar howetuft commented on June 30, 2024 3

Hello,

YES! A few months ago, I made special effort to have so (so I'm pleased to find a client today ;-))
This script should demonstrate the capability, just copy/past in the console:

from os import path
import Render

# Adapt the 2 following lines if you want to change renderer
# Caveat: we assume that the external renderer program has been correctly
# installed and the path to that program has been correctly set in FreeCAD
# parameters

RENDERER, TEMPLATE = "Povray", "povray_standard.pov"
# RENDERER, TEMPLATE = "Luxcore", "luxcore_standard.cfg"
# RENDERER, TEMPLATE = "Cycles", "cycles_standard.xml"
# RENDERER, TEMPLATE = "Pbrt", "pbrt_standard.pbrt"


# Create a new doc
doc = App.newDocument("RenderTest")

# Create a rendering project
template_path = path.join(Render.WBDIR, "templates", TEMPLATE)  # This could be made more user-friendly...
_, proj, _ = Render.Project.create(doc, renderer=RENDERER, template=template_path)
proj.GroundPlane = True

# Create an object and add its view to project
box = doc.addObject("Part::Box", "Box")
box.recompute()
proj.Proxy.add_view(box)

# Create a camera, position it and add its view to project
_, cam, _ = Render.Camera.create(doc)
cam.Placement = App.Placement(App.Vector(40, -30, 50), App.Rotation(App.Vector(-0.7, -0.3, -0.6), 300))
proj.Proxy.add_view(cam)

# Render
# wait_for_completion should be set to True if freecadcmd is launched in script
# mode, otherwise freecad will exit without completing rendering.
# to the contrary, in interactive console mode, wait_for_completion may be better
# set to False (default)
img = proj.Proxy.render(wait_for_completion=True)
print(f"Done: {img}\n")

Can you let me know if it is OK for you?

from freecad-render.

adizhol avatar adizhol commented on June 30, 2024 1

cool! It's worth adding these steps to the Wiki/documentation pages.

Basically I want to render floor plan from 2d floor plans

from freecad-render.

adizhol avatar adizhol commented on June 30, 2024

@howetuft cool! Thanks!
I will try it later.
How to I initialize "App" ?
Can I call Renderer APIs in a detached python console - not within FreeCAD?

from freecad-render.

howetuft avatar howetuft commented on June 30, 2024

How to I initialize "App" ?

Basically, it's already defined in FreeCAD console.
But if you want to redefine it explicitly:

import FreeCAD as App

Can I call Renderer APIs in a detached python console - not within FreeCAD?

Yes, there are 2 solutions:

  1. Use freecadcmd, the console version of FreeCAD. It does not open a GUI, just a console. You can also pass the script as a command-line argument - no console open, just run the script.
  2. Import FreeCAD in a standard Python interpreter. It's more tricky, as you must make Python aware of FreeCAD installation. To do that, you have to add this in the header of the above script:
import sys
sys.path.append("your/path/to/your/freecad/libs")
import FreeCAD as App

For instance, on my Arch Linux system, it resolves into

import sys
sys.path.append("/usr/lib/freecad/lib")
import FreeCAD as App

Just out of curiosity, what is your use case precisely?

from freecad-render.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.