Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python] AddPoint with attributes #665

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ diff:
- (js) BND_PointCloud::CreateFromThreeJSON #642
- (js) Added several methods and properties for Planes #568
- (dotnet) Linux release builds in an Amazon Linux 2023 container
- (py) AddPoint now supports attributes #665 @StudioWEngineers

### Changed

Expand Down
10 changes: 10 additions & 0 deletions src/bindings/bnd_extensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,13 @@ BND_UUID BND_ONXModel_ObjectTable::AddPoint1(double x, double y, double z)
return ON_UUID_to_Binding(rc);
}

BND_UUID BND_ONXModel_ObjectTable::AddPoint6(double x, double y, double z, const BND_3dmObjectAttributes* attributes)
{
ON_Point point_geometry(x,y,z);
ON_UUID rc = Internal_ONX_Model_AddModelGeometry(m_model.get(), &point_geometry, attributes);
return ON_UUID_to_Binding(rc);
}

BND_UUID BND_ONXModel_ObjectTable::AddPointCloud(const BND_PointCloud& cloud, const BND_3dmObjectAttributes* attributes)
{
const ON_Geometry* g = cloud.GeometryPointer();
Expand Down Expand Up @@ -1705,8 +1712,11 @@ void initExtensionsBindings(rh3dmpymodule& m)
.def("__iter__", [](py::object s) { return PyBNDIterator<BND_ONXModel_ObjectTable&, BND_FileObject*>(s.cast<BND_ONXModel_ObjectTable &>(), s); })
#endif
.def("AddPoint", &BND_ONXModel_ObjectTable::AddPoint1, py::arg("x"), py::arg("y"), py::arg("z"))
.def("AddPoint", &BND_ONXModel_ObjectTable::AddPoint6, py::arg("x"), py::arg("y"), py::arg("z"), py::arg("attributes"))
.def("AddPoint", &BND_ONXModel_ObjectTable::AddPoint2, py::arg("point"))
.def("AddPoint", &BND_ONXModel_ObjectTable::AddPoint3, py::arg("point"), py::arg("attributes"))
.def("AddPoint", &BND_ONXModel_ObjectTable::AddPoint4, py::arg("point"))
.def("AddPoint", &BND_ONXModel_ObjectTable::AddPoint5, py::arg("point"), py::arg("attributes"))
.def("AddPointCloud", &BND_ONXModel_ObjectTable::AddPointCloud, py::arg("cloud"), py::arg("attributes")=nullptr)
.def("AddLine", &BND_ONXModel_ObjectTable::AddLine1, py::arg("from"), py::arg("to"))
.def("AddPolyline", &BND_ONXModel_ObjectTable::AddPolyline1, py::arg("polyline"), py::arg("attributes")=nullptr)
Expand Down
5 changes: 3 additions & 2 deletions src/bindings/bnd_extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ class BND_ONXModel_ObjectTable
public:
BND_ONXModel_ObjectTable(std::shared_ptr<ONX_Model> m) { m_model = m; }
BND_UUID AddPoint1(double x, double y, double z);
BND_UUID AddPoint6(double x, double y, double z, const class BND_3dmObjectAttributes* attributes);
BND_UUID AddPoint2(const ON_3dPoint& point) { return AddPoint1(point.x, point.y, point.z); }
//Guid AddPoint3(Point3d point, DocObjects.ObjectAttributes attributes)
BND_UUID AddPoint3(const ON_3dPoint& point, const class BND_3dmObjectAttributes* attributes) { return AddPoint6(point.x, point.y, point.z, attributes); }
BND_UUID AddPoint4(const ON_3fPoint& point) { return AddPoint1(point.x, point.y, point.z); }
//Guid AddPoint5(Point3f point, DocObjects.ObjectAttributes attributes)
BND_UUID AddPoint5(const ON_3fPoint& point, const class BND_3dmObjectAttributes* attributes) { return AddPoint6(point.x, point.y, point.z, attributes); }
//Guid[] AddPoints1(IEnumerable<Point3d> points)
//Guid[] AddPoints2(IEnumerable<Point3d> points, DocObjects.ObjectAttributes attributes)
//Guid[] AddPoints3(IEnumerable<Point3f> points)
Expand Down
24 changes: 23 additions & 1 deletion tests/python/test_File3dm_ObjectTable.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,28 @@

#objective: to test that passing a list of points or a Point3dList to the CreateControlPointCurve method returns the same curve
class TestFile3dmObjectTable(unittest.TestCase):
def test_addPoint(self) -> None:
"""Tests for the `AddPoint` method.
"""
file_3dm = rhino3dm.File3dm()

# create layers
file_3dm.Layers.AddLayer("layer1", (30, 144, 255, 255))
file_3dm.Layers.AddLayer("layer2", (255, 215, 0, 255))

# points added without attributes are added to the current layer, i.e., the first
# layer added to the model
file_3dm.Objects.AddPoint(rhino3dm.Point3d(0, 0, 0))
with self.subTest(msg="AddPoint without attributes"):
self.assertEqual(file_3dm.Objects[0].Attributes.LayerIndex, 0)

# add point with attributes
obj_attr = rhino3dm.ObjectAttributes()
obj_attr.LayerIndex = 1
file_3dm.Objects.AddPoint(rhino3dm.Point3d(1, 1, 0), obj_attr)
with self.subTest(msg="AddPoint with attributes"):
self.assertEqual(file_3dm.Objects[1].Attributes.LayerIndex, 1)

def test_addPolyline(self):

pointArray = []
Expand Down Expand Up @@ -63,7 +85,7 @@ def test_deleteObject(self):

self.assertTrue(qtyObjects == 2 and qtyObjects2 == 1)



if __name__ == '__main__':
print("running tests")
Expand Down
Loading