VBA - Bentley MAP detach XFM Feature record from graphical element.

Since Bentley Map has no !! way to transfer the XFM data in an ordinary database, I had to write me a VBA application.

The VBA Macro creates a database attachement with the XFM Feature data. The the XFM block should be deleted.

In the MAP Help I havn't found any command to resolve this.

...........

Set oDatabaseLink = Application.CreateDatabaseLink(glMslinkOld, gnEntityNum, msdDatabaseLinkageOdbc, False, 0)


If oElement.IsGraphical Then
oElement.AddDatabaseLink oDatabaseLink
??? remove XFM ????
oElement.Rewrite
gnCount = gnCount + 1

......

  • Hi Josef,

    so the complete workflow is:

    1. There are some shape files with the same structure (cadastral map areas).
    2. There is XFM project designed based on SHP files structure. (Note: It's possible to import SHP file both with and without XFM project, so it's the reason of this question)
    3. You use MapInteroperability tool in Bentley Map to import SHP file
    4. You want to convert such file into "mslink style", which includes:
      1. To move properties from XFM to database
      2. To establish mslinkg to this newle created record
      3. To drop XFM element into normal MicroStation element

    Is it correct?

    With regards,

     Jan

  • Hi Jan,

    I use Bentley Map only for import SHP Files, no XFM project.

    Command:

    >File >Import >Gis Data Types >Imports >New Import >Add File >Import

    With regards,

    Josef

    Attached my MVBA script.

    dbXFM2DB.mvba

  • Hi Josef,

    I have had not enough time to check your code (but for the first sight it looks not bad, even if talking about its structure). I did some quick testing and in my opinion this code should work:

    Dim ftEnum As FeatureEnumerator
    Set ftEnum = locateOp.GetLocatedFeatures
    
    Do While ftEnum.MoveNext
    	Dim currentFeature As feature
    	Set currentFeature = ftEnum.Current
    	
    	Dim pureElement As element
    	Set pureElement = xft.FeatureMgr.RemoveFeatureLinkages(currentFeature.Geometry)
    	
    	'Do whatever you need with the new element
    	pureElement.Level = ActiveDesignFile.Levels.Find("Default")
    	
    	pureElement.Rewrite
    Loop

    I guess you should add it to your process feature class to OnFinished method.

    With regards,

     Jan

  • Hi Jan,
    First thank you for your effort!

    If I understand you correctly, then I have to work through all selected features and not like my approach through the selected elements.
    My basic code is (was):
    Dim ee As ElementEnumerator
    Set ee = locateOp.GetLocatedElements
    ShowPrompt "Elements: " & CStr(locateOp.LocatedElementsCount)
    Do While ee.MoveNext

    Set ele = ee.Current
    ele.Redraw msdDrawingModeHilite
    If Not ele.HasAnyDatabaseLinks Then
    insertRow ele ' convert xfm data to ODBC record an attach to element
    End If
    Loop

    I must substitute this approach with your code.
    Is this correct?

    With regards,
    Josef R.
  • Hi Josef,

    Unknown said:
    f I understand you correctly, then I have to work through all selected features and not like my approach through the selected elements.

    My experience with Bentley Map XFT API is not good enough to say if you have to and if it's the only way, but it's the approach that seems to work ;-)

    If I understand BM API approach right, the feature is the core, not element (which representing the feature geometry and is not mandatory for some feature types like collections or data). This is in parallel with GIS approach as used in e.g. OGC and presented in many APIs (GeoTools, PostGIS etc.). So if you want to "defeaturize" a particular object, you have to enumerate features, not plain elements. Maybe your approach to work with elements directly can work also, but XFT API is quite high level, so there is a limited freedom to define what exactly will happen automatically and what not.

    In my opinion you can use my code to receive a plain MicroStation element (this is not a new element, but the original element representing the feature geometry and now it's "defeaturized") and to add mslink to this element using already existing your code.

    Unknown said:
    I must substitute this approach with your code.

    I assume it should not be a huge effort. Fortunately it's still about the same Locate class and OnFinished method. The only important thing is that you have to drop XFM feature data from an element after you migrate XFM attributes to a database, because after the element is "defeaturized", it's not possible to receive any XFM data anymore. Something like (enumerating features step by step):

    1. Read XFM properties from a feature
    2. Store the properties in a database (you will receive mslink)
    3. Remove XFM linkages from the feature
    4. Rewrite the element
    5. Add mslink to the element

    With regards,

     Jan