I use microstation 08.11.09.578, DGN 2D V7 Upgrade V8
I want to get the 2D coordinates of the element, I see the manual but don't see the method 'Point2dFromXY'
Point2dFromXY Method Returns a point with specified x and y components. Syntax Point2d = object.Point2dFromXY (X, Y)
I get the element's X Y coordinate but it returns null
Code C#
void Test(string sPath) { MicroStationDGN.Application app = new MicroStationDGN.Application(); DesignFile dgnfile = app.OpenDesignFile(sPath, true); ElementScanCriteria _MSesc = new ElementScanCriteria(); _MSesc.ExcludeAllTypes(); _MSesc.IncludeType(MsdElementType.msdElementTypeLine); //_MSesc.IncludeType(MsdElementType.msdElementTypeLineString); _Element ele; ElementEnumerator ee = app.ActiveModelReference.Scan(_MSesc); while (ee.MoveNext()) { ele = ee.Current; int iVectorCount = ele.AsLineElement.VerticesCount; Array xPoint = ele.AsLineElement.GetVertices(); string sTEXT = ""; for (int i = 0; i < iVectorCount; i++) { sTEXT += ", i = " + i + " : X = " + xPoint.GetValue(0) + ", Y = " + xPoint.GetValue(1) + ", Z = " + xPoint.GetValue(2) ; } MessageBox.Show("sTEXT = " + sTEXT); } }
Hi,
ba ranh said:I want to get the X Y coordinates of the line element
Line or LineString element?
ba ranh said:I convert to c# code
But, unfortunately, you did it wrongly.
As was discussed already in another thread, when you choose to wrote external application (and not in-process addin), you have to meet more requirements and the code is (a bit) more complex. In the discussed case, as described in VBA documentation, you should use CreateObjectInMicroStation method. But, I assume the error is not caused by this omission.
ba ranh said:I get the element's X Y coordinate but it returns null
Did you read the error message? The problem is not it returns null.
How it is possible that MicroStation data type is to be loaded from WindowsFormsApp1 assembly? Without knowing how complete project is set (what assemblies are referenced etc.) it's hard to say.
ba ranh said:Array xPoint = ele.AsLineElement.GetVertices();
Why this declaration is used?
GetVertices() returns Point3d[]
Regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
GetVertices() I see it as Array
ba ranh said:GetVertices() I see it as Array
Really?
Does not looks weird for you (as for developer) when it is "just array", without defining what type of object is stored in array?
Mine is an array
What assembly do you reference? I think your project is wrong, as it looks like your reference COM directly, not MicroStation interop assembly.
Yes it is a COM portCan I see your reference?
ba ranh said:Can I see your reference?
No. I maintain (only) several my old V8i projects now (because V8i is not supported product now), and none from them is external application, because it just not make any sense to make life harder and more limited, comparing to standard MicroStation addin.
Search this web, it was discussed several times, and I think some code was shared too.
But, what is difficult on referencing Interop assembly?