Dear all, good day.
I have a cell containing an element of type Surface(18).
I cannot understand how to navigate through its subelements.
Here it is visual basic code:
Public Sub NavigateThroughSurface( ByVal oApplication As Bentley.Interop.MicroStationDGN.Application ) Dim oEnumerator As Bentley.Interop.MicroStationDGN.ElementEnumerator = oApplication.ActiveModelReference.Scan
While oEnumerator.MoveNext Dim oElement = oEnumerator.Current If Not oElement.IsCellElement Then Continue While
Dim oCellElement As Bentley.Interop.MicroStationDGN.CellElement = oElement.AsCellElement Dim lSubElementEnumerator As Bentley.Interop.MicroStationDGN.ElementEnumerator = oCellElement.GetSubElements While lSubElementEnumerator.MoveNext Dim oSubElement = lSubElementEnumerator.Current If oSubElement.Type = Bentley.Interop.MicroStationDGN.MsdElementType.Surface Then 'I do not find any "oSubElement.AsSurface" function... 'I have already done several tries, but without success:
'!!!!following statement throws exception: Dim oBsplineSurfaceElement As Bentley.Interop.MicroStationDGN.BsplineSurfaceElement = oSubElement.AsBsplineSurfaceElement
'!!!!following statement throws exception too: Dim lSolids As Bentley.Interop.MicroStationDGN.ElementEnumerator = oApplication.SmartSolid.ConvertToSmartSolidElement(oSubElement)
'?????????So how I can point to the surface itself and navigate through its subelements????????? End If End While End While End Sub
Thanks in advance.
Roberto
Italy
Roberto Cardosi said:I have a cell containing an element of type Surface(18)
Type 18/19 surface/solid elements are primitive types. They have been around since the last century. They are neither B-spline surfaces nor BREP solids. As a primitive type, they have no components (sub-elements).
One way to analyse a type 18/19 would be to convert it to a SmartSolid and use the SmartSolid API.
As Jan writes, the best API for analysing those primitives is MDL. It's possible to determine how they were created (e.g. by extrusion or rotation) and the profile used to create that result. Such methods are not available to you in VBA.
Regards, Jon Summers LA Solutions
Dear all, many thanks for the answers.
I am a newbye in this community, so please forgive me for having not followed its best practices...
Public Sub NavigateThroughSurface( ByVal oApplication As Bentley.Interop.MicroStationDGN.Application ) Dim oEnumerator As Bentley.Interop.MicroStationDGN.ElementEnumerator = oApplication.ActiveModelReference.Scan While oEnumerator.MoveNext Dim oElement = oEnumerator.Current If Not oElement.IsCellElement Then Continue While Dim oCellElement As Bentley.Interop.MicroStationDGN.CellElement = oElement.AsCellElement Dim lSubElementEnumerator As Bentley.Interop.MicroStationDGN.ElementEnumerator = oCellElement.GetSubElements While lSubElementEnumerator.MoveNext Dim oSubElement = lSubElementEnumerator.Current If oSubElement.Type = Bentley.Interop.MicroStationDGN.MsdElementType.Surface Then 'I do not find any "oSubElement.AsSurface" function... 'I have already done several tries, but without success: '!!!!following statement throws exception: Dim oBsplineSurfaceElement As Bentley.Interop.MicroStationDGN.BsplineSurfaceElement = oSubElement.AsBsplineSurfaceElement '!!!!following statement throws exception too: Dim lSolids As Bentley.Interop.MicroStationDGN.ElementEnumerator = oApplication.SmartSolid.ConvertToSmartSolidElement(oSubElement) '?????????So how I can point to the surface itself and navigate through its subelements????????? End If End While End While End Sub
Jon Summers said:One way to analyse a type 18/19 would be to convert it to a SmartSolid and use the SmartSolid API.
I have already tried to convert the subelement in SmartSolid, but following statement throws an exception:
So, please may you better explain what you mean by "convert it to a SmartSolid"?
What is SmartSolid API and where I can find it?
Following screenshots show you the versions I am using:
Thanks in advance
Roberto Cardosi said:What is SmartSolid API?
Use SmartSolid.ConvertToSmartSolidElement(yourElement) to convert your type 18 element to an ElementEnumerator. Then you can use the methods of SmartSolid and SmartSolidElement to perform your analysis.
SmartSolid.ConvertToSmartSolidElement(yourElement)
ElementEnumerator
SmartSolid
SmartSolidElement
Roberto Cardosi said:following statement throws exception
VBA doesn't have exceptions. What programming language are you writing?
I suggest that you write your initial program in pure MicroStation VBA. It's hard for us to reproduce VBA + some other language code.
That way, you won't get caught out by problems created at the interface of two different programming environments (e.g. VB.NET is not VBA) running in two different processes. Once your VBA code is working, then you can consider porting to another language.
I have tried both in vba and in vb.net, but it does not work.
Following the link where you can download the very simple dgn file containing surface (type 18):
https://app.box.com/s/6v0ksnpohoskaypskc7s4lmfa89cfe7j
Here is the code in VBA:
Option Explicit Public Sub Start() Dim oEnumerator As ElementEnumerator Set oEnumerator = Application.ActiveModelReference.Scan While oEnumerator.MoveNext Dim oElement As Element Set oElement = oEnumerator.Current If oElement.IsCellElement Then Dim oCellElement As CellElement Set oCellElement = oElement.AsCellElement Dim lSubElement As ElementEnumerator Set lSubElement = oCellElement.GetSubElements While lSubElement.MoveNext Dim oSubElement As Element Set oSubElement = lSubElement.Current Dim lSolid As ElementEnumerator Set lSolid = Application.SmartSolid.ConvertToSmartSolidElement(oSubElement) MsgBox ("if you read this message, then it works!") Wend End If Wend End Sub
This code throws following error:
Here is the code in VB.net:
Private Sub Button17_Click(sender As Object, e As EventArgs) Handles Button17.Click Dim targetPWModel As String = "type1" Dim oApplicationObjectConnector As Bentley.Interop.MicroStationDGN.ApplicationObjectConnector = GetObject(, "MicroStationDGN.ApplicationObjectConnector") Dim oApplication = oApplicationObjectConnector.Application Dim oDesignFile = oApplication.ActiveDesignFile Dim oEnumerator As Bentley.Interop.MicroStationDGN.ElementEnumerator = oApplication.ActiveModelReference.Scan While oEnumerator.MoveNext Dim oElement = oEnumerator.Current If Not oElement.IsCellElement Then Continue While Dim oCellElement As Bentley.Interop.MicroStationDGN.CellElement = oElement.AsCellElement Dim lSubElementEnumerator As Bentley.Interop.MicroStationDGN.ElementEnumerator = oCellElement.GetSubElements While lSubElementEnumerator.MoveNext Dim oSubElement = lSubElementEnumerator.Current If oSubElement.Type = Bentley.Interop.MicroStationDGN.MsdElementType.Surface Then 'I do not find any "oSubElement.AsSurface" function... 'I have already done several tries, but without success: Dim lSolids As Bentley.Interop.MicroStationDGN.ElementEnumerator = oApplication.SmartSolid.ConvertToSmartSolidElement(oSubElement) MsgBox("if you read this message, then it works!") End If End While End While MsgBox("done") End Sub
And this is the error it throws:
Any other ideas?
Thanks again.
Roberto Cardosi said:This code throws following error
CardosiEllipticalHead.dgn
I simplified your DGN model (removed the cell) and VBA code...
Option Explicit Public Sub Main() Dim id As DLong id = DLongFromLong(4090) Dim oHead As Element Set oHead = ActiveModelReference.GetElementByID(id) Debug.Assert Not oHead Is Nothing Analyse oHead End Sub Public Sub Analyse(ByVal oHead As Element) Dim oSolidComponents As ElementEnumerator ' Next line throws 'unknown error' Set oSolidComponents = SmartSolid.ConvertToSmartSolidElement(oHead) Debug.Assert Not oSolidComponents Is Nothing Do While oSolidComponents.MoveNext Debug.Print "Found component type " & _ CStr(oSolidComponents.Current.Type) Loop End Sub
The code fails to convert the Type 18 to a SmartSolid in the line below my comment.
The DGN file and the VBA code provide evidence for a Trouble Report (TR) or Service Request (SR) you can file with Bentley Systems. Or possibly Artur Goldsweer or Yongan.Fu can help?