Recalling elements after modifying

Status
Not open for further replies.

Robert M.

Usenet Archive
Joined
Jan 9, 2001
Messages
310
Reaction score
0
Hey there!

Here's another question...

I drop a cell in a macro, but I want to select it again with another command or internal call to the element via file position or element from file. I record the end of file pos before i drop the element, but when I try to get it again using the file pos the element's not found!! aaarrgh! (heheh).

I'm stuck..can someone help me please!!!
:-)

Here's the snippet!...

' SELECT BY CELL
MbeSendCommand "SELECTBY SETTINGS CELL "
' USE CELL NAME AS A TARGET
MbeSetAppVariable "SELECTBY", "selectorGlobals.cellName", celName ' EXECUTE THE SELECTION MbeSendCommand "SELECTBY EXECUTE " ' DROP THE SELECTED ELEMENT MbeSendCommand "DROP element" MbeSendDataPoint 0,0,0,1 ' GET THE CURRENT END OF FILE POSITION BEFORE DROPPING THE ELEMENT endOfFilePos = MbeDgnInfo.endOfFile MbeSendCommand "place fence element" MbeLocateElement endOfFilePos
 
Hi Robert,
When a cell is dropped, its component elements are moved to the end of the file. Whatever your EOF marker was pointing to before, it's now pointing to something else (or nothing at all, perhaps an "in-between" location on some other complex element). BTW, the new EOF points to the last component of the original cell, which is stored depending upon their file-position-order when the cell was created...

I'm not sure what you want to do, but it sounds interesting. Dropping a cell then pointing to its new file location is like spilling a sack of marbles in a bathtub and trying to pick one up--which one you get is a mystery ;-)

HTH,
Simon

"Robert M." wrote:
Hey there!

Here's another question...

I drop a cell in a macro, but I want to select it again with another command or internal call to the element via file position or element from file. I record the end of file pos before i drop the element, but when I try to get it again using the file pos the element's not found!! aaarrgh! (heheh).

I'm stuck..can someone help me please!!!
:-)

...
 
Doh!

Not what I expected but I guess it's the way it goes... Hmm basically I'm placing the cell and dropping it, but I then want to modify the points and elements from the cell.

If there is another way I'd be keen to know :-)

Regards

Rob
 
I've never seen this behaviour concerning component elements being moved to the EOF when a cell is dropped. I tried testing this a few times and was unable to duplicate the results. Here is some typical output from EDG:

Before dropping cell:
17 (6) SHAPE Level = 1
18 #2# CELL (ARRO) Level = 0
19 (3) LINE (1) Level = 1
20 (3) LINE (1) Level = 1
21 (3) LINE (1) Level = 1
22 (3) LINE (1) Level = 1
23 (15) circular ELLIPSE Level = 1
24 << END OF DESIGN >>

After dropping cell:
17 (6) SHAPE Level = 1
18 del#2# CELL (ARRO) Level = 0
19 (3) LINE Level = 1
20 (3) LINE Level = 1
21 (3) LINE Level = 1
22 (3) LINE Level = 1
23 (15) circular ELLIPSE Level = 1
24 << END OF DESIGN >>

You should be able to get the filepos of the first component element before you drop the cell using element.firstElement. If you want to work on more than one element you will have to find out how many elements are in the cell before you drop it.

Dan

On Wed, 16 Jan 2002 11:22:44 +1100, "Robert M."
wrote:

Doh!

Not what I expected but I guess it's the way it goes... Hmm basically I'm placing the cell and dropping it, but I then want to modify the points and elements from the cell.

If there is another way I'd be keen to know :-)

Regards

Rob

...
 
Hi Dan,
Interesting...
Try this macro (watch for wrapped lines). Place (in this order) some cells, then lines, etc. Run the macro, which hilites the last element in a file, and a line will hilite (the last element). Now drop one cell, and run the macro again. It'll be one of the components of the cell that's dropped:

Sub Main
Dim element As New MbeElement
Dim filePos As Long
Dim lastPos As Long
Dim point As MbePoint
Dim status As Long
Dim elemRange As MbeRange
Dim UORs As Long

UORs = MbeDgnInfo.subPerMaster * MbeDgnInfo.uorPerSub

'start with first element in file
filePos = element.fromFile (0)

'do until EOF (when filePos = -1)
Do While filePos >= 0
'store the current element position:
If element.isGraphics = 1 And element.type 33 Then 'is not dimension lastPos = filePos ElseIf element.type = 33 Then 'is dimension 'find some component of the dimension:
lastPos = filePos
End If
'calculate file position of next element:
filePos = element.fromFile (filePos + element.fileSize, 0)
Loop

'set the file position to the last valid element from lastPos:
filePos = element.fromFile (lastPos, 0)

'zoom to the element:
If element.type = 33 Then 'dimension element
status = element.getRange(elemRange)
Print elemRange.xLow, elemRange.yLow
MbeSendKeyin "window center;XY=" & CStr(elemRange.xLow / UORs) & "," & CStr(elemRange.yLow / UORs) & ";SELVIEW 1" Else 'all others status = element.getOrigin(point) Print point.x, point.y MbeSendKeyin "window center;XY=" & CStr(point.x) & "," & CStr(point.y) & ";SELVIEW 1" End If

'hilite the element:
element.display MBE_Hilite

MbeWriteMessage "Element Type " & CStr(element.type)
End Sub

What's really strange is that this confirmed up in EdG of the file too:
Before (cell, then three lines):
42 #2# CELL (ADFIRE) Level = 0
43 (15) circular ELLIPSE (1) Level = 21 44 (15) circular ELLIPSE (1) Level = 21 45 (17) TEXT (1) Level = 21 46 (3) LINE Level = 1 47 (3) LINE Level = 1 48 (3) LINE Level = 1 56 << END OF DESIGN >>

After (note the former components of the cell _after_ the three lines):
42 (17) TEXT (1) Level = 21 43 (3) LINE Level = 1 44 (3) LINE Level = 1 45 (3) LINE Level = 1 54 (15) circular ELLIPSE Level = 21 55 (15) circular ELLIPSE Level = 21 56 (17) TEXT Level = 21 64 << END OF DESIGN >>

It's a conspiracy!
Simon

Dan MacNeil wrote:
I've never seen this behaviour concerning component elements being moved to the EOF when a cell is dropped. I tried testing this a few times and was unable to duplicate the results. Here is some typical output from EDG:

Before dropping cell:
17 (6) SHAPE Level = 1
18 #2# CELL (ARRO) Level = 0
19 (3) LINE (1) Level = 1
20 (3) LINE (1) Level = 1
21 (3) LINE (1) Level = 1
22 (3) LINE (1) Level = 1
23 (15) circular ELLIPSE Level = 1
...
 
Interesting Stuff. I think this is what is going on. Cell is basically like a complex element - a header followed by component elements. When you drop it - the component elements of the cell will be written to end of file - not in between anywhere - at the end. The header of the original Cell is flagged as DELETED, the components are not flagged - they are ignored when Microstation reads the file - If header says the element is deleted then it is so. To verify this, COMPRESS the file and you should see the CELL and all it's components disappear from the file if you analyze it with EDG again.
 
Heya Simon,

Is it easier if I send a datapoint onto the origin if it has an element there?

Cheers
 
Simon,
I tried your macro but it didn't have any effect on the outcome. I got the same result as before; the cell component elements stayed put and the same element hilited both times (a line after the cell).

I noticed there is a bit of a jump in the EDG element numbers you show; were you doing something in the file besides:
run macro
drop cell
run macro
?

I'm testing at home with MS95 but I don't expect to find any difference at work with MSSE. Are you using a later version?

Very strange :<)
Dan

On Wed, 16 Jan 2002 02:43:34 GMT, Simon Wurster
wrote:

Hi Dan,
Interesting...
Try this macro (watch for wrapped lines). Place (in this order) some cells, then lines, etc. Run the macro, which hilites the last element in a file, and a line will hilite (the last element). Now drop one cell, and run the macro again. It'll be one of the components of the cell that's dropped:
...
snip
...
What's really strange is that this confirmed up in EdG of the file too:
Before (cell, then three lines):
42 #2# CELL (ADFIRE) Level = 0
43 (15) circular ELLIPSE (1) Level = 21 44 (15) circular ELLIPSE (1) Level = 21 45 (17) TEXT (1) Level = 21 46 (3) LINE Level = 1 47 (3) LINE Level = 1 48 (3) LINE Level = 1 56 << END OF DESIGN >>

After (note the former components of the cell _after_ the three lines):
...

...
snip
 
Hi Dan,
Gee, I wonder if something changed btwn. '95 and J? I too tried several different cell/DGN file combinations (all MS/J though), and got the same result: the dropped cell's elements are moved to the end of the file.

Dunno... Maybe an MDL guru can shed some light on this anamoly...

Regards,
Simon

Dan MacNeil wrote:
Simon,
I tried your macro but it didn't have any effect on the outcome. I got the same result as before; the cell component elements stayed put and the same element hilited both times (a line after the cell).

I noticed there is a bit of a jump in the EDG element numbers you show; were you doing something in the file besides:
run macro
drop cell
run macro
?

...
 
I know nothing of MDL, but I know MS file format. Started with IGDS in 1983 and went over to Microstation in early 90s. no anamoly Nature of the beast - they have to go to end. Same thing will happen with complex string. Complex some elements together. The original elements will be deleted and a new complex element will go to the end of the file - a header followed by component elements - VERY SIMILAR STRUCTURE COMPARED TO A CELL. Place some more elements they go to end of file of course. Now drop the complex element just made above - guess what - it's header is flagged as deleted and elements get rewritten to end of file.

Add a vertex or delete a vertex from a linestring - new element added at end of file. Edit some text changing the number of characters - Les or more - doesn't matter - a new element will be placed at end of file.

Above is why it is always good to compress file periodically. With all the typical modifications made, deleted elements take up file space - even if nothing is deleted with the delete command.

Robert M. - What are you trying to do with "CELL" after it's dropped. If you drop it, it's gone. don't go looking for a "CELL" at previous end of file. All the component elements will be there, but not the cell ITS GONE.

Also what version of MS are you using?

"Simon Wurster" wrote:

Hi Dan,
Gee, I wonder if something changed btwn. '95 and J? I too tried several different cell/DGN file combinations (all MS/J though), and got the same result: the dropped cell's elements are moved to the end of the file.

Dunno... Maybe an MDL guru can shed some light on this anamoly...

Regards,
Simon
 
Hi Stephen,

OK I'm placing the cell which is basically a shape or complex shape or circle, then dropping it to use the points for other tasks. I am dropping it because I thought that would be the best and easiest way to get the points from the element, but I may be trying to hard to do it... :-| ??

If I placed the cell, getting the endoffile first, could scan the cell(shape) and get the points from the shape without having to drop it? The reason i am using the shapes and complex shapes from cells is because it saves time in the whole scheme of this process, and it's a repeating thing..
:-)

Regards

Rob
 
I assume this is with MS V7 because of all the EDG comments on all the posts. I don't think you need to drop the cell if you don't need to modify any elements within it - note I stated THINK - I'm not really sure. You need to extract the components from the cell. Are you trying to do this with a macro, MDL or UCM I'm running V7 now but I am currently trying to get prepared for V8. I have hundreds of UCMs for V7 and a dozen or so macros. I don't do MDL. Getting the components of your cell in MS V8 with a VBA macro is pretty easy - my first VBA command was an analyze element which when processing cells lists the component elements. I think (that word again), it would be possible to get the component elements in V7 with MS Basic. I've written UCMs that get component elements from Complex strings and textnodes, but I've never trying breaking down a cell to process the components. If you do drop the cell containing a Complex string, you still need to deal with a complex element. You've basically got a complex Element inside another one.

Before I go further please respond:
MS Version:
Language: MDL, Basic, UCM, VBA

I'd like to help if I can, but I'm still not clean as to the ultimate goal here. I have a few books that I could peruse, but I want to clarify what the environment is.
 
Hi Stephen,

I'm running V7.1.1.2 using MSBasic..
If it';s a case of getting the info from the celll when it's placed then you think it is possible to place the cell then scan it and gett the info like datapoints...colours, levels etc.?

Cheers
 
I would think so, but like I said I haven't coded much MSBasic. I've got a book Mapping with Microstation
Volume IV: Macro Programming
by Anthony M. Bonnici
It's pretty good, but when I acquired it I was well entrenched in using UCMs and never switched to Macros, except where UCMs could not get the job done.

I'm looking a MS-V8 now and UCMs are truly dead. MS-BASIC is to follow next according to README with V8. Soooo, I am looking at VBA now. The fundamentals are very similar to MS-BASIC, but the object model is different and the syntax is different. With VBA you can create an Element Object in memory, have it move dynamically on the screen while the user is placing it, and with the final input, the element is created in the file. Pretty cool stuff. I'm still trying to figure a lot of things out and I'm getting a lot of help Via Bentleys Newsgroups on Viecon.

The Cell header should be a MBE_CellHeader element type.

.nextComponent method should aid in scanning the Cell Element

.nextElement method brings you to next element but the latter should enable you to scan the cell components. I'm not sure how to tell when you've read all the components from the cell.

.thisComponent - read/write Integer property. Mark the position of a component element or read the "handle" to a previously marked component.

.componentFilePos returns the file position from which a component element was read.

.isComponent - read-only integer property. Determine if element is a component of complex element. I would think that this is true for your cell.

.firstElement - Set complex element position to the 1st element

"Robert M." wrote:

Hi Stephen,

I'm running V7.1.1.2 using MSBasic..
If it';s a case of getting the info from the celll when it's placed then
you
think it is possible to place the cell then scan it and gett the info like datapoints...colours, levels etc.?

Cheers
goal
: here. I have a few books that I could
peruse, but I want to clarify what the environment is.
 
The fact of the matter is that the component elements of a cell are not written to the end of the design file when a cell is dropped. The header is marked as deleted and the complex bit on the component elements is set to 0, but the component elements are re-written to the same file position as when they were part of the cell. To re-read the component elements after the cell is dropped you will need to get the words to follow of the cell header, add two to that number, and multiply by 2. Add this value to the cell's file position and you will have the file position of the first component element. The rest of the component elements will follow.

You can easily verify this by:
1) Place a cell with a single component element.
2) Place something else like a line.
3) Use analyze to see the file position of the component element in the cell placed in step 1.
4) Drop the cell.
5) Use analyze to see the file position of the element that was dropped from the cell placed in step 1. Both file positions will be the same.
 
I'm not really up to speed at all on Macro programming. My experience is UCMs and now I'm dabbling with VBA in MS-V8. None the less, looking at your code, I'm wondering about a few things. Is the cell really getting dropped? Do you need to send Datapoint to Identify the Cell and a second one to actually drop it. Also make sure you get the EOF position BEFORE dropping the cell. In your snippet, I think that you are getting the EOF after you've already dropped the cell!

"Mike Palmer" wrote:

The fact of the matter is that the component elements of a cell are not written to the end of the design file when a cell is dropped. The header
is
marked as deleted and the complex bit on the component elements is set to
0,
but the component elements are re-written to the same file position as
when
they were part of the cell. To re-read the component elements after the
cell
is dropped you will need to get the words to follow of the cell header,
add
two to that number, and multiply by 2. Add this value to the cell's file position and you will have the file position of the first component
element.
The rest of the component elements will follow.

You can easily verify this by:
1) Place a cell with a single component element.
2) Place something else like a line.
3) Use analyze to see the file position of the component element in the
cell
placed in step 1.
4) Drop the cell.
5) Use analyze to see the file position of the element that was dropped
from
the cell placed in step 1. Both file positions will be the same.
to
> get it again using the file pos the element's not found!! aaarrgh! (heheh).
>
> I'm stuck..can someone help me please!!!
> :-)
>
> Here's the snippet!...
>
> ' SELECT BY CELL
> MbeSendCommand "SELECTBY SETTINGS CELL "
> ' USE CELL NAME AS A TARGET
> MbeSetAppVariable "SELECTBY", "selectorGlobals.cellName", celName ...
 
Status
Not open for further replies.

Latest threads

Back
Top