Code Monkey home page Code Monkey logo

pythonocc-demos's Introduction

Codacy Badge

Some pythonocc related code snippets, examples, jupter notebooks etc.

Requirements :

  • pythonocc-core 7.8.1
conda install -c conda-forge pythonocc-core=7.8.1
  • jupyter if you want to test the jupyter notebooks, as well as pythreejs.

Repository structure :

  • assets: 2D images, 3D modules in various formats. Used by the python scripts

  • examples: small python scripts that each describe a pythonocc feature

    $ cd examples  
    $ python core_helloworld.py
  • jupyter_notebook: a set of examples running pythonocc inside a jupyter notebook.
    $ cd jupyter_notebooks  
    $ jupyter notebook

pythonocc-demos's People

Contributors

botengu avatar ed-k avatar jkbgbr avatar karl-nilsson avatar kleinsimon avatar okanpinar avatar rainman110 avatar rayfoundry avatar robincpc avatar tanneguydv avatar therealsupermario avatar thorade avatar tpaviot avatar

Stargazers

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

Watchers

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

pythonocc-demos's Issues

How to extrude a surface from a curve?

Hi, @tpaviot

I am just a new comer to opencascade.

I am trying to add the Support of an anEdge in BRepFill_Filling.Add. And I would like to extrude the edge to get the supporting surface. But I have not found a function to do so.

Is there any function to use?

Thanks!

Invisible JupyterRenderer?

Dear Thomas, all,

when using

from OCC.Display.WebGl.jupyter_renderer import JupyterRenderer

I get an invisible / empty viewer in Jupyter on all browsers for all .ipynb starting from helloworld.ipynb .

  • "naked" pythreejs demos are working
  • "naked" ipywidgets are working (I get a number of widgets at the top of the viewer gadget

image

Have you encountered this before? What might be a good direction to hunt for this issue? should I maybe look into the "new" pythoncc-core?

Thank you very much in advance! And thank you for all your great work!

conda env not working after conda install

Hi all

After
conda install -c conda-forge -c dlr-sc -c pythonocc -c oce pythonocc-core==0.18.1

conda env cannot be used any more.

Even for conda list, I get

system cannot find the path specified

Any suggestions what causes this?

Regards
johannes

System: Win 10
conda version : 4.5.11
conda-build version : 3.4.1
python version : 3.6.4.final.0

Solving environment: done

environment location: \Anaconda3\envs\oce

added / updated specs:
- pythonocc-core==0.18.1

The following packages will be downloaded:

package                    |            build
---------------------------|-----------------
setuptools-40.6.2          |           py36_0         585 KB  conda-forge

The following NEW packages will be INSTALLED:

ca-certificates: 2018.10.15-ha4d7672_0 conda-forge
certifi:         2018.10.15-py36_1000  conda-forge
freeimageplus:   3.17.0-vc14_0         dlr-sc      [vc14]
freetype:        2.7-vc14_1            conda-forge [vc14]
gl2ps:           1.3.8-vc14_3          dlr-sc      [vc14]
icu:             58.2-vc14_0           conda-forge [vc14]
jpeg:            9b-vc14_2             conda-forge [vc14]
libpng:          1.6.34-vc14_0         conda-forge [vc14]
oce:             0.18.2-vc14h5f3c129_1 oce         [vc14]
openssl:         1.0.2o-vc14_0         conda-forge [vc14]
pip:             18.1-py36_1000        conda-forge
pyqt:            5.6.0-py36h764d66f_7  conda-forge
python:          3.6.6-he025d50_0      conda-forge
pythonocc-core:  0.18.1-py36_vc14_110  pythonocc   [vc14]
qt:              5.6.2-vc14_1          conda-forge [vc14]
setuptools:      40.6.2-py36_0         conda-forge
sip:             4.18.1-py36h6538335_0 conda-forge
smesh:           6.7.5-vc14hfb33b19_0  pythonocc   [vc14]
tbb:             2017_20170226-vc14_0  conda-forge [vc14]
vc:              14-0                  conda-forge
vs2015_runtime:  14.0.25420-0          conda-forge
wheel:           0.32.2-py36_0         conda-forge
wincertstore:    0.2-py36_1002         conda-forge
zlib:            1.2.11-vc14_0         conda-forge [vc14]

Face recognition from step file example crashes

python core_geometry_face_recognition_from_stepfile.py
INFO:OCC.Display.backend:backend loaded: qt-pyqt5
INFO:OCC.Display.SimpleGui:GUI backend set to: qt-pyqt5
 ###### 3D rendering pipe initialisation #####
Display3d class initialization starting ...
Aspect_DisplayConnection created.
Graphic_Driver created.
V3d_Viewer created.
AIS_InteractiveContext created.
V3d_View created
Cocoa window created.
Display3d class successfully initialized.
 ########################################
 **  Model Complete Check List  **
Check:1 -- Entity (n0:id) 543:#552   Type:POINT_STYLE
Parameter n0.2 (marker) : Entity has illegal type
Face selected:  <class 'TopoDS_Compound'>
Traceback (most recent call last):
  File "/Users/blah/anaconda3/envs/opencad/lib/python3.7/site-packages/OCC/Display/qtDisplay.py", line 232, in mouseReleaseEvent
    self._display.Select(pt.x(), pt.y())
  File "/Users/blah/anaconda3/envs/opencad/lib/python3.7/site-packages/OCC/Display/OCCViewer.py", line 620, in Select
    callback(self.selected_shapes, X, Y)
  File "core_geometry_face_recognition_from_stepfile.py", line 108, in recognize_clicked
    recognize_face(topods_Face(shape))
RuntimeError: Standard_TypeMismatch
TopoDS::Face
wrapper details:
  * symname: topods_Face
  * wrapname: _wrap_topods_Face__SWIG_0
  * fulldecl: TopoDS_Face const TopoDS::Face(TopoDS_Shape const &)
Abort trap: 6

SVG rendering functions missing in display_as_svg notebook

Hello,

We have discovered in a freshly installed pythonocc-core (7.4.0rc1) on conda that the two functions required by the display_as_svg jupyter notebook example are not present in the library:

import os

from OCC.Core.gp import gp_Dir
from OCC.Display.WebGl.jupyter_renderer import JupyterRenderer
from OCC.Extend.DataExchange import read_step_file, export_shape_to_svg

results in

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-9-13466bb7a556> in <module>
      3 from OCC.Core.gp import gp_Dir
      4 from OCC.Display.WebGl.jupyter_renderer import JupyterRenderer
----> 5 from OCC.Extend.DataExchange import read_step_file, export_shape_to_svg

ImportError: cannot import name 'export_shape_to_svg' from 'OCC.Extend.DataExchange' (/home/artonson/miniconda3/envs/occ/lib/python3.7/site-packages/OCC/Extend/DataExchange.py)

and

my_renderer.DisplayShapeAsSVG(robot_shp, direction=gp_Dir(1, 1, 0.1),
                              export_hidden_edges=False,
                              line_width=1.5)

yields

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-8-515d1b0f4da5> in <module>
----> 1 my_renderer.DisplayShapeAsSVG(robot_shp, direction=gp_Dir(1, 1, 0.1),
      2                               export_hidden_edges=False,
      3                               line_width=1.5)

AttributeError: 'JupyterRenderer' object has no attribute 'DisplayShapeAsSVG'

Platform: Linux 16.04
conda 4.6.14

Can you comment on where things could have gone wrong?

Kind regards,
Alexey

automatic recognition of screws

Hi,
i need your help.
I started a new programm and want to recognise if my STEP file is a screw, also i want to extract the name out of the header section.
I m using
from OCC.Extend.DataExchange import read_step_file
to read my file.
Can someone help me? I just need some hints
Greetings
Egon

core_topology_faces has some color typos

In core_topology_faces.py, on line 66, you mention the brown face, and then proceed to make a brownFace.Face() object
But then on line 122, you give it the color blue. Shouldn't the object be named as BlueFace for consistency with the color pythonOCC actually renders it in?

The problem with create Viewer3d on Ubuntu 20.04 LTS VM Google Cloud Platform

I am working with python 3.8.5 and pythonocc-core 7.5.1 on Ubuntu VM, Google Cloud Platform
and I am trying covert shape to png by offscreen_rendering

The error when I am trying create the renderer: offscreen_renderer = Viewer3d()

Exception Type: 	RuntimeError
Exception Value: 	Aspect_DisplayConnectionDefinitionErrorCan not connect to the server "" raised from method Display3d of class Display3d

Exception Location: 	/home/username/miniconda3/lib/python3.8/site-packages/OCC/Core/Visualization.py, line 166, in __init__
Python Executable: 	/home/username/miniconda3/bin/python
Python Version: 	3.8.5

/home/username/miniconda3/lib/python3.8/site-packages/OCC/Display/OCCViewer.py, line 120, in __init__
Display3d.__init__(self)

/home/username/miniconda3/lib/python3.8/site-packages/OCC/Core/Visualization.py, line 166, in __init__
_Visualization.Display3d_swiginit(self, _Visualization.new_Display3d())

Thank you for your help!

Error in Example File: core_geometry_oriented_bounding_box

Hi,

While trying to understand how to display bounding box of shapes, I discovered that the example core_geometry_oriented_bounding_box doesn't run through.

Error message prompt:
Exception has occurred: RuntimeError
"Standard_ConstructionErrorgp_Dir() - input vector has zero norm raised from method gp_Dir of class gp_Dir"
"RuntimeError: Standard_ConstructionErrorgp_Dir() - input vector has zero norm raised from method gp_Dir of class gp_Dir"

I believe the error is on line 44, with both gp_Dir(aZDir) and gp_Dir(aXDir)

Thank you for the work

Width in TopodsWires and selection in AIS_line

Hello Sir.

I am currently working on a project with pythonocc==7.5.1 where I am modeling a 2D object which can be written as multiple lines. I need to be able to do two things at the same time:

  • Find out which of the lines was selected by the user on the viewer
  • Change the width of the lines

I tried two different methods, but neither satisfy both of the previous requirements:

  1. Creating the lines as wires: I get the information on which wire was selected, but I can't seem to change its aspect
  2. Creating the lines as AIS_lines: I can change the width, but can't get any information on which line was selected

Could you please give me any suggestions to be able to solve this issue? I thank you in advance for any insight you might provide!

Here is a simple example to demonstrate the issue I am having.

import numpy as np
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeEdge, BRepBuilderAPI_MakeWire
from OCC.Core.gp import gp_Pnt
from OCC.Core.TopoDS import TopoDS_Wire
from OCC.Core.Quantity import Quantity_Color, Quantity_TOC_RGB
from OCC.Core.Geom import Geom_CartesianPoint
from OCC.Core.AIS import AIS_Line
from OCC.Core.Prs3d import Prs3d_LineAspect

def on_click(shapes, *kwargs):
    
    if len(shapes) == 0:
        # AIS LINE ARE NOT CAUGHT! Shape is an empty list
        print("On click ===> Empty shape list!")

    for shape in shapes:  
        if isinstance(shape, TopoDS_Wire):
            # WIRES ARE CAUGHT HERE
            print("On click ===> TopoDS_Wire!")


def display_lines_as_wires(lines):

    for [x1,y1],[x2,y2] in lines:
        wire = BRepBuilderAPI_MakeWire()
        edge = BRepBuilderAPI_MakeEdge(gp_Pnt(x1, y1, 0), gp_Pnt(x2, y2, 0)).Edge()
        wire.Add(edge)

        display.DisplayShape(wire.Shape(), update=False, color="RED")


def display_ais_lines(lines):

    width = 5.
    color = Quantity_Color(13/255, 13/255, 203/255, Quantity_TOC_RGB)

    for [x1,y1],[x2,y2] in lines:

        ais_line = AIS_Line(
            Geom_CartesianPoint(x1,y1,0),Geom_CartesianPoint(x2,y2,0)
        )
        drawer = ais_line.Attributes()
        aspect = Prs3d_LineAspect(color, 0, width)
        drawer.SetLineAspect(aspect) 
        ais_line.SetAttributes(drawer)

        display.Context.Display(ais_line, False)


if __name__ == "__main__":

    points = np.random.normal(size=(5,2))
    lines = np.array([[points[i], points[i+1]] for i in range(len(points)-1)])
    offset_lines = lines + 4

    from OCC.Display.SimpleGui import init_display
    display, start_display, add_menu, add_function_to_menu = init_display()

    display_ais_lines(lines)
    display_lines_as_wires(offset_lines)
    display.register_select_callback(on_click)
    display.FitAll()
    start_display()

BUG about core_display_pbr.py

When run this program, a bug appears:

File "C:/workspaces/python/pythonocc-demos/examples/core_display_pbr.py", line 81, in <module>
    display.DisplayShape(bottle, material=alu_pbr_aspect)

  File "C:\ProgramData\Anaconda3\envs\OCCT751\lib\site-packages\OCC\Core\Graphic3d.py", line 14867, in __init__
    _Graphic3d.Graphic3d_MaterialAspect_swiginit(self, _Graphic3d.new_Graphic3d_MaterialAspect(*args))
TypeError: Wrong number or type of arguments for overloaded function 'new_Graphic3d_MaterialAspect'.
  Possible C/C++ prototypes are:
    Graphic3d_MaterialAspect::Graphic3d_MaterialAspect()
    Graphic3d_MaterialAspect::Graphic3d_MaterialAspect(Graphic3d_NameOfMaterial const)

Hope u can give the answer.
Env:

  • pythonocc-core 7.5.1
  • OS: win10

No text in example "Core-Geometry-axis.py"

As I understand it, displayMessage should display text. But in the example program, core_geometery_axis.py no text is being displayed by lines:

display.DisplayMessage(p1, "P1")
display.DisplayMessage(p2, "P2")

Maybe some arguments are missing ?

core_export_stl.py problem

Hello Sir.

I wanted to ask is it possible for the core_export_stl example to put under function. I try to put it under a function but the "display, start_display, add_menu, add_function_to_menu = init_display()" line is unable. Do you have any suggestion about this problem?

Thank you.

Displaying CAD in VTK

I'm not sure if this is the right place to look, but here's hoping.

I'm interested in using pythonocc to update existing CAD (e.g., add some lines/surfaces, mesh geometry) and display that alongside a VTK model inside a QVTKRenderWindowInteractor.

I looked through the examples and didn't see anything like that. Do you have any suggestions of how to do that or have an example (even if the data is not consistent)?

Example for automatically sizing the Display3d widget?

Hi there,

I'm having a hard time getting the display in PyQt5 to fully fit into a window. If I resize the window, it then works great.

I've tried:

  • self.display.ResetView()
  • self.display.View.MustBeResized()
  • self.layout().addWidget(self.canvas, stretch=1)

Any other suggestions?

example of a demo that still contains OCC.core.*

Based on your comment to my issue on pythonocc-core, I was expecting to see the import commands to be updated. Check this one out.. It still contains:

from OCC.Core.BRepTools import breptools_Read
from OCC.Core.TopoDS import TopoDS_Shape
from OCC.Core.BRep import BRep_Builder

After deleting the subdirectory core from the import commands, the demo apparently runs fine.

from OCC.BRepTools import breptools_Read
from OCC.TopoDS import TopoDS_Shape
from OCC..BRep import BRep_Builder

Can you comment?
Thanks.

Wrong BoundingBox dimension extraction

I am trying to extract box dimensions from the STP file and it's worked for a some of the samples, but unfortunately, I got the wrong extraction for the other samples for example below zipped STP file

Test.zip

I got this results value for "x": 6.802000200000001
and the right one is 6.24, and so on for y and z values.

and here is my code

from __future__ import print_function

from OCC.Extend.DataExchange import read_step_file
from OCC.Core.IFSelect import IFSelect_RetDone
from OCC.Core.Bnd import Bnd_Box
from OCC.Core.BRepBndLib import brepbndlib_Add
from OCC.Core.BRepMesh import BRepMesh_IncrementalMesh
from OCC.Core.STEPControl import STEPControl_Reader

shapes = read_step_file('path/to/stpfile')

def read_stp_file(file_path):
	step_reader = STEPControl_Reader()
	status = step_reader.ReadFile(file_path)
	if status == IFSelect_RetDone:
		fails_only = False
		step_reader.TransferRoots()
		shape = step_reader.Shape(1)
		return shape
	else:
		print("Error: can't read file.")

bbox = Bnd_Box()
use_mesh = True
mesh = BRepMesh_IncrementalMesh()
mesh.SetParallelDefault(True)
mesh.SetShape(shapes)
mesh.Perform()
assert mesh.IsDone()
brepbndlib_Add(shapes, bbox, use_mesh)
xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get()
print('x value : >>>> ', xmax - xmin)

Get Volume of Stepfile

Hello,

is it possible to get the volume of a model in a step-file using occ?

thanks for your help!

License

Hi there! I think I am missing the license information here for the repo.

Can you provide more information for code and the example models?

BR

Show STEP-file in GUI

Hello,
I have written a code in which I evaluate STEP-files and search for certain features. To improve the GUI, I would like to display the CAD model. I think I have seen the code here before, but I can't find it anymore. I would be very grateful for your help.
Greetings
Egon

Converting STP/STEP to x3d

Hi there,

I stumbled upon this repo when I was looking for a way to convert STP to x3d. I found some documentations [(https://pythonocc-doc.readthedocs.io/en/latest/convert/ )] but it seems that the code in this particular example is not longer supported and I can't find any other examples in this repo that shows a similiar procedure to convert STP to x3d. Is it still possible to use pythonocc to convert STP to x3d or is it not longer supported?

Best regards,
C

STEP file compound naming problem

I'm using core_load_step_with_colors.py to resolve the structure of names of a step file.
I get the names using function GetLabelName() of a label.
But it sometimes returns "COMPOUND" or "SOLID" as the name.
As other software like 3d-tool that compound does actually have a name.
I wonder is there any way to solve this naming problem.
Thank you!

this is not a bug but demo requests.

I was wondering if you kindly give a demo of OCAF and AIS_ViewController.
These demos and the python port have been extremely helpful. sorry for requesting stuff from here, I dont know how else I could have contacted you. Thanks a lot.

Error when using JupyterRenderer

I am a beginner in PyOCC. I try to use JupyterRenderer, and write a demo as below:
from OCC.Display.WebGl.jupyter_renderer import JupyterRenderer
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox

box = BRepPrimAPI_MakeBox(1.0, 1.0, 1.0).Shape()

renderer = JupyterRenderer()
renderer.DisplayShape(box, render_edges=True)
renderer.Display()

I get a error, I have no idea how to fit it. I use 7.7.0, It would be my honor to receive your assistance.
image

Reading JT files

Hi, I am just looking for advice.
Is there a way to import JT (jupiter tessellation) files into pythonocc-core?

DLL load failed while importing _STEPControl

Hello Thomas,
When I tried to run the pythonocc-demos example "core_geometry_face_recognition_from_stepfile.py", I got the following dll error.
DLL load failed while importing _STEPControl
My installed packages are as follow:
Python >= 3.8.5
Pytorch >= 1.6.0
Tensorboard >= 2.3.0
Torch-geometric >= 1.6.1
Numpy >= 1.21.2
pythonocc-core >= 7.5.1

I have attached the error. Could you please suggest me how to solve this error to run your code.

Thanking you
キャプチャ
)

Effective way to update the display?

We're looking to improve our 3D viewer's response and I had a few questions regarding it:

  • pythonocc seems to use Erase to remove shapes from the display, but OpenCascade's documention shows that it only hides the shape, doesn't delete it. Wouldn't it be better to RemoveAll() instead?
  • is there a demo on how to update an existing shape in the viewer?
  • importing a small (2kB) mesh takes a very long time to add via display.DisplayShape(shape), is there a way to reduce the loading time? Like convert the mesh's shape into another object and then load it?

Problem with some demos

I have installed pythonocc-core from the master branch of the git repo. Everything works, but some demos are giving me some errors. For the file examples/core_display_export_EF.py, for example, I can correct this with the following modification:

--- a/examples/core_display_export_to_EF.py
+++ b/examples/core_display_export_to_EF.py
@@ -27,7 +27,7 @@ display, start_display, add_menu, add_function_to_menu = init_display()
 my_box = BRepPrimAPI_MakeTorus(40., 20.).Shape()
 
 display.DisplayShape(my_box, update=True)
-f = display.View.View()
+f = display.View.View().GetObject()

This was the code up to commit e59acdc, where this and other files were edited "to use transparent handles". Now my question is, for which version of pythonocc-core is this? 0.18.1?

Positioning issues with core_load_step_with_colors.py

Using the core_load_step_with_colors.py example displays parts in incorrect positions.

However loading the SEP file with STEPControl_Reader as a single shape, positions the elements correctly. Please see screenshots attached.

File can be downloaded here

screenshot from 2018-06-16 19-17-51
screenshot from 2018-06-16 19-19-07

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.