tpaviot / pythonocc-utils

A python package that provides useful classes/methods for pythonocc
GNU Lesser General Public License v3.0
45 stars 35 forks source link

Measurement of CAD file #23

Open Abhinav-Anil opened 4 years ago

Abhinav-Anil commented 4 years ago

How to find out the actual measurement of the step/iges files? Please help

tpaviot commented 4 years ago

what do you mean with measurement ? measurement of what ? in which unit ?

Abhinav-Anil commented 4 years ago

I'm having .step file and want to fetch the properties of cuboid and cube like length, breadth, depth in milimeter.

Abhinav-Anil commented 4 years ago

Hi, After using your both the links give below then also I am unable to find the edges, vertices and distance from the step file. https://github.com/tpaviot/pythonocc-core/blob/0.18.1/examples/core_geometry_face_recognition_from_stepfile.rst

https://github.com/tpaviot/pythonocc-core/blob/0.18.1/examples/core_topology_traverse.rst

def recognize_clicked(shp, *kwargs):
    """ This is the function called every time
    a face is clicked in the 3d view
    """
    for shape in shp:  # this should be a TopoDS_Face TODO check it is
        print("Edge selected: ", shape)
        recognize_edge(topods_Edge(shape))

def recognize_batch(event=None):
    """ Menu item : process all the faces of a single shape
    """
    # then traverse the topology using the Topo class
    t = Topo(shp)

    for edge_face in t.edges():
        recognize_edge(edge_face)

after running this it will show, Error: Core Dump

Please assist me in this issue.

tpaviot commented 4 years ago

Update to the latest example version at https://github.com/tpaviot/pythonocc-demos/blob/master/examples/core_geometry_face_recognition_from_stepfile.py

Abhinav-Anil commented 4 years ago

Update to the latest example version at https://github.com/tpaviot/pythonocc-demos/blob/master/examples/core_geometry_face_recognition_from_stepfile.py

@tpaviot it doesn't work for topods_Edge and topods_Vertices Result display like -

Traceback (most recent call last):
  File "/home/abhinav/anaconda3/lib/python3.7/site-packages/OCC/Display/qtDisplay.py", line 300, in mouseReleaseEvent
    self._display.Select(pt.x, pt.y)
  File "/home/abhinav/anaconda3/lib/python3.7/site-packages/OCC/Display/OCCViewer.py", line 638, in Select
    callback(self.selected_shapes, X, Y)
  File "/home/abhinav/Documents/cad/cad_module.py", line 150, in recognize_clicked
    recognize_face(topods_Edge(shape))
**RuntimeError: Standard_TypeMismatch
TopoDS::Edge
Aborted (core dumped)**
Abhinav-Anil commented 4 years ago

268=EDGE_LOOP('',(#371,#372,#373,#374,#375,#376,#377,#378));

269=EDGE_LOOP('',(#379));

270=EDGE_LOOP('',(#380));

271=EDGE_LOOP('',(#381));

272=EDGE_LOOP('',(#382,#383,#384,#385));

273=EDGE_LOOP('',(#386,#387,#388,#389));

274=EDGE_LOOP('',(#390,#391,#392,#393));

275=EDGE_LOOP('',(#394,#395,#396,#397));

276=EDGE_LOOP('',(#398,#399,#400,#401));

277=EDGE_LOOP('',(#402,#403,#404,#405));

278=EDGE_LOOP('',(#406,#407,#408,#409));

279=EDGE_LOOP('',(#410,#411,#412,#413));

280=EDGE_LOOP('',(#414,#415,#416,#417));

281=EDGE_LOOP('',(#418,#419,#420,#421));

282=ORIENTED_EDGE('',,,#470,.F.);

283=ORIENTED_EDGE('',,,#471,.F.);

284=ORIENTED_EDGE('',,,#472,.T.);

285=ORIENTED_EDGE('',,,#473,.F.);

286=ORIENTED_EDGE('',,,#474,.T.);

287=ORIENTED_EDGE('',,,#475,.F.);

288=ORIENTED_EDGE('',,,#476,.T.);

289=ORIENTED_EDGE('',,,#477,.F.);

Actually I want to fetch the edges from my file and I use the code :

from __future__ import print_function

import os
import os.path
import sys

from OCC.STEPControl import STEPControl_Reader
from OCC.IFSelect import IFSelect_RetDone, IFSelect_ItemsByEntity
from OCC.GeomAbs import *
from OCC.TopoDS import topods_Edge
from OCC.BRepAdaptor import BRepAdaptor_Surface, BRepAdaptor_Curve
from OCC.Display.SimpleGui import init_display

from occ import Topo,dumpTopology

def read_step_file(filename):

    step_reader = STEPControl_Reader()
    status = step_reader.ReadFile(filename)

    if status == IFSelect_RetDone:  # check status
        failsonly = False
        step_reader.PrintCheckLoad(failsonly, IFSelect_ItemsByEntity)
        step_reader.PrintCheckTransfer(failsonly, IFSelect_ItemsByEntity)
        step_reader.TransferRoot(1)
        step_reader.NbRootsForTransfer()
        a_shape = step_reader.Shape(1)
    else:
        print("Error: can't read file.")
        sys.exit(0)
    return a_shape

def recognize_edge(a_edge):
    fig = BRepAdaptor_Curve(a_edge)
    fig_type = fig.GetType()
    transfer = fig.Trsf()
    tolerance = fig.Tolerance()

    print("Returns the coordinates of the curve ", transfer)
    print("Returns the tolerance ", tolerance)

    if fig_type == GeomAbs_Circle:
        print("Circle")
        gp_cir = fig.Circle()
        loc = gp_cir.Location()
        axis = gp_cir.Axis().Location()
        print("Location", loc)
        print("axis", axis)
def recognize_clicked(shp, *kwargs):
    for shape in shp:
        print("Edges ", shape)
        recognize_edge(topds_Edge(shape))

def recognize_batch(event=None):
    t = Topo(shp)
    for fe in t.edges():
        recognize_edge(fe)

def exit(event=None):
    sys.exit()

if __name__ == "__main__":
    display, start_display, add_menu, add_function_to_menu = init_display()
    display.SetSelectionModeFace()  # switch to Face selection mode
    display.register_select_callback(recognize_clicked)

    # first loads the STEP file and displ/home/abhinav/Downloads/cylinderay
    shp = read_step_file(
        os.path.join(
            ".",
            "/home/abhinav/Downloads/OUTPUT OF ALU PART (extract.me)/OUTPUT OF ALU PART",
            "ALU_PART.stp",
        )
    )

    display.DisplayShape(shp, update=True)
    add_menu("recognition")
    add_function_to_menu("recognition", recognize_batch)
    start_display()

But it is showing the error

Traceback (most recent call last):
  File "/home/abhinav/anaconda3/lib/python3.7/site-packages/OCC/Display/qtDisplay.py", line 300, in mouseReleaseEvent
    self._display.Select(pt.x, pt.y)
  File "/home/abhinav/anaconda3/lib/python3.7/site-packages/OCC/Display/OCCViewer.py", line 638, in Select
    callback(self.selected_shapes, X, Y)
  File "/home/abhinav/Documents/cad/checking.py", line 75, in recognize_clicked
    recognize_edge(topds_Edge(shape))
NameError: name 'topds_Edge' is not defined
Aborted (core dumped)

please help @tpaviot @jf--- @aothms @

aothms commented 4 years ago

topds_Edge should probably be topods_Edge. not able to comment on the rest.

Abhinav-Anil commented 4 years ago

topds_Edge should probably be topods_Edge. not able to comment on the rest.

Sorry for the mistake but even after do correction it still show Aborted(core dumped)

aothms commented 4 years ago

it still show Aborted(core dumped)

That hints at an error in C++, maybe from incorrect usage of pyocc or a bug in occ. It's really hard to read your code due to incorrect formatting. Try running python in valgrind or similar to get some context as to what is happening in C++. https://jvns.ca/blog/2018/04/28/debugging-a-segfault-on-linux/

tpaviot commented 4 years ago

@Abhinav-Anil please insert the full step file. please read https://guides.github.com/features/mastering-markdown/, especially the Syntax Highlighting section to make your reports more readable