Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
  • Welcome
  • Products
  • Support
  • About
  • More
  • Cancel
MicroStation Programming
  • Product Communities
  • Developers and Programming
  • MicroStation Programming
  • More
  • Cancel
MicroStation Programming
MicroStation Programming - Wiki Simple example with object library
    • Sign in
    • MicroStation Programming - Wiki
    • -MicroStation CONNECT Edition
      • +MicroStation SDK
      • +MicroStation MDL
      • -MicroStation VBA
        • +MVBA FAQ
        • -MVBA Topics
          • CRUD example
          • Debugging
          • Documentation
          • Migration from VBA 6.x to 7.x
          • +MVBA Transforms
          • Network Shared Projects
          • Object model
          • Simple example with object library
          • Simple example with recording code
          • VBA Editor
          • VBA Integration with Applications
      • +Training
      • +Code Examples and Utilities
      • +Code Snippets
    • +MicroStation V8

     
     Questions about this article, topic, or product? Click here. 

    Simple example with object library

    Simple example – Using MicroStation object library

    If a VBA code is created from a recording, the base of the code are keyin commands like this one from the recorded example: CadInputQueue.SendKeyin " PLACE SMARTLINE"

    Often VBA macros are used for repeated use, e.g. to import thousands of coordinates and place lines or cells for each  together with tags or Itemtypes. It is recommended then to use functions from the MicroStation object library instead for a better control and performance.

    The alternate method to create elements are functions starting with “create”. To search for such “Create*” functions we can use the help file or directly browse in the MicroStation object library. From the VBA Editor with F2 we can switch from Source Code display to an Explorer like display of a complete list of all classes, functions, methods and properties. F7 brings you back to source code display.

    The first view of the object library may look like this:

    By default the content of <All libraries> is displayed. You may select here to get a filtered content of a specific library:

    “MicroStationDGN” – list all classes added with MicroStation “VBA” – list all base functionality from VBA

    The list may provide more libraries from other application like Excel, if these libraries are referenced to this project (See Tools > References) A search for “create” in the library returns a long list with functions. During scrolling down there should be 2 functions to create lines: CreateLineElement1 and CreateLineElement2.

    A click on the selection provides details  about the declaration of the function:

     

    This function requires 2 points to create a line, which we then may place into the drawing. A VBA code example using this function may look like this:

    Sub CreateLineTest()
    Dim oLine As LineElement
    Dim pStart As Point3d
    Dim pEnd As Point3d
        pStart = Point3dFromXYZ(10, 20, 30)
        pEnd = Point3dFromXYZ(70, 40, 20)
        Set oLine = CreateLineElement2(Nothing, pStart, pEnd)
        ActiveModelReference.AddElement oLine
    End Sub
    

     

    A brief description of this subroutine: The function CreateLineElement2 takes 2 points and returns an element of Type LineElement. The method .AddElement is finally used to add this new created element into the active model of the active drawing file.

    • Documentation
    • VBA Programming
    • VBA
    • Share
    • History
    • More
    • Cancel
    • Artur Goldsweer Created by Bentley Colleague Artur Goldsweer
    • When: Fri, May 22 2020 6:19 AM
    • Revisions: 1
    • Comments: 0
    Recommended
    Related
    Communities
    • Home
    • Getting Started
    • Community Central
    • Products
    • Support
    • Secure File Upload
    • Feedback
    Support and Services
    • Home
    • Product Support
    • Downloads
    • Subscription Services Portal
    Training and Learning
    • Home
    • About Bentley Institute
    • My Learning History
    • Reference Books
    Social Media
    •    LinkedIn
    •    Facebook
    •    Twitter
    •    YouTube
    •    RSS Feed
    •    Email

    © 2021 Bentley Systems, Incorporated  |  Contact Us  |  Privacy |  Terms of Use  |  Cookies