Open Abhinav-Anil opened 4 years ago
what do you mean with measurement ? measurement of what ? in which unit ?
I'm having .step file and want to fetch the properties of cuboid and cube like length, breadth, depth in milimeter.
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.
Update to the latest example version at https://github.com/tpaviot/pythonocc-demos/blob/master/examples/core_geometry_face_recognition_from_stepfile.py
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)**
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 @
topds_Edge
should probably be topods_Edge
. not able to comment on the rest.
topds_Edge
should probably betopods_Edge
. not able to comment on the rest.
Sorry for the mistake but even after do correction it still show Aborted(core dumped)
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/
@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
How to find out the actual measurement of the step/iges files? Please help