VBA to place data point at intersection of selected lines

I need some help on this.  I have a grid of lines/arcs that I need to be able to select and run the VBA and have it place a data point at the all the intersections of the selected elements.  I have done some reading online, but I dont know enough about VBA in Microstation to get started.  I have attached a screen shot of the grid I am working with.  Actually I am trying to locate these points and using the tracking tool in InRoads I need to find surface elevations at all the intersection points.  I think I can select the lines and then activate the tracking tool in InRoads and then run the VBA to place a data point at all the intersections.  Any help will be greatly appreciated.  

  • Hi Phillip,

    welcome to the community.

    This is kind the form of question: "Here is my problem, anybody can provide me a solution."

    To get you a start:

    You are able to get all the selected elements using:

    Dim elo As ElementEnumerator

    Set elo = ActiveModelReference.GetSelectedElements

    Read about ElementEnumerator in the help.

    To find a Intersection between two elements el1,el2 you can use:

    p = el1.AsIntersectableElement.GetIntersectionPoints(el2, Application.Matrix3dIsIdentity)

    Good luck,

    Stefan.

  • Do you actually want a data  point  or do you mean an active point... they are not the same  a data point  is the left mouse click onto the design plane.. and active point is a object  like a cell but it is view independant ie looks the same no matter want the zoom factor..

    If these lines are all at the same interval you could place the first one and use the copy command or the pipe command...

    Hang on just read the bit about inroads and tracking cant you use the intersect snap tool set permanently on ie double click on the snap tool ..

    but I dont know if the tracking tool in Inroads likes accudraw....

    Lorys

    Started msnt work 1990 - Retired  Nov 2022 ( oh boy am I old )

    But was long time user V8iss10 (8.11.09.919) dabbler CE  update 16 (10.16.00.80) 

    MicroStation user since 1990 Melbourne Australia.
    click link to PM me 

  • I actually want a data point (is. left click on the intersection)  I am currently doing it by setting the intersection snap as permanent and going through and snapping on each intersection and left clicking.  This is a feasible way but not really practical because there are so many points.  The image that I included only shows one flange of the bridge girder.  I have two flanges per girder and 3-6 girders per span and 18 spans on this one bridge alone.  That doesn't include the LT & RT coping and gutterlines that I need elevations on.  I need proposed and existing elevations at all the points also, so snapping on each intersection is very time consuming not to mention that the monotony is enough to drive someone insane.  The girders aren't always parallel to the centerline so the spacing varies and the spacing between the 20th point lines vary depending on the length of the span.  

  • Unknown said:
     I have attached a screen shot ...

    A screen-shot is good, but a DGN file is better.  We all use MicroStation, so a DGN file illustrates better the data you have.

    In this case, it's important to know about your dimensionality.  Presumably this is a 3D model, but what about your grid?  Are all those lines (a) planar and (b) do they lie on the same plane?  We can't deduce answers to those questions from a screen-shot.

    Finding Lines

    Follow Stefan's suggestion: use the ModelReference.Scan method to get an ElementEnumerator of lines.  Here's an example of a VBA project to collect lines.

     
    Regards, Jon Summers
    LA Solutions

  • Example.dgnJon,  I have attached a DGN that is similar to what I am working with.  I have deleted everything except the lines I am working with in this VBA.  I actually don't want to scan the entire file because the file will likely contain elements that I don't need to find the intersection of.  I want to be able to make a selection of lines and arcs and run the VBA to find all the intersections between the selected elements then have the VBA do the equivalent of left clicking (placing a data point) at the coordinate of the intersection.  The file I am working with is actually 2D because I need to get the surface elevations from InRoads tracking tool.

  • DGN Files and Models

    Unknown said:
     I actually don't want to scan the entire file

    Graphic elements are stored in models.  Models are stored in DGN files.  A DGN file will often contain multiple models.

    Consequently, you scan a model, not a file.  The VBA object ActiveModelReference is probably what you will work with most.

    Unknown said:
    The [model] will likely contain elements that I don't need to find

    That's normal: you set the properties of an ElementScanCriteria object to restrict the model scan.  That might be, in your case, line elements; or elements on a particular level.

    Unknown said:
     I want to be able to make a selection of lines and arcs and run the VBA to find all the intersections between the selected elements

    Create a list of candidate elements.  Then compare each candidate with all other candidates to find intersections.

    It's useful if you can differentiate between types of candidates.  From your DGN model it looks like you have one set of lines on level 1_RT_FLANGE_BEAM_2 and another set on level 1T_Lines.  You can build two lists, then use VBA method GetIntersectionPoints on a pair obtained from both lists.

    Pillage and Adapt

    Use the VBA example I cited and others you will find in VBA help.  Substitute your level names in that example — see what results you get.

     
    Regards, Jon Summers
    LA Solutions

  • Philip,

    again, use ActiveModelReference.GetSelectedElements to get all the selected elements.

    (Would be good to tell us your improvements or send the code you produced until now, looks like we do a lot of double posting right now.)

    Regards, Stefan.

  • Ok.   Here is my code so far.  It is working ok and it is finding the intersections but I have a couple of problems.  The first is that when I select the lines and run the VBA it will usually find two intersection points at each intersection each with apparently different rotations so it will put two data points at each intersection which is not ideal.  I think this has something to do with the Matrix3dIsIdentity when finding the intersection but I don't know how to make it ignore the rotation and only find one intersection point.  The other thing is that I need it to process the selected elements against all visible levels in View 1 not the level that I have defined in the VBA code.  Basically I need the end users to be able to select the elements and turn the level on that they want to process the selected elements against and run the VBA.  I need to assign all visible levels to the  ScanEnumerator variable.

    LabelIntersections.mvba

     

  • Unknown said:
     I think this has something to do with the Matrix3dIsIdentity

    p = el1.AsIntersectableElement.GetIntersectionPoints(el2, Application.Matrix3dIsIdentity)

    It's a good job you mentioned that!  CAD apps, including MicroStation, use 3D transforms and matrices in their geometric computations.  In MicroStation VBA, a rotation is defined by a Matrix3D user defined type (UDT).

    That method takes a Matrix3D to inform it of any required rotation to consider when calculating intersections.  You often provide a zero rotation (the identity matrix), given by function Matrix3dIdentity.  You've written Matrix3dIsIdentity, which answers the question "Is this a zero-rotation matrix?" with a Boolean answer, not a Matrix3D.

    I'm surprised that you didn't see a compilation error.  Try this instead...

    p = el1.AsIntersectableElement.GetIntersectionPoints(el2, Application.Matrix3dIdentity)

     
    Regards, Jon Summers
    LA Solutions

  • Hi Philip,

    good job so far.

    I think Jons suggestion should do the job.

    And you might find this function useful, which includes all visible level of a certain view into a scancriteria.

    (Untested.)

    Function AddVisibleLevelsToScanCriteria(sc As ElementScanCriteria, viewindex As Integer)

       Dim vw As View

       Dim lv As Level

       Set vw = ActiveDesignFile.Views(viewindex)

       For i = 1 To ActiveDesignFile.Levels.Count

           Set lv = ActiveDesignFile.Levels(i)

           If lv.IsDisplayedInView(vw) Then

               sc.IncludeLevel lv

           End If

       Next i

    End Function

    Regards, Stefan.