I need get startpoint and endpoint Consecutive both two lines with condition lines have point intersection, i tried with method Point3dSubtract and get intersection line, but i can not get startpoint and endpoint of line create point intersection. Help me!
And my code:
Sub intersection_line() Dim olv As Level Set olv = ActiveDesignFile.Levels("Level 11") Dim RayA As Ray3d Dim RayB As Ray3d Dim boolResultado As Boolean Dim inter1 As Point3d Dim fract1 As Double Dim inter2 As Point3d Dim fract2 As Double Dim ScanLinesByLength As Long Dim oCriteria As New ElementScanCriteria Dim oCriteria2 As New ElementScanCriteria Dim startPoint As Point3d Dim endPoint As Point3d Dim startPoint2 As Point3d Dim endPoint2 As Point3d oCriteria.ExcludeAllLevels oCriteria.IncludeLevel olv oCriteria.ExcludeNonGraphical oCriteria.ExcludeAllTypes oCriteria.IncludeType msdElementTypeLine oCriteria2.ExcludeAllLevels oCriteria2.IncludeLevel olv oCriteria2.ExcludeNonGraphical oCriteria2.ExcludeAllTypes oCriteria2.IncludeType msdElementTypeLine Dim oLines As ElementEnumerator Dim oLines2 As ElementEnumerator Set oLines = ActiveModelReference.Scan(oCriteria) Set oLines2 = ActiveModelReference.Scan(oCriteria2) While (oLines.MoveNext) Dim oLine As LineElement Set oLine = oLines.Current.AsLineElement startPoint.X = oLine.startPoint.X endPoint.X = oLine.endPoint.X startPoint.Y = oLine.startPoint.Y endPoint.Y = oLine.endPoint.Y RayA.Origin = oLine.startPoint RayA.Direction = Point3dSubtract(oLine.endPoint, oLine.startPoint) While (oLines2.MoveNext) Dim oLine2 As LineElement Set oLine2 = oLines2.Current.AsLineElement startPoint2.X = oLine2.startPoint.X endPoint2.X = oLine2.endPoint.X startPoint2.Y = oLine2.startPoint.Y endPoint2.Y = oLine2.endPoint.Y RayB.Origin = oLine2.startPoint RayB.Direction = Point3dSubtract(oLine2.endPoint, oLine2.startPoint) result = Ray3dRay3dIntersectXY(RayA, RayB, inter1, fract1, inter2, fract2) Wend Wend End Sub
And my file.
5826.test.dgn
Hi,
please read and respect the forum best practices: It is mandatory to specify both the used product and its version exactly (e.g. using the product name and build number).
Also, please always use Insert > Insert code tool when you share any code snippet (even one line long), because in the current state, when code is displayed as plain unformatted text, it is unreadable.
Hung Pham said:I need get startpoint and endpoint Consecutive both two lines wth condition lines have point intersection
Thanks for the DGN example, but I am lost a bit, because I do not see any "intersection point" there.
Do you mean you want to find all common vertices, where 2 lines in Level 11 have the same vertex?
Hung Pham said:Help me!
You must rewrite your code, because "the same vertex" does not mean "intersection is there". Geometrically it is different situation. In fact, two different solutions exist, but in VBA, which is very limited when working with data structures, one is easier in my opinion:
Scan for lines in Level 11, and for every line, do another 2 scans, using ElementRange around start point and end point. It returns "candidates", that should be tested for the same vertex (using "the same in tolerance" approach", because you cannot compare two double values for equality). A disadvantage of this solution is it returns every point twice, because found both for first and second line. When it is problem, e.g. further filtering or evidence what was found can be added.
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Thank you Jan. I understood very much about the way to write when I post.
I was write again my code:
Sr, I can't understand your solutions, could you show me your example code? Please. best regard!
Hung Pham said:Sr, I can't understand your solutions, could you show me your example code? Please. best regard!
Check the attached MVBA. But be aware it is for CONNECT Edition (I do not have V8 on my computer right now), so probably there is error reported because of element id type (but it can be fixed easily).
And as I wrote, extra filtering is probably necessary, because during testing some vertices are found twice.
Regards,
find-vertices.zip
Thanks you soo much Jan. I am trying code. Regards.
Sr. I am was run your code, but i have a problem, how to i get lines same vertex consecutive . Because my code is get vertex of end line and your code is get vertex of start line. Please, can you help me? best regard!
Hung Pham said:my code is get vertex of end line and your code is get vertex of start line
A LineElement has properties StartPoint and EndPoint.
LineElement
StartPoint
EndPoint
Regards, Jon Summers LA Solutions
Thanks you, I will to try. Regards.
Hung Pham said:Please, can you help me?
Sorry, but no. This forum is about helping people with their code, not in the way "Write the code for me (and for free).".
The shared code covers the core functionality and demonstrates how to find a vertex shared by two individual lines. To modify it to fit it to you specific requirements is up to you.
Look on this page and search for Computing Intersections. There's a VBA project you can download.
Thank Jan, i think will be reading and learning more with VBA document.
Thank Jon, i will be studing more VBA.