Hello, I am having trouble with this code to set my level object (runtime error '5')I put here a snippet of the code:
Private Function GetFolio(ops As String) Dim elEnum As ElementEnumerator Dim el As Element Dim elScanCriteria As ElementScanCriteria Dim elLevel() As Level ReDim elLevel(UBound(OptionVB_CadreDecoupe)) For i = 0 To UBound(OptionVB_CadreDecoupe) Set elLevel(i) = ActiveDesignFile.Levels(OptionVB_CadreDecoupe(i)) Next
The error occurs on line 9.
And I put a capture of the spy tools :
any idea what I did wrong?
Hi Etienne,
what exactly do you want to achieve?
To iterate levels is rarely useful and other ways can be used (but it requires to know what your aim is).
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Hi Jan,
I try to retrieve a list of element according to the level, in order to know for example their position, their length or for example if an element of level 1 intersects with an element of level 2.
Etienne Duperey said:I try to retrieve a list of element according to the level
In such case, why to iterate all levels in active DGN file?
Etienne Duperey said:if an element of level 1 intersects with an element of level 2.
It's about to obtain level object(s) based on their name(s). No iteration of all levels is necessary.
Regards,
Etienne Duperey said: the CADRE_A3 does exist, but not in the active Dgn, the latter is in a Dgn referenced
If you want to build a list of lines on a particular level in all reference attachments, then you need to enumerate those models. In each model, search for lines on that level.
Write a function that creates your scan criteria for a model...
Function ScanCriteriaForLinesOnLevel (ByVal levelName As String, ByVal oModel As ModelReference) As ScanCriteria Dim oLevel As Level Set oLevel = oModel.Levels (levelName) If oLevel Is Nothing Then Debug.Print "Level '" & levelName & "' does not exist in model '" & oModel.Name & "'" Exit Function End If Dim oCriteria As New ElementScanCriteria oCriteria.ExcludeAllLevels oCriteria.IncludeLevel oLevel oCriteria.ExcludeAllTypes oCriteria.IncludeType msdElementTypeLine oCriteria.IncludeType msdElementTypeLineString Set ScanCriteriaForLinesOnLevel = oCriteria End Function
Now get a list of lines from a model...
Function GetLinesOnLevel (ByVal levelName As String, ByVal oModel As ModelReference) As Element() Dim oLines As ElementEnumerator Set oLines = oModel.Scan (ScanCriteriaForLinesOnLevel (levelName, oModel) GetLinesOnLevel = oLines.BuildArrayFromContents() End Function
Now enumerate the active model and its attachments...
Dim oLines() As Element oLines = GetLinesOnLevel (levelName, ActiveModelReference) Dim oModel As ModelRefernce For Each oModel In ActiveModelReference.Attachments oLines = GetLinesOnLevel (levelName, oModel) Next oModel
Regards, Jon Summers LA Solutions