CopyObjects do not copy tables, dimensions and who knows what else ... Why?

CopyObjects do not copy tables, dimensions and who knows what else ... Why?

stekicarYWNUL
Participant Participant
1,159 Views
11 Replies
Message 1 of 12

CopyObjects do not copy tables, dimensions and who knows what else ... Why?

stekicarYWNUL
Participant
Participant

This is the code I am using to copy all objects from one drawing to another.

For some reason it does not copy tables and dimensions. Is there a reason why?

 

 

Option Explicit

Sub CopyAllObjects()

Dim sourceDwg As AcadDocument, destDwg As AcadDocument

Set sourceDwg = ActiveDocument
Set destDwg = Documents.Add

sourceDwg.CopyObjects allObjectsArray(selectAllObjects(sourceDwg)), destDwg.ModelSpace
    
End Sub

Function selectAllObjects(myDoc As AcadDocument) As AcadSelectionSet

Set selectAllObjects = CreateSelectionSet("mySel", myDoc)
myDoc.Application.ZoomAll
selectAllObjects.Select acSelectionSetAll
    
End Function

Function allObjectsArray(ss As AcadSelectionSet)
Dim iEnt As Long

ReDim Objects(0 To ss.count - 1) As AcadEntity
For iEnt = 0 To ss.count - 1
    Set Objects(iEnt) = ss.Item(iEnt)
Next iEnt
allObjectsArray = Objects

End Function

Function CreateSelectionSet(SSset As String, Optional myDoc As Variant) As AcadSelectionSet
If IsMissing(myDoc) Then Set myDoc = ThisDrawing

On Error Resume Next
Set CreateSelectionSet = myDoc.SelectionSets(SSset)
If Err Then
    Set CreateSelectionSet = myDoc.SelectionSets.Add(SSset)
Else
    CreateSelectionSet.Clear
End If
End Function

 

 

--Moderator edit: Changed the code format to VB.

0 Likes
Accepted solutions (1)
1,160 Views
11 Replies
Replies (11)
Message 2 of 12

Ed__Jobe
Mentor
Mentor

When you step through the code below, can you verify that the objects have been selected? Are they on a locked layer?

For iEnt = 0 To ss.count - 1
    Set Objects(iEnt) = ss.Item(iEnt)
Next iEnt

As a quick test, create a command that simply does SelectAll and then set ss.Highlight= true. See if the dims and tables got selected.

If you still can't figure it out, upload a copy of your dwgs.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 12

stekicarYWNUL
Participant
Participant

It gets transferred to Objects array:

stekicarYWNUL_0-1677001438709.png

Rectangles that go around base dimensions get transferred, but no dimensions. Layers are not locked.

0 Likes
Message 4 of 12

Ed__Jobe
Mentor
Mentor

What version of AutoCAD are you using and does it have the latest service pack installed?

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 5 of 12

stekicarYWNUL
Participant
Participant

2018 All service packs installed.

0 Likes
Message 6 of 12

Ed__Jobe
Mentor
Mentor

There is something wrong with your file. I used your routine on my template and it worked fine. What is weird is that the dim and table show up in paperspace. After I selected the table from a paperspace viewport, it showed up in modelspace, but not the dim. 🤔

 

I made a couple of changes to your code for testing and it ran much faster by iterating modelspace than using a selection set. You also don't have to zoom all.


Sub CopyAllObjects()

    Dim sourceDwg As AcadDocument, destDwg As AcadDocument
    Dim oEnts As Variant 'added just to observe contents
    
    Set sourceDwg = ActiveDocument
    Set destDwg = Documents.Add
    oEnts = allObjectsArray2(sourceDwg)
    sourceDwg.CopyObjects oEnts, destDwg.ModelSpace
    
End Sub

Function allObjectsArray2(dwg As AcadDocument)
    Dim iEnt As Long
    Dim oEnt As AcadEntity
    
    
    ReDim Objects(0 To dwg.ModelSpace.Count - 1) As AcadEntity
    For iEnt = 0 To dwg.ModelSpace.Count - 1
        Set Objects(iEnt) = dwg.ModelSpace.Item(iEnt)
    Next iEnt
    allObjectsArray2 = Objects

End Function

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 7 of 12

stekicarYWNUL
Participant
Participant

I am making DWG file from PTC Creo software. Let me check your code.

0 Likes
Message 8 of 12

Ed__Jobe
Mentor
Mentor
Accepted solution

If you are copying from a file created in Creo, perhaps their definition for dims and tables is different from adesk's. They may not be translating properly.

 

This doc provides info on compatibility with Creo using the IMPORT command. Have you tried just linking to a Creo file using IMPORT? The view in the dwg is dynamic with the Creo part. Also, maybe the problem lies with the fact that you are still on 2018. I'm using 2023. Perhaps the version of Creo you are using is newer than what is supported by acad 2018?

 

Since you are copying everything, another option would be sourceDoc.SaveAs(destinationPath)

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 9 of 12

stekicarYWNUL
Participant
Participant

Creo, when used with part_layer option exports layers closest to what I need. Downside is that main view scale goes to 1:1. They do not mention anything about dims and tables though. But, from what you helped me to find out is that tables and dims are set for paperspace which makes no sense. I will have to find out why is that happening.

 

On a side note, I am trying to filter selectionset to select only AcadMText, AcadSolid, AcadBlockReference and AcadLeader and I am using:

    Dim filterType(3) As Integer
    Dim filterData(3) As Variant
    filterType(0) = 0
    filterData(0) = "AcadMText"
    filterType(1) = 0
    filterData(1) = "AcadSolid"
    filterType(2) = 0
    filterData(2) = "AcadBlockReference"
    filterType(3) = 0
    filterData(3) = "AcadLeader"
    
    selectAllObjects.Select acSelectionSetAll, , , filterType, filterData

But it does not work. I tried to find valid naming convention for this search on AutoCAD help but to no available.

Thank you for your help.

0 Likes
Message 10 of 12

Ed__Jobe
Mentor
Mentor

This doc provides info on compatibility with Creo using the IMPORT command. Have you tried just linking to a Creo file using IMPORT? The view in the dwg is dynamic with the Creo part. Also, maybe the problem lies with the fact that you are still on 2018. I'm using 2023. Perhaps the version of Creo you are using is newer than what is supported by acad 2018?

 

For selection set filters, you need to use the object's DXF name. Use the LIST command to see what the the group code 0 name is.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 11 of 12

stekicarYWNUL
Participant
Participant

AutoCAD cannot open Creo's DRW files. It can open 3D prt & asm files.

 

LIST command returns:

stekicarYWNUL_1-1677009366206.png

And I do not see object type for selected item.

 

I guess, I will not be able to use existing code. I have found one code that is saving file to block and then place it in new drawing. That way everything moves correctly. Although, I did not check if dimensions displaying correct values ...

Thank you for your help!

0 Likes
Message 12 of 12

Ed__Jobe
Mentor
Mentor

Sorry, I use a lisp I wrote called ENTLIST. See attached. Block references are "INSERT"  dxf objects. You can also refer to the DXF reference.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes