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)
ba ranh said:I see the manual but don't see the method 'Point2dFromXY'
What programming language are you using?
Regards, Jon Summers LA Solutions
I use C#
ba ranh said:I use C# with MicroStation 08.11.09.578
You're calling the VBA COM InterOp from C# from a separate process (i.e. a EXE).
ba ranh said:I want to get the 2D coordinates of the element
All DGN coordinates are 3D, even when in a 2D model. The Z value is zero in 2D.
I strongly suggest that you write a prototype of your app. using VBA. Move it to C# once the VBA is working correctly.
Different element types have different ways of getting coordinates. A TextElement or CellHeaderElement has an Origin property. Linear elements implement the IVertexList interface.
TextElement
CellHeaderElement
Origin
IVertexList
Hi,
Jon wrote good answer, some extra comments:
Element? What element? Be developer, be precise!
Element is e.g. (reference) Attachment. Has it coordinates? No. Or what about cell? It has coordinates (origin / insertion point), but maybe you are interested in vertices coordinates of lines inside the cell?
No detail answer can be provided until more details is shared.
Did you try to search manual and this forum?
When I searched for "get line vertices", as example of more specific requirement, in MicroStation VBA help, I found immediately "Highlighting the Closest Segment" example, that can be used to learn how to do it. And when I searched for "get line vertices vba" in this forum, many discussions were found.
Regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
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); } }
I want to get the X Y coordinates of the line element to compare with each other to see if it overlaps
I see your code at https://communities.bentley.com/products/programming/microstation_programming/f/archived-microstation-v8i-vba-forum/75500/getting-linestring-points/203597#203597
Sub Start() Open "C:\\path_to_your_file\\output_file.txt" For Output As #1 Dim esc As ElementScanCriteria Set esc = New ElementScanCriteria esc.ExcludeAllTypes esc.IncludeType msdElementTypeLineString Dim ee As ElementEnumerator Set ee = ActiveModelReference.Scan(esc) Dim el As LineElement Dim stringNum As Long stringNum = 1 Do While ee.MoveNext Print #1, "String " + CStr(stringNum) Dim vertices As Long vertices = ee.Current.AsLineElement.VerticesCount Dim points() As Point3d points = ee.Current.AsLineElement.GetVertices Dim index As Long For index = 0 To vertices - 1 Print #1, CStr(points(index).X) + " " + CStr(points(index).Y) + " " + CStr(points(index).Z) Next stringNum = stringNum + 1 Loop Close #1 End Sub
I convert to c# code, it gives me an empty error like this
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[]
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?