Git Product home page Git Product logo

cadquery-vscode's Introduction

VSCode CadQuery extension


Important note:

This extension is no longer compatible with the new version of CadQuery Server. Until this is resolved, please use the LivePreview extension instead:

  1. install LivePreview;
  2. ctrl+shift+P -> Simple Browser: Show
  3. update the url according to your running CadQuery server instance (ie. 127.0.0.1:5000).

VSCode extension that integrates CadQuery Server in VSCode.

CadQuery Server is a web server used to render 3d models from CadQuery code loaded dynamically.

Installation

Install the IDE

The extension works both on VSCodium or VSCode.

Install the extension

In VSCode, search for cadquery in Extensions tab in the sidebar.

The extension is available in:

Alternatively, you can manually install the extension in VSCode by downloading the vsix file from one on both registries.

Install CadQuery Server

Read installation instructions.

Usage

1. Run the CadQuery server

You can configure the server url in the VSCode extension settings (which is http://127.0.0.1:5000 by default).

source venv/bin/activate # required if you used a virtual environment
cq-server

Read usage instructions for advanced use.

2. Activate the extension

Hit f7 to enable the viewer. Alternatively you can use the VSCode command palette (Ctrl+Shift+P) and search for Open CadQuery viewer.

The preview should be updated each time your CadQuery Python script is saved.

3. Tips and tricks

You should use a language server to activate code completion, such as Pylance. Note that in order to make it work on VSCodium, you must set the nameLong value to Visual Studio Code in your product.json (located at /usr/share/codium/resources/app/product.json on Linux).

You can make the UI lighter by enabling VSCode Zen mode by hitting Ctrl+K then Z.

About

cadquery-vscode's People

Contributors

roipoussiere avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cadquery-vscode's Issues

Show syntax errors in your code

Typos, wrong API use, ... will just be hidden behind the cadquery server.
Can this be surfaced in some VS Code output model?

Code completion is failed when adding more than two dots.

For example, when I type:
obj = cq.Workplane('front').box(1,2,3)
the code completion works well. But when adding more dots, such as :
obj = cq.Workplane('front').box(1,2,3).faces('>Z').workplane().hole(0.2)
all the following up methods can not activate code completion.

I am using VSCode v1.71.1 on Windows 10 1809 LTSC, and this plugin is of version 0.1.3 which is the latest.

By the way, I only use this plugin as a CADQuery code completion plugin in VSCode for easily writing .py file. The 3D object is simutaniously being rendered in CQ-Editor by Autoreload function.

Make cq-server port configurable

On a Mac port 5000 is used and I don't want to turn the respective service off.
And sometimes I'd like to also control the host variable. 0.0.0.0 is pretty broad.
So support for cq-server --host 0.0.0.0 --port 4999 or cq-server -h 0.0.0.0 -p 4999 would be highly appreciated.

Move imports to show

The next Jupyter-Cadquery will come with multiprocessing support for large assemblies.
This doesn't work well with flask. I made it run by forcing imports (initializing multiprocessng) being done after start of flask:

import cadquery

from flask import Flask, request


app = Flask(__name__)
json_result = "[{}, {}]"


def show(model):
    global json_result

    from jupyter_cadquery.utils import numpy_to_json
    from jupyter_cadquery.cad_objects import to_assembly
    from jupyter_cadquery.base import _tessellate_group

    json_result = numpy_to_json(_tessellate_group(to_assembly(model)))


@app.route("/", methods=["GET", "POST"])
def root():
    if request.method == "GET":
        return "Please send a CadQuery Python script in a POST request.\n"
    elif request.method == "POST":
        exec(request.get_data().decode())
        return json_result


def run():
    app.run(host="0.0.0.0", port=4999, debug=False)

Is this something you could change?

Refresh when VS Code tab is moved

Before

image

Then I move the CAD tab:

image

So the bottom view is empty now
If I save again, it appears:

image

While the cad adapts to the size of the tab, the objects camera view is sub optimal. Maybe you could reset the camera?
Can be done by calling viewer.reset().

Issue on Windows

Hello, I've tried your extension on Windows and when I want to open the viewer I get this error msg :
Une erreur système s'est produite (ENOENT: no such file or directory, open '/c:/Users/Romain/.vscode/extensions/roipoussiere.cadquery-0.1.2/static/cq-viewer.html')

The problem is due to the first slash before the c:/, the file is actually in the right location, the path is just corrupted due to the linux slash used here.

Help: cq-server won't start after virtual pip install

Hi roipoussiere

I have been using OpenSCAD in VSCodium for a while now, however, as my models become more complex, I am running into performance issues, so I decided to give CadQuery a whirl. I followed your instructions provided and when I tried to start cq-server from the terminal it would not start...
Screenshot from 2022-07-04 13-25-15
As my programming skills are wildly dangerous at best, I am unsure how to proceed. I have thought of following the installation instructions on the CadQuery2 wiki, but would prefer to use VSCodium and preview my files there. I am using a Lenovo Thinkpad X1 Tablet running Fedora 36, Gnome 42, Python 3.10.5 and the latest version of VSCodium. I deleted the venv folder and retried in case I had messed something up. I know that Fedora 36 changed some of the site package installation directories, but I assumed the virtual environment thing would avoid any issues.

Any help resolving this issue would be greatly appreciated.

Thanks
Dorian

Consider a more robust exec approach

exec fails with simple (an natural) approaches:

import cadquery as cq

l = 1
w = 2
h = 3

def box():
    return cq.Workplane().box(l, w, h).edges().fillet(0.1)

show(box())

fails with

  File "<string>", line 9, in box
NameError: name 'cq' is not defined

So let's change it (just for the test, I would never program like that):

l = 1
w = 2
h = 3


def box():
    import cadquery as cq

    return cq.Workplane().box(l, w, h).edges().fillet(0.1)


show(box())

Now, this fails with

  File "<string>", line 9, in box
NameError: name 'l' is not defined

exec just doesn't play well with global variables

Of course, this works:

def box(l=1, w=2, h=3):
    import cadquery as cq

    return cq.Workplane().box(l, w, h).edges().fillet(0.1)

show(box())

However I would need to adapt my style of coding - especially for quick hacks - to the limitations of exec.

Maybe there is a more robust way?

Bug in Orientation or Wrong views?

Hi ,
first i am very new to CAD so excuse my bug report if i made something wrong....

import cadquery as cq

res = cq.Workplane("front").box(50, 50, 50)

res = res + cq.Workplane("front").text("Front", 8, 26)
res = res + cq.Workplane("back").text("Back", 8, 26)
res = res + cq.Workplane("top").text("Top", 8, 26)
res = res + cq.Workplane("bottom").text("Bottom", 8, 26)
res = res + cq.Workplane("left").text("Left", 8, 26)
res = res + cq.Workplane("right").text("Right", 8, 26)

res = res.rotate((0, 0, 0), (1, 0, 0), 90) # Rotates the object 90 degree down so it works without touching in Cura Slicer and Super Slicer
cq.exporters.export(res, "test.step")
cq.exporters.export(res, "test.stl")
res = res.rotate((0, 0, 0), (1, 0, 180), 90)
show(res)

The rotate before exporting step and stl is required so it is aligned with 3d printer slicers.

The rotate before the show is required so i dont have to use the mouse to view to click on it.... so it looks good...

This puts everything in a good perspective....
image

The only problem is the LEFT/RIGHT are opposing.... (TOP, BOTTOM, FRONT, BACK are working correctly)
image

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.