Copy Nightmare

Copy Nightmare

Anonymous
Not applicable
296 Views
2 Replies
Message 1 of 3

Copy Nightmare

Anonymous
Not applicable
One last go - all of the next process needs to be done in VBA.
I need to open a drawing, select everything in model space, copy it and then open a new drawing based on a specific template and paste everything back into model space. Then save the drawing. I can't get me head around how to copy everything and then open a drawing based on a template. Alot of the examples shown here need a screen selection but I need to do the select all automatically. If anyone can assist I will be very grateful
0 Likes
297 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
How about something like this? Note that there is no error checking and the
code to save the new drawing is not included.....this is merely an example
for you to use that does what you are trying to do.

Sub copyMSpace()
Dim oEnt As AcadEntity
Dim vEnts() As AcadEntity
Dim oLayer As AcadLayer
Dim I As Long
Dim oDwg1 As AcadDocument
Dim oDwg2 As AcadDocument

Set oDwg1 = Application.ActiveDocument
For Each oLayer In oDwg1.Layers
If oLayer.Lock = True Then oLayer.Lock = False
Next
ReDim vEnts(0 To oDwg1.ModelSpace.Count)
For Each oEnt In oDwg1.ModelSpace
Set oLayer = oDwg1.Layers.Item(oEnt.Layer)
If (oLayer.Freeze = False) And (oLayer.LayerOn = True) Then
Set vEnts(I) = oEnt
I = I + 1
End If
Next
ReDim Preserve vEnts(0 To I - 1)

If oDwg1.GetVariable("SDI") = 0 Then
Set oDwg2 = Application.Documents.Add("ACAD.DWT")
Else
Set oDwg2 = oDwg1.New("ACAD.DWT")
End If

oDwg1.CopyObjects vEnts, oDwg2.ModelSpace

End Sub

wrote in message news:5065429@discussion.autodesk.com...
One last go - all of the next process needs to be done in VBA.
I need to open a drawing, select everything in model space, copy it and then
open a new drawing based on a specific template and paste everything back
into model space. Then save the drawing. I can't get me head around how to
copy everything and then open a drawing based on a template. Alot of the
examples shown here need a screen selection but I need to do the select all
automatically. If anyone can assist I will be very grateful
0 Likes
Message 3 of 3

Anonymous
Not applicable
Jeff,

Your code works great, I really appreciate your mail.
Thanks for taking the time to solve me problem.

Regards

Ian
0 Likes