I'm trying to cut out a part from a line. For that i use LineElement.PartialDelete
I use the COM interop API for C# ,since the NET API way is orders of magnitude overcomplicated and no simple function like PartialDelete seems to exist. I have no interest in converting and trying to use the underlying CurveVector for a simple 2 point line, especially not without any useful info in the DgnPlatformNet.chm (i couldn't find any info how to cut one into pieces) nor any examples showing how to edit one.
In my test example i have a line (le1) from 0,0 to 12,0 and 2 points on 3,0 and 9,0. Two points that are clearly on the line! A third point is on 5,0 since the COM function doesn't allows null for the third point like the MDL function mdlElmdscr_partialDelete.
When I use le1.PartialDelete(out partial1, out partial2, ref p1, ref p2, ref pmid, 1); I get as result the entire line in partial2 and in partial1 a ComplexStringElement somewhere in nirvana at 9.223E+14m,9.223E+14m (see image)
.
What i would expect are two LineElements, one from 0,0 to 3,0 and a second from 9,0 to 12,0.
I have the following super simple and dumbed down example code, which shows that PartialDelete isn't working correct.
BCOM.Matrix3d rotm = s_comApp.Matrix3dIdentity(); BCOM.Point3d[] lp1 = new BCOM.Point3d[2]; lp1[0] = new BCOM.Point3d() { X = 0, Y = 0, Z = 0 }; lp1[1] = new BCOM.Point3d() { X = 12, Y = 0, Z = 0 }; BCOM.LineElement le1 = s_comApp.CreateLineElement2(null, ref lp1[0], ref lp1[1]); le1.Color = 0; s_comApp.ActiveModelReference.AddElement(le1); BCOM.Point3d p1 = new BCOM.Point3d() { X = 3, Y = 0, Z = 0 }; BCOM.Point3d p2 = new BCOM.Point3d() { X = 9, Y = 0, Z = 0 }; BCOM.Point3d pmid = new BCOM.Point3d() { X = 5, Y = 0, Z = 0 }; BCOM.Element partial1 = null; BCOM.Element partial2 = null; le1.PartialDelete(out partial1, out partial2, ref p1, ref p2, ref pmid, 1); if (partial1 != null) { partial1.Color = 4; s_comApp.ActiveModelReference.AddElement(partial1); } if (partial2 != null) { partial2.Color = 5; s_comApp.ActiveModelReference.AddElement(partial2); }
Any help to get PartialDelete to do what i want would be appreciated.
\edit
Update 12 has the same issue.
I did some tests and it seems you are right that PartialDelete does not work correctly in Interop API.
I recommend to test the same code in VBA at first. Some bugs reported for MicroStation CONNECT Edition were in Interop implementation, but not in COM, and this test can help to investigate where the problem is.
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
A few more comments:
Based on few more tests it seems the problem is not only in returned coordinates, but also in fact that the first returned element is ComplexString (at least in my test snippet), which can be hardly returned when simple line is divided into two.
Maybe Artur Goldsweer can provide some insight?
To call mdlElmdscr_partialDelete using P/Invoke is an alternative, but it requires to marshall all variables properly and I assume to don't call this function only, but also to add returned elements to model through P/Invoke, because MSElementDescr is quite useless in managed code.
I do not agree that the new NET API is overcomplicated, its OOP design is much better and more flexible than old COM/Interop, but at the same time I agree that because of lack of documentation (even with help of native API doc) it's often not clear how to use the API. How to break linear element is very good example, I am not sure what is the best approach.
Regards,
Hi All,
there is a know open issue with the COM method PartialDelete in CONNECT Edition. Defect 983416 is filed to address this issue.
Thanks to PatB who added the info, that this issue only occurs with executing this method in 2D models. I have tested and can confirm this, in 3D it works fine, in 2D there is a regression from V8i with method PartialDelete.
Best regards,Artur