我最初打算在 Bentley 编程论坛上问这个问题,因为他们对我用来建模我的 C# 问题有类似的答案。但是,我为论坛创建的帐户似乎无法正常工作。
代码的目的是设置线型、颜色、线宽,最后是线型参数下的两个设置,称为比例和角模式。
作为背景,我对 C# 比 VBA 更熟悉,这可能会导致我错过一些东西,但我感觉的解决方案类似于上面链接中突出显示的 C# 方法(我非常偶然地发现):
Private Sub AdjustStyleToByLevel(lvlName As String)
' Set up level definitions
Dim oLevel As Level
Set oLevel = ActiveDesignFile.Levels(lvlName)
' Set up scan criteria
Dim oScanCriteria As ElementScanCriteria
Set oScanCriteria = New ElementScanCriteria
oScanCriteria.ExcludeAllLevels
oScanCriteria.IncludeLevel oLevel
Dim oEnumerator As ElementEnumerator
Set oEnumerator = ActiveModelReference.Scan(oScanCriteria)
Dim oElement As Element
Do While oEnumerator.MoveNext
Set oElement = oEnumerator.Current
If oElement.IsTraversableElement Then
Dim oLineElement As LineElement
Set oLineElement = oElement
Set oLineElement.LineStyle = ByLevelLineStyle
oLineElement.Color = ByLevelColor ' -1
oLineElement.LineWeight = ByLevelLineWeight ' -1
' Define and set the Line Style settings
Dim oParams As LineStyleParameters
Set oParams = oElement.GetLineStyleParameters
oParams.ScaleFactor = Share.ChartScale / 100
oParams.SetRunThroughCorners
oLineElement.SetLineStyleParameters (oParams)
oLineElement.Rewrite
End If
Loop
End Sub
正是这一行oLineElement.SetLineStyleParameters (oParams)
给了我错误 438:“对象不支持此方法或属性”。但是,当将此与上面提到的 C# 方法(引用如下)进行比较时,我没有注意到一个主要区别。
public void ChangeLineStyleScale()
{
BCOM.Application msApp = BMI.Utilities.ComApp;
BCOM.LineElement oLine = msApp.ActiveModelReference.GetElementByID64(15092) as BCOM.LineElement;
BCOM.LineStyleParameters lsParams = oLine.GetLineStyleParameters();
lsParams.ScaleFactor = 2.0;
oLine.SetLineStyleParameters(lsParams);
oLine.Rewrite();
}
有谁知道我在这里做错了什么,或者如何解决这个问题?
谢谢