版权声明:本文为博主原创文章,未经博主允许不得转载。 https://cloud.tencent.com/developer/article/1334335
有人问ms中用vba如何建立一个实体。很简单的一个问题,对照vba.chm,找到method里的
CreateCylinder Method
Generate a Cylinder at origin with SmartSolidElement Type.
Syntax
Set SmartSolidElement = object.CreateCylinder (Template, radius, height)
The CreateCylinder method syntax has these parts:
Part Description
object A valid object.
radius A Double expression. radius of base plan.
height A Double expression. height of the cylinder.
Template An Element expression.
Version
08.11.09
在ms的vba编辑器中写入
Sub Macro2()
Dim myshape1 As SmartSolidElement
Set myshape1 = SmartSolid.CreateCone(Nothing, 10, 5, 10)
ActiveModelReference.AddElement myshape1
myshape1.Rewrite
End Sub
运行就得到实体了。很简单,可是我找了一个上午。MicroStation_VBA_中文教程中丝毫没有提到如何建立实体。都是建立线、面……vba.chm中根本没有建立实体的代码例子。网络上根本搜不到。根据chm里的方法描述,起先代码是这样的
Sub Macro2()
Dim myshape1 As SmartSolidElement
Set myshape1 = CreateCone(Nothing, 10, 5, 10)
ActiveModelReference.AddElement myshape1
myshape1.Rewrite
End Sub
根本通不过。因为参考CreateShapeElement1这个方法如下,它的前面没有object啊。
Sub Macro2()
Dim myshape As ShapeElement
Dim shapepoints4(0 To 3) As Point3d
shapepoints4(0).x = 5
shapepoints4(0).y = 5
shapepoints4(1).x = 10
shapepoints4(1).y = 5
shapepoints4(2).x = 10
shapepoints4(2).y = 10
shapepoints4(3).x = 5
shapepoints4(3).y = 10
Set myshape = CreateShapeElement1(Nothing, shapepoints4, msdFillModeFilled)
myshape.FillColor = RGB(250, 250, 250)
ActiveModelReference.AddElement myshape
myshape.Rewrite
End Sub
最后终于在ms的example文件夹下找到了一个例题SmartSolid.mvba,恍然大悟。