I connect the application using the following code.
Dim m_App As MicroStationDGN.ApplicationObjectConnector = GetObject(, "MicroStationDGN.ApplicationObjectConnector") ' Dim msDGNApp As MicroStationDGN.Application = m_App.Application Dim m_DF As MicroStationDGN.DesignFile = msDGNApp.ActiveDesignFile
This is how I get the DesignFile.
From here how will I get the FeatureMgr Class initialized.
Or Is there any othere method. Please help
Liju Mathew Varghese
Thanks Jeff. This helped me a to put my step ahead.
...you will need to use the CreateObjectInMicroStation method on the MicroStation application object to ensure that your XFT objects are created in the MicroStation's address space. The CreateObjectInMicroStation method is useful for an out-of-proc program that needs to create objects from a COM server that must run in MicroStation's address space.
Following is a simple VB.NET code example which uses CreateObjectInMicroStation to create XFT objects as previously described.
Imports DGN = Bentley.Interop.MicroStationDGNImports XFT = Bentley.Interop.Xft
Public Class Form1
Friend m_xftCmdMgr As XFT.CmdMgr Friend m_xftFeatureMgr As XFT.FeatureMgr Friend m_xftFeatureEnumerator As XFT.FeatureEnumerator Friend m_xftDialogMgr As XFT.DialogMgr Friend m_xftPropMgr As XFT.PropMgr Friend m_MSApp As DGN.Application Friend m_ActiveFile As DGN.DesignFile Friend m_CurrentModel As DGN.ModelReference
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
test()
End Sub
Friend Sub xft_initialize(ByVal msapp As DGN.Application)
m_MSApp = msapp
m_xftFeatureMgr = CType(m_MSApp.CreateObjectInMicroStation("xft.FeatureMgr"), XFT.FeatureMgr) m_xftFeatureEnumerator = CType(m_MSApp.CreateObjectInMicroStation("xft.FeatureEnumerator"), XFT.FeatureEnumerator) m_xftCmdMgr = CType(m_MSApp.CreateObjectInMicroStation("xft.CmdMgr"), XFT.CmdMgr) m_xftPropMgr = CType(m_MSApp.CreateObjectInMicroStation("xft.PropMgr"), XFT.PropMgr) m_xftDialogMgr = CType(m_MSApp.CreateObjectInMicroStation("xft.DialogMgr"), XFT.DialogMgr)
Sub test()
Dim oMSApp As Bentley.Interop.MicroStationDGN.Application Dim oMSAppConnector As Bentley.Interop.MicroStationDGN.ApplicationObjectConnector
' Create our MicroStation application object. oMSAppConnector = GetObject(, "MicroStationDGN.ApplicationObjectConnector")
oMSApp = oMSAppConnector.Application
' Initialize our global XFT objects in the MicroStation process. xft_initialize(oMSApp)
' Display the currently active design file. MsgBox(oMSApp.ActiveDesignFile.Name)
' Create an XFT feature enumerator. m_xftFeatureEnumerator = m_xftFeatureMgr.GetFeaturesInDgnList(oMSApp.ActiveDesignFile)
Dim oFeature As XFT.feature Dim sPropertyList As String Dim oProperty As XFT.Property
' Loop through our feature enumerator and create string that contains the property names and values. Do While m_xftFeatureEnumerator.MoveNext oFeature = m_xftFeatureEnumerator.Current Dim oProperties As XFT.PropertyEnumerator = oFeature.GetPropertyEnumerator sPropertyList = "Property Values: " Do While oProperties.MoveNext oProperty = oProperties.Current sPropertyList += " " + oProperty.Name + " = " + oProperty.value Loop
' Display the property names and values. MessageBox.Show(sPropertyList) Loop
End Class
Regards,
Jeff Bielefeld [Bentley]
This is what I'm doing in Vb.NET
Dim MSApp As Application
Dim app As MicroStationDGN.ApplicationObjectConnector
Try
app = GetObject(, "MicroStationDGN.ApplicationObjectConnector")
MSApp = app.Application
MsgBox("Connected")
Catch ex As Exception
MsgBox("Open Power Map" & vbCrLf & ex.Message)
End Try
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim el As Element
With MSApp.ActiveModelReference
el = .GetElementByID64(txt.Text)
If el IsNot Nothing Then
Dim Mgr As New XFT.FeatureMgr ' Error Happens here
Dim ft As feature
ft = Mgr.CreateFeature(el)
Else
MsgBox("Element Not Found")
End If
End With
But I get the following error on the line
Dim s as new xft.FeatureMgr
Retrieving the COM class factory for component failed due to the following error: 8007007e.
You need to have Bentley Map loaded and to reference the assemblies in the /Mpa/Bin/assemblies folder to your project.. The feature manager is in the Bentley.Interop.XFT assembly.