Strange copy method behaviour

Strange copy method behaviour

Anonymous
Not applicable
364 Views
7 Replies
Message 1 of 8

Strange copy method behaviour

Anonymous
Not applicable
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
0 Likes
365 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable
Aplogies for the tismyping errors

--
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
"Dave Preston" wrote in message
news:5749529@discussion.autodesk.com...
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
0 Likes
Message 3 of 8

Anonymous
Not applicable
I don't think you can reliably depend on acad returning objects in the order
of creation when you make a selection set
In theory one should be able to depend on handles being in ascending order,
but I don't think that's even reliable

It does sound like you want the "locational" ordering that you're doing

I'm not sure I'm understanding exactly what's not working for you
but you say you're needing to sort in opposite order to what you'd expect,
so one possibility comes to mind that I've come across in the past.

One oddity that I've noticed in the past which gave unexpected results
(not sure if it was the same as what you're experiencing but anyway...)

when you need to work with points like your insertion points

roundY = oMtext.InsertionPoint(1) / roundVal
.Fields("x") = oMtext.InsertionPoint(0)

the weirdly unlogical fact is that the above won't work properly, but the
following will...
'first assign to a variant the insertion point
vInsPt = oMtext.InsertionPoint
'then use the variant to get the array elements
roundY = vInsPt(1) / roundVal
.Fields("x") = vInsPt(0)

no idea why that *should* make a difference and it may not help in your case
at all,
just something I remember fighting in the past so hopefully it might help

Mark


"Dave Preston" wrote in message
news:5749529@discussion.autodesk.com...
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

snip
0 Likes
Message 4 of 8

Anonymous
Not applicable
Autodesk made a change to the internal selection
mechanism (don't recall what release it first showed
up in, I think 2005), and the result of that was that
selection sets became completely unordered, even
when objects were picked individually they would not
appear in the order picked.

This broke thousands of customer applications that
relied on the assumption that picked objects would
appear in the selection set in the order they were
picked.

This was easily remedied in ObjectARX, where the
order that objects were picked could be deduced
by using a callback, but unfortunately, there is no
such cure for LISP.

If you need to have the user pick objects in some
meaningful order, you need to use a loop that calls
(entsel) to get them, and puts them in a list, like
this:

(defun pickem ( / lst e )
(while (setq e (entsel "\nPick an object: "))
(setq lst (cons (car e) lst))
)
(reverse lst)
)


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

"Dave Preston" wrote in message news:5749529@discussion.autodesk.com...
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
0 Likes
Message 5 of 8

Anonymous
Not applicable
Thanks for your time and response Mike. I have replied more thoroughly to
Tony's response.

--
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
"MP" wrote in message
news:5750471@discussion.autodesk.com...
I don't think you can reliably depend on acad returning objects in the order
of creation when you make a selection set
In theory one should be able to depend on handles being in ascending order,
but I don't think that's even reliable

It does sound like you want the "locational" ordering that you're doing

I'm not sure I'm understanding exactly what's not working for you
but you say you're needing to sort in opposite order to what you'd expect,
so one possibility comes to mind that I've come across in the past.

One oddity that I've noticed in the past which gave unexpected results
(not sure if it was the same as what you're experiencing but anyway...)

when you need to work with points like your insertion points

roundY = oMtext.InsertionPoint(1) / roundVal
.Fields("x") = oMtext.InsertionPoint(0)

the weirdly unlogical fact is that the above won't work properly, but the
following will...
'first assign to a variant the insertion point
vInsPt = oMtext.InsertionPoint
'then use the variant to get the array elements
roundY = vInsPt(1) / roundVal
.Fields("x") = vInsPt(0)

no idea why that *should* make a difference and it may not help in your case
at all,
just something I remember fighting in the past so hopefully it might help

Mark


"Dave Preston" wrote in message
news:5749529@discussion.autodesk.com...
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

snip
0 Likes
Message 6 of 8

Anonymous
Not applicable
Many thanks Tony,
I tried my best to explain it but I obviously failed somewhat:-

The method of selection is unimportant as I sort on the x, y co-ordinates in
a recordset then retrieve the entities by it's Handle.
I know the order is correct as I can zoom to each entity in order of the
recordset and I get what I expect i.e. top left first

The issue is when I use the .copy method using the recordset order. I would
expect the first entity that I copy to become the first new entity in the
model, but after I have copied them all then scan through the file it is
the last, using For Each oEntity In ThisDrawing.ModelSpace, so SelectionSet
ordering does not come into it. I don't see how this is possible, it's as if
the first entity gets shuffled later in the file when the next one is
copied. Does this explanation make sense and does it suggest what the
problem could be?

--
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
"Tony Tanzillo" wrote in message
news:5750535@discussion.autodesk.com...
Autodesk made a change to the internal selection
mechanism (don't recall what release it first showed
up in, I think 2005), and the result of that was that
selection sets became completely unordered, even
when objects were picked individually they would not
appear in the order picked.

This broke thousands of customer applications that
relied on the assumption that picked objects would
appear in the selection set in the order they were
picked.

This was easily remedied in ObjectARX, where the
order that objects were picked could be deduced
by using a callback, but unfortunately, there is no
such cure for LISP.

If you need to have the user pick objects in some
meaningful order, you need to use a loop that calls
(entsel) to get them, and puts them in a list, like
this:

(defun pickem ( / lst e )
(while (setq e (entsel "\nPick an object: "))
(setq lst (cons (car e) lst))
)
(reverse lst)
)


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

"Dave Preston" wrote in message
news:5749529@discussion.autodesk.com...
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
0 Likes
Message 7 of 8

Anonymous
Not applicable
Apologies Tony, you are spot on. My subsequent code that writes the "01"
suffix was using a selection set. I changed it to scanning each entity in
ModelSpace and it works. Many many thanks

--
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
"Dave Preston" wrote in message
news:5750609@discussion.autodesk.com...
Many thanks Tony,
I tried my best to explain it but I obviously failed somewhat:-

The method of selection is unimportant as I sort on the x, y co-ordinates in
a recordset then retrieve the entities by it's Handle.
I know the order is correct as I can zoom to each entity in order of the
recordset and I get what I expect i.e. top left first

The issue is when I use the .copy method using the recordset order. I would
expect the first entity that I copy to become the first new entity in the
model, but after I have copied them all then scan through the file it is
the last, using For Each oEntity In ThisDrawing.ModelSpace, so SelectionSet
ordering does not come into it. I don't see how this is possible, it's as if
the first entity gets shuffled later in the file when the next one is
copied. Does this explanation make sense and does it suggest what the
problem could be?

--
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
"Tony Tanzillo" wrote in message
news:5750535@discussion.autodesk.com...
Autodesk made a change to the internal selection
mechanism (don't recall what release it first showed
up in, I think 2005), and the result of that was that
selection sets became completely unordered, even
when objects were picked individually they would not
appear in the order picked.

This broke thousands of customer applications that
relied on the assumption that picked objects would
appear in the selection set in the order they were
picked.

This was easily remedied in ObjectARX, where the
order that objects were picked could be deduced
by using a callback, but unfortunately, there is no
such cure for LISP.

If you need to have the user pick objects in some
meaningful order, you need to use a loop that calls
(entsel) to get them, and puts them in a list, like
this:

(defun pickem ( / lst e )
(while (setq e (entsel "\nPick an object: "))
(setq lst (cons (car e) lst))
)
(reverse lst)
)


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

"Dave Preston" wrote in message
news:5749529@discussion.autodesk.com...
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
0 Likes
Message 8 of 8

Anonymous
Not applicable
Hi Dave.

As you've already seemed to have found, the ordering
issue applies to all selection sets that are aquired
interactively, not just those that involve individually
picked objects.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

"Dave Preston" wrote in message news:5750609@discussion.autodesk.com...
Many thanks Tony,
I tried my best to explain it but I obviously failed somewhat:-

The method of selection is unimportant as I sort on the x, y co-ordinates in
a recordset then retrieve the entities by it's Handle.
I know the order is correct as I can zoom to each entity in order of the
recordset and I get what I expect i.e. top left first

The issue is when I use the .copy method using the recordset order. I would
expect the first entity that I copy to become the first new entity in the
model, but after I have copied them all then scan through the file it is
the last, using For Each oEntity In ThisDrawing.ModelSpace, so SelectionSet
ordering does not come into it. I don't see how this is possible, it's as if
the first entity gets shuffled later in the file when the next one is
copied. Does this explanation make sense and does it suggest what the
problem could be?

--
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
"Tony Tanzillo" wrote in message
news:5750535@discussion.autodesk.com...
Autodesk made a change to the internal selection
mechanism (don't recall what release it first showed
up in, I think 2005), and the result of that was that
selection sets became completely unordered, even
when objects were picked individually they would not
appear in the order picked.

This broke thousands of customer applications that
relied on the assumption that picked objects would
appear in the selection set in the order they were
picked.

This was easily remedied in ObjectARX, where the
order that objects were picked could be deduced
by using a callback, but unfortunately, there is no
such cure for LISP.

If you need to have the user pick objects in some
meaningful order, you need to use a loop that calls
(entsel) to get them, and puts them in a list, like
this:

(defun pickem ( / lst e )
(while (setq e (entsel "\nPick an object: "))
(setq lst (cons (car e) lst))
)
(reverse lst)
)


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

"Dave Preston" wrote in message
news:5749529@discussion.autodesk.com...
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
0 Likes