bernhard-42 / vscode-ocp-cad-viewer

A viewer for OCP based Code-CAD (CadQuery, build123d) integrated into VS Code
Apache License 2.0
80 stars 9 forks source link

SystemError: initialization of _internal failed without raising an exception #3

Closed josephbejjani closed 7 months ago

josephbejjani commented 1 year ago

Hello, I successfully installed the OCP CAD Viewer. I am using CadQuery 2 and would like to display my 3D geometry in VS Code. I am receiving the following error when anything, even the example provided within the extension. Any help is appreciated! Thanks, Joseph

Traceback (most recent call last): File "c:\Users\user\Documents\Code\CadQuery\Compressor JB\paraturbo-cad\COMP\Main Function.py", line 5, in from ocp_vscode import * File "C:\ProgramData\Anaconda3\envs\turbocomp\lib\site-packages\ocp_vscode__init.py", line 17, in from .show import ( File "C:\ProgramData\Anaconda3\envs\turbocomp\lib\site-packages\ocp_vscode\show.py", line 17, in from ocp_tessellate import PartGroup File "C:\ProgramData\Anaconda3\envs\turbocomp\lib\site-packages\ocp_tessellate__init__.py", line 21, in from .cad_objects import ( File "C:\ProgramData\Anaconda3\envs\turbocomp\lib\site-packages\ocp_tessellate\cad_objects.py", line 20, in from .ocp_utils import ( File "C:\ProgramData\Anaconda3\envs\turbocomp\lib\site-packages\ocp_tessellate\ocp_utils.py", line 71, in from quaternion import rotate_vectors File "C:\ProgramData\Anaconda3\envs\turbocomp\lib\site-packages\quaternion__init.py", line 31, in from .quaternion_time_series import ( File "C:\ProgramData\Anaconda3\envs\turbocomp\lib\site-packages\quaternion\quaternion_time_series.py", line 10, in from quaternion.numba_wrapper import njit File "C:\ProgramData\Anaconda3\envs\turbocomp\lib\site-packages\quaternion\numba_wrapper.py", line 13, in from numba import njit, jit, vectorize, int64, float64, complex128 File "C:\ProgramData\Anaconda3\envs\turbocomp\lib\site-packages\numba\init__.py", line 42, in from numba.np.ufunc import (vectorize, guvectorize, threading_layer, File "C:\ProgramData\Anaconda3\envs\turbocomp\lib\site-packages\numba\np\ufunc\init__.py", line 3, in from numba.np.ufunc.decorators import Vectorize, GUVectorize, vectorize, guvectorize File "C:\ProgramData\Anaconda3\envs\turbocomp\lib\site-packages\numba\np\ufunc\decorators.py", line 3, in from numba.np.ufunc import _internal SystemError: initialization of _internal failed without raising an exception

josephbejjani commented 1 year ago

I downgraded my version of numpy with no success. Same error displayed again.

bernhard-42 commented 1 year ago

Could you please try without numba? Given that OCP is a C++ library, I would have expected that it doesn't work with numba. So I never tested it

josephbejjani commented 1 year ago

Thank you for the prompt reply. How can I try without numba? I import the following in my code:

import cadquery as cq
import numpy as np
import pandas as pd
from cadquery.selectors import AreaNthSelector
import pickle
from cadquery import *
from cq_warehouse import *
from cq_warehouse.extensions import *
import os

I need numpy to evaluate a parametric function that returns coordinate points which I then plot in 3D space. Thanks a lot!

josephbejjani commented 1 year ago
import cadquery as cq
from Impeller import *

from ocp_vscode import *
set_port(3939)

reset_show()
set_defaults(axes=True, transparent=False, collapse=1, grid=(True, True, True))

Imp = Impeller()
Hub = Imp.hub()
show_object(Hub,options={"alpha":0, "color": (255,0,0)})

This is the code where I call my function. I tried it in cq-editor and it works. I would like to run it in vs code though.

josephbejjani commented 1 year ago

I tried with a simple box. It did not work as well.

import cadquery as cq
from ocp_vscode import show, show_object, reset_show, set_port, set_defaults, get_defaults
set_port(3939)

result = cq.Workplane("front").box(2.0, 2.0, 0.5)

show_object(result)

Small note: I never used numba in my work.

bernhard-42 commented 1 year ago

numpy is OK , but I see this in the stack trace: C:\ProgramData\Anaconda3\envs\turbocomp\lib\site-packages\numba\np\ufunc_init_.py so something installed numba ... Googling for that talks about dependency issues

I just tried after installing numba, your last example still works.

Can you create another fresh environment to test the last example? Looks like some dependencies are maybe broken ...

josephbejjani commented 1 year ago

Thanks a lot! It works. I tried it with several examples. However, for some of them I am receiving this message:

+Traceback (most recent call last):
  File "c:\Users\user\Documents\Code\CadQuery\Compressor JB\paraturbo-cad\Impeller Calling Functions.py", line 37, in <module>
    show_object(Mainblades)
  File "C:\ProgramData\Anaconda3\envs\vs-cad2\lib\site-packages\ocp_vscode\show.py", line 502, in show_object
    show(
  File "C:\ProgramData\Anaconda3\envs\vs-cad2\lib\site-packages\ocp_vscode\show.py", line 335, in show
    data = _convert(
  File "C:\ProgramData\Anaconda3\envs\vs-cad2\lib\site-packages\ocp_vscode\show.py", line 157, in _convert
    instances, shapes, states, config, count_shapes = _tessellate(
  File "C:\ProgramData\Anaconda3\envs\vs-cad2\lib\site-packages\ocp_vscode\show.py", line 53, in _tessellate
    part_group = to_assembly(
  File "C:\ProgramData\Anaconda3\envs\vs-cad2\lib\site-packages\ocp_tessellate\convert.py", line 806, in to_assembly
    pg, instances = _to_assembly(
  File "C:\ProgramData\Anaconda3\envs\vs-cad2\lib\site-packages\ocp_tessellate\convert.py", line 519, in _to_assembly
    part = get_instance(cad_obj.obj, pg.name, rgba, instances, progress)
  File "C:\ProgramData\Anaconda3\envs\vs-cad2\lib\site-packages\ocp_tessellate\convert.py", line 369, in get_instance
    obj, loc = relocate(obj)
  File "C:\ProgramData\Anaconda3\envs\vs-cad2\lib\site-packages\ocp_tessellate\convert.py", line 408, in relocate
    loc = get_location(obj)
  File "C:\ProgramData\Anaconda3\envs\vs-cad2\lib\site-packages\ocp_tessellate\ocp_utils.py", line 768, in get_location
    raise TypeError(f"Unknown location typ {type(loc)}")
TypeError: Unknown location typ <class 'method'>

Any insights about this problem?

bernhard-42 commented 1 year ago

Could you maybe share the code where it happens?

bernhard-42 commented 1 year ago

@josephbejjani Is this still an issue, or can we close it?

josephbejjani commented 1 year ago

Hello. Sorry for the delay and unresponsiveness as I was experimenting with the extension! I couldn't share my code because it is part of a confidential project at the lab I work in. The extension works for when calling some methods in the code, but does not for complicated assemblies with unions, so I am calling those heavy methods in cq-editor instead. Issue can be closed! Thanks again for the support, JB

bernhard-42 commented 1 year ago

hmm, would be nevertheless great to understand what doesn't work. Could you build a simple example not related to your project? It looks like you assign a method where a location is expected.

You seem to have a cadquery assembly. The OCP CAD Viewer code then tries to identify instances (references) to ensure each object is only tessellated once. Therefore it relocates the object to the origin and adds the original location to it separately. This is a critical step and it doesn't expect a method passed instead of a Location or TopLoc_Location.

What is your use case for passing a method instead of a location?

josephbejjani commented 1 year ago

assembly.add(blade[i+1],color=cq.Color('red3'), name = bladename + ' ' + str(i+2))

I think my issue lies in such a command which I run within a loop. Sometimes it works, sometimes not. I run a similar command while defining location but with no naming and it works fine. In any case, this small issue is not hindering my work. Thanks for the follow up! JB

josephbejjani commented 1 year ago

The goal behind this is to name the components so they appear in a CAD software table/tree with their respective names instead of long series of numbers and letters. It indeed works when I open my step in a CAD software (I tried with 2 softwares).

bernhard-42 commented 7 months ago

Since I don't know what to do here, I'll close this issue. Please re-open if it happens to you again