You are currently reviewing an older revision of this page.
With a small number of steps, VBA can be used to create a large number of generated levels.
A level can be created with the following statement:
Dim oLevel As Level Set oLevel = ActiveDesignFile.AddNewLevel("levelname")
Dim oLevel As Level
Set oLevel = ActiveDesignFile.AddNewLevel("levelname")
However, even though this will normally work, this statement will cause a runtime error if a level with the same name already exists. This error will look something like this:
To prevent this, you could use an advanced test to determine whether a level with the same name already exists. This can be carried out with the following example:
Dim
oLevel
As
Level
Set
oLevel =
Nothing
oLevTemp
For
Each
In
ActiveDesignFile.levels
If
oLevTemp.Name =
"levelname"
Then
oLevel = ActiveDesignFile.levels(
)
End
Next
Is
oLevel = ActiveDesignFile.AddNewLevel(
oLevel.IsActive =
True
ActiveDesignFile.levels.Rewrite
Finally, the newly generated level is set to active and all changes to levels are saved.
However, you can also simply ignore the runtime error by adding the following instruction:
On Error Resume Next Dim oLevel As Level Set oLevel = ActiveDesignFile.AddNewLevel("levelname")
On Error Resume Next
You should take into account that all runtime errors can be ignored and continue processing with "On Error Resume Next". However, you should not always do this because it can significantly complicate the deterction of programming errors and lead to unforseen problems.