gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15947
  • QQ554730525
  • 铜币25339枚
  • 威望15364点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
阅读:2792回复:3

结合MicroStation与Visual BASIC的综合应用

楼主#
更多 发布于:2003-07-31 22:12
作者 William G. Patterson, P.E.

[ 编者注:MicroStation的下一个版本,V8将增加Visual BASIC作为一种支持的程式语言。本篇文章将讨论如何使用Visual BASIC作为一个程式环境,来预先处理MicroStation BASIC巨集指令并应用於 MicroStation/J 系统中。]

在结合 MicroStation BASIC和微软的Visual BASIC 提供了一个快速而且全面的方法,可用来发展机构内中等与大规模的应用系统。我在经历了使用MDL,UCM与巨集指令集来设计程式之後,发现MicroStation和Visual BASIC的结合有一个截然不同优势,可用来作为设计和草案的自动化处理程序。

使用MicroStation和Visual BASIC的优点,包括快速的发展时间,无大小限制的应用系统,与设计良好的用户介面环境。主要的限制是当用户的设计图档在执行时,也必须同时开启MicroStation。在大部分的情况之下,这并不会造成用户任何困扰,只会使得使用者於观看设计图时觉得更加的生动有趣,与画图过程中必要的互动。

学习用MicroStation和Visual BASIC的基本指令仅仅只需要用户几天的时间。而用户所换得的却是一种广泛的能力, 来使用MicroStation与Visual BASIC以便开发更加复杂的系统。

MicroStation中记录巨集指令集的组合工作,可以复制到Visual BASIC中,并可被修改以便在Visual BASIC中执行。下面所叙述的就是一个MicroStation中记录的巨集指令集与转换成Visual BASIC的程式码之间的比较。唯一差异的地方是,物件msApp与稍微的修改。 point z则可被忽略。

正如此处所显示的,使用巨集指令集和BASIC程式码,用户可以下载档案 Form1.frm,是在本篇文章的 Visual BASIC form 档案所产生的。或者,从本篇文章的线上说明版本中将程式码剪贴。将本段程式码复制并贴上於MicroStaion BASIC 巨集指令集的编辑程式软件中,或是Visual BASIC 中,如同被要求的动作,以便测试。

放在MicroStation BASIC 巨集指令集的编辑程式里的文字:

Sub main

Dim startPoint As MbePoint

Dim point As MbePoint, point2 As MbePoint

?

MbeSendCommand "PLACE DIALOGTEXT ICON "

MbeSendAppMessage "TEXTEDIT", "FirstLine Place This Text"

?

startPoint.x = -5.136406#

startPoint.y = 28.803958#

?

point.x = startPoint.x

point.y = startPoint.y

MbeSendDataPoint point, 1%

?

MbeSendReset

End Sub

?

Visual BASIC 程式码 (复制到一个 VB 按钮中):

Dim msApp As Object

Dim msPoint As Object

Set msApp = CreateObject("MicroStation.Application")

Set msPoint = msApp.mbePoint

?

msApp.MbeSendCommand "PLACE TEXT"

msApp.mbesendkeyin "Place This Text"

msPoint.x = -5.136406

msPoint.y = 28.803958

msApp.MbeSendDataPoint msPoint, 1

msApp.MbeSendReset

注意:

l 输入编辑程式一定要被打开,以便能寄送信息。

l 任何可被输入的命令,也可随著msApp.MbeSendCommand 程式呼叫而寄送出去。

l 这是一个好主意 - 每次只打开一个MicroStaion,如此一来,当对程式进行修改时,只会对那唯一的档案进行修改。

呼叫程式 msApp.MbeSendDataPoint msPoint,1 传送於早先msPoint.x和 msPoint.y 变数所定义的点。这个1代表著视景一,它是需要被打开的。设计图将需要使用这个视景,而且准确性是依据视景对物体放大焦距的大小。 为增加准确性可设定误差容忍度为零(msApp.MbeState.LocateTolerance = 0) 。 该设定值可在改变前先存档,然後在程式的结束後再更改。

下面是一个使用Visual BASIC与MicroStation外部命令更加彻底的例子,使用Visual BASIC 与MicroStation外部指令来介接MicroStation。再次说明,该段程式码是相似於巨集指令集,即可被纪录并且用於MicroStation本身。该范例允许MicroStation打开 .dgn档,并输入文字内容。

奔特力的SELECT支持,提供了几个例子再这个线上说明上,一些已经在下面合并了。基本的说明文件档案和该SELECT线上说明资源是十分有价值的辅助工具。

一个简单例子的步骤

MicroStation档案的档名与档案路径必须被指定用C:\temp\Seed2d.dgn。使用下述的名字来新增下面的按钮矩阵:

????????? Command1(0) with the Caption Open DGN File

????????? Command1(1) with the Caption Place Text

????????? Command1(2) with the Caption Place a Line

????????? Command1(3) with the Caption Quit

新增下面这些文字的栏位

????????? txtFileName 'Fill text box with DGN file name and path

?

????????? Text1(0)扵'Text to be placed

????????? Text1(1)扲'Random x,y coordinates in this one and below.

?

????????? Text1(2)

????????? Text1(3)

????????? Text1(4)



 

MicroStation Objects

Dim msApp As Object

Dim msPoint As Object

?

'mbeCall Variables

Dim DATA As String 'Text to transfer (string)

Dim LEVEL As String 'LV="##" (string)

Dim ANGLE As String 'AA="##" (string)

Dim MSFONT As String 'FT="##" (string)

Dim LINECODE As String 'LC="##" (string)

Dim MSFONTSIZE As String 'TX="##" (string)

?

'Generic Points

Dim P1X, P1Y, P2X, P2Y

?

Private Sub Form_Load()

?

Set msApp = CreateObject("MicroStation.Application")

Set msPoint = msApp.mbePoint

?

End Sub

?

Private Sub Command1_Click(Index As Integer)

?

If Index = 0 Then

? Call StartMicroStation 'Open MicroStation file

ElseIf Index = 1 Then 'Place Text

?? LEVEL = "10"

?? ANGLE = "0"

?? MSFONT = "23"

?? MSFONTSIZE = ":4"

?? DATA = Text1(0).Text

?? P1X = Text1(1).Text

?? P1Y = Text1(2).Text

? ?Call mbePlaceText

elseIf Index = 2 Then 'Draw Line

?? LINECODE = 0

?? LEVEL = "1"

?? P1X = Text1(1).Text

?? P1Y = Text1(2).Text

?? P2X = Text1(3).Text

?? P2Y = Text1(4).Text

?? Call mbePlaceLine

elseIf Index = 3 Then Unload Me 'Cancel

?

End If

?

End Sub

?

Sub StartMicroStation()

?

Dim MyFileName As String

Dim TestFileExist As String

?

MyFileName = txtFileName.Text

?

'Check to see if the file exist.

TestFileExist = Dir(MyFileName) 'Returns only the file name if it exist.

If TestFileExist = Empty Then

? ?'If file does not exist copy a seed file to desired location.

?? 'FileCopy SourceFile, DestinationFile

End If

?

'Open MicroStation with previously created file.

Set msApp = CreateObject ("MicroStation.Application")

'It is a good idea only to have one MicroStation file open

'at a time. If dgnFileName variable is empty then no file

'is open.

MicroStaionFileName = msApp.MbeDgnInfo.dgnFileName()

If MicroStaionFileName = Empty Then

?? msApp.MbeSendCommand ("newfile " + MyFileName) 'Actual opens DGN file.

Else

?? MsgBox "Close MicroStation then try again "

End If

?

End Sub

?

Sub mbePlaceText()

' ------------

If DATA = Null Then: DATA = " "

With msApp

?? .MbeSendCommand "SET PARSE OFF" 'Allows key words to be printed

?? .MbeSendCommand "LV=" + LEVEL

?? .MbeSendCommand "AA=" + ANGLE

?? .MbeSendCommand "FT=" + MSFONT

?? .MbeSendCommand "TX=" + MSFONTSIZE

?? .MbeSendCommand "PLACE TEXT"

'.MbeSendCommand "active txj = cc" 'This will center the text

?? .mbesendkeyin DATA

?? msPoint.x = P1X

?? msPoint.y = P1Y

?? .MbeSendDataPoint msPoint, 1


?? .MbeSendReset

?? .MbeSendCommand "SET PARSE ON"

End With

End Sub

?

Sub mbePlaceLine()

' ------------

With msApp

?? .MbeSendCommand "LC=" + LINECODE

?? .MbeSendCommand "LV=" + LEVEL

?? .MbeSendCommand "PLACE LINE "

?? msPoint.x = P1X

?? msPoint.y = P1Y

?? .MbeSendDataPoint msPoint, 1

? ?msPoint.x = P2X

?? msPoint.y = P2Y

?? .MbeSendDataPoint msPoint, 1

?? .MbeSendReset

End With

End Sub

上述程式码提供了一个范例,关於如何使用MicroStation BASIC与Visual BASIC来结合成一个综合性的设计与草案的项目工作。花费时间来学习MicroStation与Visual BASIC的基本功夫,它将可以增加用户结合MicroStation BASIC与 Visual BASIC的能力。

William Patterson是南卡罗来纳运输部门的一个工程师。SCDOT 为MicroStation用户俱乐部的成员提供了本篇文章中的所有程式码,但对於用户在其他地方使用本程式所引起的问题并不负责。使用者写信给 William Patterson。请寄 : pattersowg@dot.state.sc.us.

所有权利都由奔特力系统股份有限公司保留 (1996 - 2000)。
喜欢0 评分0
y0106598
路人甲
路人甲
  • 注册日期2003-08-01
  • 发帖数373
  • QQ
  • 铜币869枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2003-08-01 15:34
顶,我正想学vb,看来有用
我是一个普通的人, 普通的就像上帝!
举报 回复(0) 喜欢(0)     评分
laskr
路人甲
路人甲
  • 注册日期2003-08-01
  • 发帖数696
  • QQ
  • 铜币494枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2003-11-23 16:08
学习
举报 回复(0) 喜欢(0)     评分
liubz
路人甲
路人甲
  • 注册日期2003-09-25
  • 发帖数56
  • QQ
  • 铜币248枚
  • 威望0点
  • 贡献值0点
  • 银元0个
3楼#
发布于:2003-12-10 18:10
有没有类似acad2000中的acad.tbl呀,否则vb环境中没有上下文提示。
举报 回复(0) 喜欢(0)     评分
游客

返回顶部