How do i locate the last element?

Jason Recliner

Usenet Archive
Joined
Oct 17, 2002
Messages
10
Reaction score
0
I am trying to convert text to tags using Microstation Basic. Basically i want to step through a file looking for text on a certain level, get the string (using MbeElement.getString), place a cell at the origin of the text and then tag the cell with the string obtained from the text. The problem i am having is how to locate the cell to tag it once i have placed it, ie locate the last element created. I am assuming i need to use MbeStartLocate and/or MbeRelocate but i'm not sure how.

Any ideas?
 
Sub Main
Dim endOfFile as Long

' save the end of file position
endOfFile = MbeDgnInfo.endOfFile

' ... do something here like place an element..

' make the current file position the previous end of file position endOfFile = elem.FromFile(endOfFile)

' locate the element
MbeLocateElement endOfFile

' do something with the located element
' ...........

End Sub
 
I tried that but it wont select any elements,
after it gets to:
endOfFile = elem.FromFile(endOfFile)
endOfFile returns -1
 
That suggests you have not placed a new element as the code is correct. If you still have problems post or email me your code
 
A working example

Sub Main
Dim endOfFile as Long

' save the end of file position
endOfFile = MbeDgnInfo.endOfFile

' ... do something here like place an element..
MbeSendCommand "PLACE LINE"
MbeSendDataPoint 0,0,0,1
MbeSendDataPoint 10,10,0,1

' make the current file position the previous end of file position endOfFile = elem.FromFile(endOfFile)

' do something with the located element
' ...........
MbeSendCommand "DELETE ELEMENT"
MbeLocateElement endOfFile
MbeLocateElement endOfFile

MbeStartDefaultCommand

End Sub

--
perl -e '$_ = "macart\@NO.ozemail.SPAM.com.au\n"; s/NO\.//; s/SPAM\.//; print;' | Sub Main | Dim endOfFile as Long | | ' save the end of file position | endOfFile = MbeDgnInfo.endOfFile | | | ' ... do something here like place an element.. | | | ' make the current file position the previous end of file position | endOfFile = elem.FromFile(endOfFile) | | | ' locate the element | MbeLocateElement endOfFile | | ' do something with the located element | ' ........... | | End Sub | | -- | perl -e '$_ = "macart\@NO.ozemail.SPAM.com.au\n"; s/NO\.//; s/SPAM\.//; | print;' | | | I am trying to convert text to tags using Microstation Basic. | | Basically i want to step through a file looking for text on a certain | | level, get the string (using MbeElement.getString), place a cell at | | the origin of the text and then tag the cell with the string obtained | | from the text. | | The problem i am having is how to locate the cell to tag it once i | | have placed it, ie locate the last element created. | | I am assuming i need to use MbeStartLocate and/or MbeRelocate but i'm | | not sure how. | | | | Any ideas? | |
 
Thanks for that.
I can now select the last element (a cell) but i'm having trouble tagging it. The macro runs through the file ok - finds the text, gets the string from it, place the cell at the text origin point, but it will only tag the first piece of text, the rest remain untagged. Is this because i am not creating a unique tag set definition for each one?

Code is attached below, i have cobbled it together from a few other ones so some it may look familiar...

Function PlaceTagCell (OriginPoint as MbePoint)
MbeSendCommand "ac=rm;place cell"
MbeSendDataPoint OriginPoint
MbeSendCOmmand "null"
End Function

Function AddTagSet (strSet As String) As Integer
Dim TagSet As New MbeTagSet
TagSet.name = strSet
AddTagSet = TagSet.add = Mbe_Success
End Function

Function AddTagDeF (strSet As String, strTag As String) As Integer Dim TagDef As New MbeTagDef TagDef.setName = strSet TagDef.name = strTag AddTagDef = TagDef.add = Mbe_Success End Function

Function AttachTag (Element As MbeElement, strSet As String, strTag As String,strVal As String) As Integer Dim Tag As New MbeTag Tag.setName = strSet Tag.name = strTag Tag.value = strVal AttachTag = Element.attachTag(Tag) = Mbe_Success End Function

'///////////////////////////////////////
Sub Main
Dim endOfFile As Long
Dim elem As new MbeElement
Dim RoomString as String
dim filepos as long
dim TextOrigin as MbePoint

MbeSendCommand "mark"

strSet$ = "room-no"
strTag1$ = "room-number"
strTag2$ = "building"
strTag3$ = "floor-level"
strTag4$ = "room-name-1"
strTag5$ = "campus"
strTag6$ = "asset"
strTag7$ = "room-name-2"

' Define Tag Set and two Tags
status = AddTagSet(strSet)

status = AddTagDef(strSet,strTag1)
status = AddTagDef(strSet,strTag2)
status = AddTagDef(strSet,strTag3)
status = AddTagDef(strSet,strTag4)
status = AddTagDef(strSet,strTag5)
status = AddTagDef(strSet,strTag6)
status = AddTagDef(strSet,strTag7)

' save the End of file position
endOfFile = MbeDgnInfo.endOfFile
RoomNum=0

BeginLoop:

filePos = elem.fromFile (0)

Do While filePos >= 0
If elem.level = 56 Then
If elem.type = 17 Then

'get string from room name text
status = elem.getString(RoomString)

'get origin point of room name text
status = elem.getOrigin(TextOrigin)

'change 'read' text to different
colour and level
elem.level = 63
elem.color = 3
status = elem.rewrite

'place cell on room name text
Status=PlaceTagCell(TextOrigin)

' make the current file position the
previous End of file position
endOfFile = elem.FromFile(endOfFile)
MbeLocateElement endOfFile

RoomNum=RoomNum+1

status =
AttachTag(elem,strSet,strTag1,Str$(RoomNum))
status =
AttachTag(elem,strSet,strTag2,strTag2)
status =
AttachTag(elem,strSet,strTag3,strTag3)
status =
AttachTag(elem,strSet,strTag4,RoomString)
status =
AttachTag(elem,strSet,strTag5,strTag5)
status =
AttachTag(elem,strSet,strTag6,strTag6)
status =
AttachTag(elem,strSet,strTag7,strTag7)

'print filepos
goto beginloop
End If
End If
filePos = elem.fromFile (filePos + elem.fileSize)
Loop
End Sub
 

Latest threads

Back
Top