Ticket #9331 (closed)
Export Geometry::Object to Python
Reported by: | Martyn Gigg | Owned by: | Nick Draper |
---|---|---|---|
Priority: | major | Milestone: | Release 3.2 |
Component: | Python | Keywords: | |
Cc: | Blocked By: | ||
Blocking: | Tester: |
Description
This should allow, at minimum, access to the shapeXML & bounding box of a particular ObjComponent.
Change History
comment:2 Changed 6 years ago by Martyn Gigg
- Status changed from assigned to inprogress
Export Object class to Python
Also add shape() method to the IObjComponent interface export. Refs #9331
Changeset: 0ff794bfe715aadf173a1a877398de0b5039ff5a
comment:4 Changed 6 years ago by Martyn Gigg
- Owner changed from Martyn Gigg to Nick Draper
Branch: feature/9331_access_geometry_shape_from_python
Tester: This script demonstrates the use of the XML and bounding box to access the radius value of the instrument component's shape.
import mantid import xml.etree.ElementTree as ET w = mantid.simpleapi.Load("MAR11001.raw") inst = w.getInstrument() p = inst.getComponentByName("tall He3 element") he3_shape = p.shape() #------- By XML ------------- xml = he3_shape.getShapeXML() # Define the namespace lookup in the XML namespaces = {"ns1" : "http://www.mantidproject.org/IDF/1.0"} root = ET.fromstring(xml) cyl_elem = root.find("ns1:cylinder", namespaces=namespaces) radius_elem = cyl_elem.find("ns1:radius", namespaces=namespaces) radius = radius_elem.get("val", None) print "Cylinder radius from XML:",radius #------- By BoundingBox ------------- bounding_box = he3_shape.getBoundingBox() widths = bounding_box.width() # box is axis-aligned with shape and Y-axis is assumed "up" radius = 0.5*widths.X() print "Cylinder radius from bounding box:",radius
comment:5 Changed 6 years ago by Nick Draper
- Status changed from inprogress to closed
Merge remote-tracking branch 'origin/feature/9331_access_geometry_shape_from_python'
Full changeset: 983616e2d2d497bdb458e40d3b796d13159efbc7
Note: See
TracTickets for help on using
tickets.