Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show_object works only in the CQ-editor not in imported files #466

Open
DeBalog opened this issue Dec 26, 2024 · 2 comments
Open

show_object works only in the CQ-editor not in imported files #466

DeBalog opened this issue Dec 26, 2024 · 2 comments

Comments

@DeBalog
Copy link

DeBalog commented Dec 26, 2024

I have a file in CQ Editor containing the invoker code:

import cadquery as cq
import os
import sys

lib_path = os.path.abspath("./")  # relativer Pfad zu einem absoluten Pfad umwandeln
if lib_path not in sys.path:
    sys.path.append(lib_path)

from show_test import *

which is just importing show_test.py.

show_test.py contains:

import cadquery as cq
show_object (cq.Workplane ("XY").box(30,20,10))

Running the invoker in CQ-Editor brings up the following error:
grafik
NameError: name 'show_object' is not defined

The same code works fine if it is directly in CQ-Editor.

This is a big nuisance because I need show_object for debugging and my project is spread across multiple files.

Is there a simple solution to use show_object in a file which is invoked from CQ-Editor but which is not in CQ-Editor directly?

I use
grafik
on Windows 11.

@jmwright
Copy link
Member

Hi @DeBalog

Here is one way to solve the issue (pass the show_object function around):

# Script running inside CQ-editor
from second_module import make_box

make_box(show_object)
# Imported module ("second_module")
import cadquery as cq

def make_box(show_object):
    print(globals())
    result = cq.Workplane().box(10, 10, 10)

    show_object(result)

I also tried injecting show_object into globals() which works in some contexts, but does not seem to in this one.

@DeBalog
Copy link
Author

DeBalog commented Dec 29, 2024

Hi @jmwright, thanks for you solution, I give it a try and report here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants