I notice something strange. I have a cell with one of the elements on "Level 2". When I get the element information on the cell, I can see that the particular element is on level = "Level 2". In VBA, when I scan the DGN file I notice the oEllipse.Level.Name = "" and not "Level 2". I wanted to compare the oEllipse.Level.Name = "Level 2". The work around I created was using the level number (which works) as follows:
If (oCellSubElmEnumerator.Current.Type = msdElementTypeEllipse) Then Set oEllipse = oCellSubElmEnumerator.Current
Set oLevelTwo = ActiveDesignFile.Levels("Level 2")
'If (oEllipse.Level.Name = "Level 2") Then If (oEllipse.Level.Number = oLevelTwo.Number) Then
............
My question is: Why is oEllipse.Level.Name = "" and not oEllipse.Level.Name = "Level 2"
Dilip Bhandarkar
Hi Dilip,
as Jon wrote, DGN example would help to understand better the issue. From your post it's not clear what file format do you use and why levels are named "Level 2". Is it DGN V7?
As Bruce mentioned, levels are not intuitive in some situations and to try to use level numbers can be confusing. Maybe the workaround seems to work, but it's not recommended to use level numbers (moreover as Bruce wrote, two different "level numbers" exist).
Without the example, it's hard to guess, but in my opinion you should check the cell you are iterating. Is it normal cell (so not e.g. SmartSolid cell), is it normal or shared and doesn't it point cell (where all elements have to have the same attrbiutes)?
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
I have attached the DGN (Version 8i) file and a JPEG showing a VBA watch for the ellipse (object oEllipse) and my mvba file. I created a cell named SIGNAL_HOME in another app which has 2 ellipse elements. In that app I also created 2 levels named "Level 1" and "Level 2". The ellipses are put on either "Level 1" or "Level 2". Now if I run my app CTEC_EXTRACT.mvba and stop at the line high-lighted in the code and watch oEllipse, you will notice that the Name (of level) = "", but Code = 2 and also Number (not in the image) = 2 - shown in the JPEG image.
Why is the level name = "" instead of "Level 1" or "Level 2"? Thanks.
Dilip Bhandarkar.zip
Please cancel my subscription as I have retired.
Unknown said:Set oEllipse = oCellSubElmEnumerator.Current
Does it make any difference if you write this?
Set oEllipse = oCellSubElmEnumerator.Current.AsEllipseElement
Eschew global variables. You've created a VBA reference to Microsoft scripting runtime: use early binding. Instead of this...
Public objFSO As FileSystemObject ... Public Sub START () Set objFSO = CreateObject("Scripting.FileSystemObject")
Write this...
Public Sub Start () Dim oFileSystem As New Scripting.FileSystemObject ' do something with oFileSystem
Now IntelliSense tells you about oFileSystem's properties.
Simplify your element type test. Instead of those If oCurrent.ElementType = xyz Then statements, use a Select Case statement...
If oCurrent.ElementType = xyz Then
Select Case
With oCellSubElmEnumeratorSelect Case .Current.ElementType Case msdElementTypeText Dim oWord As TextElement Set oWord = .Current.AsTextElement ... Case msdElementTypeShape Dim oShape As ShapeElement Set oShape = .Current.AsShapeElement ... Case msdElementTypeEllipse Dim oEllipse As EllipseElement Set oEllipse = .Current.AsEllipseElement ... End SelectEnd With
Regards, Jon Summers LA Solutions
Answer Verified By: Robert Hook
Thanks for the info. I will try it and let you know.
Jon,
Your solution (Set oEllipse = oCellSubElmEnumerator.Current.AsEllipseElement) works perfectly. I don't know why, but henceforth I am going to use your suggestion. I also incorporated the Select Case statement as you suggested. I
Thanks a lot.
Small point, but technically, the declaration 'objFSO as FileSystemObject' will allow intellisense to determine type and therefore list properties/methods. If it would have been declared 'objFSO As Object' then your early/late binding discussion would be correct. Intellisense is agnostic to how (or if) the object pointed to by the variable is instantiated. I do agree that if you have gone through the trouble to add the reference then it is better to instantiate using 'New' instead of 'CreateObject()'.