Message 1 of 8
Strange copy method behaviour

Not applicable
10-15-2007
02:52 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a routine that identifies all text starting with certain characters
and adds incremented text to them e.g. for "Test" it returns "Test any text
here-01", "Test different text here-02" etc. The order is determined by the
order things are created in the file. This is OK initially as the user
creates the text logically. The problem occurs when new a new item of text
is added in another part of the drawing and the sequence becomes illogical
for a user trying to find that text.
My solution was to read the origin and sort the text based on Y descending
and X ascending which means the user can find the text by starting at the
top of the drawing , working down and from left to right, then replace the
old text with my new text using the sort order with the .copy then .delete
methods. There are a number of reasons why I have to do it this way rather
than just modify the original text.
This all works fine and I put some debug code in to ensure the sort order
returns what I want before I replace the text. I would expect that the first
text I select and copy would be the first in order when I subsequently scan
the drawing but it is reversed i.e. the last one I replace is teh first in
the drawing. I tried doing teh .copy in one iteration followed by the
.deleet in another but it make no difference. In the end I reversed the sort
order to Y aascendin, X descending and it worked.
Can anyone come up with a plausible explantion? Here is thye function
Function CopyCommodityText() As Boolean
CopyCommodityText = False
On Error GoTo ErrTrap
Dim textCount As Integer
Dim roundVal As Integer
Dim roundY As Integer
roundVal = 500
'restrict to mtext on commodity layer
ReDim gpcode(0 To 2) As Integer
ReDim gpdata(0 To 2) As Variant
gpcode(0) = 8
gpdata(0) = CommodityTextName
gpcode(1) = 0
gpdata(1) = "mtext"
'restrict to model
gpcode(2) = 67
gpdata(2) = 0
'add selection set for commodity text
Set oSSet = ThisDrawing.SelectionSets.Item("sset")
Action = "Clear selection set osset"
oSSet.Clear
Action = "Create selection set osset"
oSSet.Select acSelectionSetAll, , , gpcode, gpdata
If oSSet.Count > 0 Then
'call function to create commmodity text recordset
If CreateRecordset("rsComTexts") = False Then Exit Function
With rsComTexts
.Open , , adOpenDynamic, adLockPessimistic
textCount = 0
'add text with x,y coords
For Each oMtext In oSSet
roundY = oMtext.InsertionPoint(1) / roundVal
.AddNew
.Fields("Handle") = oMtext.Handle
.Fields("x") = oMtext.InsertionPoint(0)
.Fields("y") = roundY
.Update
Next
'reverse sort as bizarrely entites seem to get written in
reverse order
'.Sort = "y DESC, x ASC"
.Sort = "y ASC, x DESC"
'retrieve in x, y order
.MoveFirst
textCount = 0
Do While Not .EOF
Set oMtext = ThisDrawing.HandleToObject(.Fields("Handle"))
'copy entity
Set oEntity = oMtext.Copy
'delete original
oMtext.Delete
.MoveNext
Loop
.Close
End With
End If
TidyUp:
oSSet.Delete
Set oSSet = Nothing
CopyCommodityText = True
Exit Function
ErrTrap:
Select Case Err
Case -2145386476 'selection set doesn't exist
ThisDrawing.SelectionSets.Add "sset"
Resume 'try again
Case Else
MsgBox "Error " & Err & Chr(10) & Err.Description
End Select
End Function
--
Dave Preston
Technical Dev. Engineer
C A Design Services Limited
Address: Design Centre, Hewett Rd, Gapton Hall,
GREAT YARMOUTH,
Norfolk 31 0NN,
Tel: 01493 440444,
Fax: 01493 442480,
E-Mail: dpreston@cadesignservices.co.uk,
Web Site: www.cadesignservices.co.uk,
Registered in England No. 1595687
This e-mail and any attached files is confidential and intended for the
addressee(s) only. It may contain privileged and confidential information,
and may not be disclosed to anyone else. Unauthorised recipients are
requested to preserve this confidentiality by deleting the original and to
advise the sender immediately of any mistakes in transmission. Internet
communications are not secure and therefore C A Design Services Limited does
not accept any legal responsibility for the contents of this message, and
the message and files are opened at the risk of the recipient. Unless
otherwise specifically stated any views or opinions are solely those of the
author and do not represent those of C A De
and adds incremented text to them e.g. for "Test" it returns "Test any text
here-01", "Test different text here-02" etc. The order is determined by the
order things are created in the file. This is OK initially as the user
creates the text logically. The problem occurs when new a new item of text
is added in another part of the drawing and the sequence becomes illogical
for a user trying to find that text.
My solution was to read the origin and sort the text based on Y descending
and X ascending which means the user can find the text by starting at the
top of the drawing , working down and from left to right, then replace the
old text with my new text using the sort order with the .copy then .delete
methods. There are a number of reasons why I have to do it this way rather
than just modify the original text.
This all works fine and I put some debug code in to ensure the sort order
returns what I want before I replace the text. I would expect that the first
text I select and copy would be the first in order when I subsequently scan
the drawing but it is reversed i.e. the last one I replace is teh first in
the drawing. I tried doing teh .copy in one iteration followed by the
.deleet in another but it make no difference. In the end I reversed the sort
order to Y aascendin, X descending and it worked.
Can anyone come up with a plausible explantion? Here is thye function
Function CopyCommodityText() As Boolean
CopyCommodityText = False
On Error GoTo ErrTrap
Dim textCount As Integer
Dim roundVal As Integer
Dim roundY As Integer
roundVal = 500
'restrict to mtext on commodity layer
ReDim gpcode(0 To 2) As Integer
ReDim gpdata(0 To 2) As Variant
gpcode(0) = 8
gpdata(0) = CommodityTextName
gpcode(1) = 0
gpdata(1) = "mtext"
'restrict to model
gpcode(2) = 67
gpdata(2) = 0
'add selection set for commodity text
Set oSSet = ThisDrawing.SelectionSets.Item("sset")
Action = "Clear selection set osset"
oSSet.Clear
Action = "Create selection set osset"
oSSet.Select acSelectionSetAll, , , gpcode, gpdata
If oSSet.Count > 0 Then
'call function to create commmodity text recordset
If CreateRecordset("rsComTexts") = False Then Exit Function
With rsComTexts
.Open , , adOpenDynamic, adLockPessimistic
textCount = 0
'add text with x,y coords
For Each oMtext In oSSet
roundY = oMtext.InsertionPoint(1) / roundVal
.AddNew
.Fields("Handle") = oMtext.Handle
.Fields("x") = oMtext.InsertionPoint(0)
.Fields("y") = roundY
.Update
Next
'reverse sort as bizarrely entites seem to get written in
reverse order
'.Sort = "y DESC, x ASC"
.Sort = "y ASC, x DESC"
'retrieve in x, y order
.MoveFirst
textCount = 0
Do While Not .EOF
Set oMtext = ThisDrawing.HandleToObject(.Fields("Handle"))
'copy entity
Set oEntity = oMtext.Copy
'delete original
oMtext.Delete
.MoveNext
Loop
.Close
End With
End If
TidyUp:
oSSet.Delete
Set oSSet = Nothing
CopyCommodityText = True
Exit Function
ErrTrap:
Select Case Err
Case -2145386476 'selection set doesn't exist
ThisDrawing.SelectionSets.Add "sset"
Resume 'try again
Case Else
MsgBox "Error " & Err & Chr(10) & Err.Description
End Select
End Function
--
Dave Preston
Technical Dev. Engineer
C A Design Services Limited
Address: Design Centre, Hewett Rd, Gapton Hall,
GREAT YARMOUTH,
Norfolk 31 0NN,
Tel: 01493 440444,
Fax: 01493 442480,
E-Mail: dpreston@cadesignservices.co.uk,
Web Site: www.cadesignservices.co.uk,
Registered in England No. 1595687
This e-mail and any attached files is confidential and intended for the
addressee(s) only. It may contain privileged and confidential information,
and may not be disclosed to anyone else. Unauthorised recipients are
requested to preserve this confidentiality by deleting the original and to
advise the sender immediately of any mistakes in transmission. Internet
communications are not secure and therefore C A Design Services Limited does
not accept any legal responsibility for the contents of this message, and
the message and files are opened at the risk of the recipient. Unless
otherwise specifically stated any views or opinions are solely those of the
author and do not represent those of C A De