This is using ADT06. All things being equal is may not be faster
but still worth a try for him... This is on a relatively slow laptop
too.
1000 1 unit lines
1000 mtext = "foo"
MS Count 2000
-0.3901367
MS Count 4000
MS Count 2000
-0.4060059
MS Count 4000
MS Count 2000
-0.4069824
MS Count 4000
[code]
Sub foo()
Dim startTime, endTime
Dim tm(3, 3) As Double
tm(0, 0) = 1: tm(0, 1) = 0
tm(0, 2) = 0: tm(0, 3) = 1
tm(1, 0) = 0: tm(1, 1) = 1
tm(1, 2) = 0: tm(1, 3) = 1
tm(2, 0) = 0: tm(2, 1) = 0
tm(2, 2) = 1: tm(2, 3) = 0
tm(3, 0) = 0: tm(3, 1) = 0
tm(3, 2) = 0: tm(3, 3) = 1
Debug.Print "MS Count " & ThisDrawing.ModelSpace.Count
startTime = VBA.Timer
Dim ent As AcadEntity
Dim iterator As AcadEntity
For Each iterator In ThisDrawing.ModelSpace
If TypeOf iterator Is AcadLine Or _
TypeOf iterator Is AcadMText Then
Set ent = iterator.Copy()
ent.TransformBy tm
End If
Next iterator
endTime = VBA.Timer
Debug.Print endTime - startTime
Debug.Print "MS Count " & ThisDrawing.ModelSpace.Count
End Sub
[/code]
"Laurie Comerford" wrote in message
news:5672536@discussion.autodesk.com...
Hi Paul,
Grabbing some sample code from the help system I ended up with:
Sub TestTransformBy()
Dim oEnt As AcadEntity
Dim oEntDup As AcadEntity
Dim PtStart(0 To 2) As Double
Dim i As Integer
Dim vPt As Variant
Dim lTmp As Long
Dim ssObjects As AcadSelectionSet
Dim TimeStart, TimeEnd
Dim transMat(0 To 3, 0 To 3) As Double
transMat(0, 0) = 1#: transMat(0, 1) = 0#: transMat(0, 2) = 0#:
transMat(0, 3) = 10#
transMat(1, 0) = 0#: transMat(1, 1) = 1#: transMat(1, 2) = 0#:
transMat(1, 3) = 0#
transMat(2, 0) = 0#: transMat(2, 1) = 0#: transMat(2, 2) = 1#:
transMat(2, 3) = 0#
transMat(3, 0) = 0#: transMat(3, 1) = 0#: transMat(3, 2) = 0#:
transMat(3, 3) = 1#
If SelectObjectsOnLayer(ssObjects, "LINE,MTEXT", "*") > 0 Then
TimeStart = 60 * Val(Format(Time, "MM")) + Val(Format(Time, "SS.SSS"))
For Each oEnt In ssObjects
For i = 1 To 1000
Set oEntDup = oEnt.Copy
oEntDup.TransformBy (transMat)
Next i
Next
TimeEnd = 60 * Val(Format(Time, "MM")) + Val(Format(Time, "SS.SSS"))
Debug.Print "1000 Lines and Mtext Items with TransformBy ",
Format(TimeEnd - TimeStart, "#0.0"); "seconds"
End If
End Sub ' ssTest()
For three runs in a drawing containing one line and one MText item this
reported. After each run I simply used the Undo command to remove the new
data.
1000 Lines and Mtext Items with TransformBy 4.0seconds
1000 Lines and Mtext Items with TransformBy 4.0seconds
1000 Lines and Mtext Items with TransformBy 4.0seconds
As it seemed significantly slower for the same data set on my computer I ran
the other methods again with the following results.
1000 Lines and Mtext Items with move 4.0seconds
1000 Lines and Mtext Items with move 4.0seconds
1000 Lines and Mtext Items with move 4.0seconds
1000 Lines and Mtext Items with Original code 2.0seconds
1000 Lines and Mtext Items with Original code 2.0seconds
1000 Lines and Mtext Items with Original code 2.0seconds
The only difference between when the first code was run and new is time
elapsed with AutoCAD open and that there is another 3Mb drawing open
Original Reports
1000 Lines and Mtext Items with entity.move 2.96875 seconds
1000 Lines and Mtext Items with entity.move 2.859375 seconds
1000 Lines and Mtext Items with entity.move 2.984375 seconds
1000 Lines and Mtext Items with Original code 1.609375 seconds
1000 Lines and Mtext Items with Original code 1.65625 seconds
1000 Lines and Mtext Items with Original code 1.609375 seconds
I'd be interested to see the results from your computer as there is nearly a
ten times difference in the output.
Also, my time measurement is more suited to comparisons on one computer than
anything else.
I'm running this in Civil 3D R2008. Although for comparisons with my other
times, that should be irrelevant.
I've never had cause to write code to move objects previously other than for
changing the insertion point of my test doughnut to highlight the point I've
just computed when I'm doing complex geometry and de-bugging. In that type
of code, setting the insertion to a computed point is the obvious answer.
--
Laurie Comerford
CADApps
www.cadapps.com.au
www.civil3Dtools.com
Sub TestTransformBy()
Dim oEnt As AcadEntity
Dim PtStart(0 To 2) As Double
Dim i As Integer
Dim vPt As Variant
Dim lTmp As Long
Dim ssObjects As AcadSelectionSet
Dim TimeStart, TimeEnd
Dim transMat(0 To 3, 0 To 3) As Double
transMat(0, 0) = 1#: transMat(0, 1) = 0#: transMat(0, 2) = 0#:
transMat(0, 3) = 10#
transMat(1, 0) = 0#: transMat(1, 1) = 1#: transMat(1, 2) = 0#:
transMat(1, 3) = 0#
transMat(2, 0) = 0#: transMat(2, 1) = 0#: transMat(2, 2) = 1#:
transMat(2, 3) = 0#
transMat(3, 0) = 0#: transMat(3, 1) = 0#: transMat(3, 2) = 0#:
transMat(3, 3) = 1#
If SelectObjectsOnLayer(ssObjects, "LINE,MTEXT", "*") > 0 Then
TimeStart = Timer
For Each oEnt In ssObjects
For i = 1 To 1000
Set oEnt = oEnt.Copy
oEnt.TransformBy (transMat)
Next i
Next
TimeEnd = Timer
Debug.Print "1000 Lines and Mtext Items with TransformBy ",
TimeEnd - TimeStart; "seconds"
End If
End Sub ' ssTest()
"Paul Richardson" wrote in message
news:5672502@discussion.autodesk.com...
>actually TransformBy is a property... entity.TransformBy
not it's NOT... I was right the first time. WOW! Anyway it's FAST.