Author Topic: Proxy entities  (Read 11518 times)

0 Members and 1 Guest are viewing this topic.

DaveW

  • Guest
Re: Proxy entities
« Reply #15 on: September 06, 2006, 05:49:48 PM »
Nice try Chuck.

It gave me this error:

After deleting the paperspace viewports the drawing then crashes with a fatal error.

The drawing is attached if you are interested. I ran it through on ACAD 2002.

Once cleaned, viewports deleted and saved, before crashing, if I close and reopen it it appears stable and the proxy warning is gone.

« Last Edit: September 06, 2006, 05:56:12 PM by DaveW »

DaveW

  • Guest
Re: Proxy entities
« Reply #16 on: September 06, 2006, 06:03:15 PM »
It works on MDT drawings too. Very nice! It does crash too after deleting a viewport and moving around. Not a big deal, just save the drawing, then open it, then delete allt he layout tabs and save it again.

Kind of strange, but very useful indeed.

Oh, BTW, I did not get the error in the picture above on an MDT drawing.

Chuck Gabriel

  • Guest
Re: Proxy entities
« Reply #17 on: September 06, 2006, 09:59:09 PM »
Next iteration:

Code: [Select]
Option Explicit

Private Const ERR_DUPLICATE_KEY As Long = -2145386475

Sub main()
  Dim sourceDoc As AcadDocument
  Dim targetDoc As AcadDocument
  Set sourceDoc = Application.ActiveDocument
  Set targetDoc = Documents.Add
  scanObjects sourceDoc, targetDoc
  Application.ZoomExtents
  Set targetDoc = Nothing
End Sub

Private Sub scanObjects(ByRef sourceDoc As AcadDocument, _
                        ByRef targetDoc As AcadDocument)
 
  On Error GoTo ERROR_HANDLER
 
  Dim sourceBlock As AcadBlock
  For Each sourceBlock In sourceDoc.Blocks
    If Not sourceBlock.IsLayout And _
    Not sourceBlock.IsXRef And _
    Left(sourceBlock.Name, 1) <> "*" Then
      Dim index As Long
      Dim objects() As AcadObject
      index = -1
      ReDim objects(0 To sourceBlock.Count) As AcadObject
      Dim ent As AcadEntity
      For Each ent In sourceBlock
        If ent.ObjectName <> "AcDbZombieEntity" Then
          If ent.HasExtensionDictionary Then
            scanDictionary ent.GetExtensionDictionary
          End If
          index = index + 1
          Set objects(index) = ent
        End If
      Next ent
      Set ent = Nothing
      If index > -1 Then
        Dim targetBlock As AcadBlock
        Set targetBlock = targetDoc.Blocks.Add(sourceBlock.Origin, sourceBlock.Name)
        ReDim Preserve objects(index) As AcadObject
        sourceDoc.CopyObjects objects, targetBlock
      End If
    End If
  Next sourceBlock
  Set sourceBlock = Nothing
 
  Dim sourceLayout As AcadLayout
  For Each sourceLayout In sourceDoc.Layouts
    index = -1
    ReDim objects(0 To sourceLayout.block.Count) As AcadObject
    For Each ent In sourceLayout.block
      If ent.ObjectName <> "AcDbZombieEntity" Then
        If ent.HasExtensionDictionary Then
          scanDictionary ent.GetExtensionDictionary
        End If
        index = index + 1
        Set objects(index) = ent
      End If
    Next ent
    Set ent = Nothing
    If index > -1 Then
      Dim targetLayout As AcadLayout
      Set targetLayout = targetDoc.Layouts.Add(sourceLayout.Name)
      ReDim Preserve objects(index) As AcadObject
      sourceDoc.CopyObjects objects, targetLayout.block
    End If
  Next sourceLayout
  Set sourceLayout = Nothing

  Exit Sub

ERROR_HANDLER:

  Select Case Err
    Case ERR_DUPLICATE_KEY
      Set targetLayout = targetDoc.Layouts(sourceLayout.Name)
      Resume Next
    Case Else
      Err.Raise Err.Number, Err.Source, Err.Description, Err.HelpFile, Err.HelpContext
  End Select

End Sub

Sub scanDictionary(ByRef dictionary As AcadDictionary)
  Dim obj As AcadObject
  For Each obj In dictionary
    If TypeOf obj Is AcadDictionary Then
      scanDictionary obj
    ElseIf obj.ObjectName Like "AcDbZombie*" Then
      obj.Delete
    ElseIf obj.HasExtensionDictionary Then
      scanDictionary obj.GetExtensionDictionary
    End If
  Next obj
  Set obj = Nothing
End Sub

DaveW

  • Guest
Re: Proxy entities
« Reply #18 on: September 06, 2006, 11:04:49 PM »
Works flawlessly on mDT and ADT drawings!!!!

Great job Chuck. You know your stuff.

Thank you very much for your time and sharing.


Dave


Dinosaur

  • Guest
Re: Proxy entities
« Reply #19 on: September 07, 2006, 12:10:20 AM »
This is a bit off topic, but every time I see a new post in this thread, this old civil engineering type phart gets more alarmed.  Have you yet determined what these proxy objects are that you are eliminating?  Do you anticipate ever sending your file back to the department that created these files?  Are they part of what is normally displayed in the drawing?

If I were to send you a Civil 3D drawing that had been exported to AutoCAD and you applied a routine to purge all proxy objects,  you would have little more than the title block and whatever annotation that was placed in the layout tabs remaining in the drawing.  Virtually everything in the model will come to you as proxy objects.  These objects are protected from manipulation because ANY such tampering would render them useless if they were again opened in Civil 3D and it is doubtful they could open the drawing at all.

DaveW

  • Guest
Re: Proxy entities
« Reply #20 on: September 07, 2006, 06:01:53 PM »
My opinion is your wrong to use any software to puts anything in drawing that is not 100% controllable by the person receiving it. Period. No if's, and's or but's.

When I work in a drawing it is mine and only mine. I will not accept anything less.

Nothing belongs in DWG that is not 100% dxf compliant across all platforms. The programmers of your custom objects should have coded what they were aiming at another way. They were were wrong to do what they did.  People should not buy and use their software, effectively giving away the rights of the end user to have complete control of all data on his machine.

Again, this is my opinion, but I stand by it firmly. As far as I am concerned it is taking out the trash.


Sorry it sounds so harsh man. I am really passionate about this issue. It is nothing presonal with you at all.
« Last Edit: September 07, 2006, 06:04:59 PM by DaveW »

DaveW

  • Guest
Re: Proxy entities
« Reply #21 on: September 07, 2006, 06:06:49 PM »
if they were again opened in Civil 3D and it is doubtful they could open the drawing at all.

it is just a clean dwg. if they can open that, they are fine.

I am pretty sure Adesk will not be too happy with Chucks code. I can say I know of several happy people using it already.

Dinosaur

  • Guest
Re: Proxy entities
« Reply #22 on: September 07, 2006, 06:39:06 PM »
Sorry it sounds so harsh man. I am really passionate about this issue. It is nothing presonal with you at all.
No problems here.  The main problem is that Autodesk is trying to make non-Autodesk (catia) compatible with dwg and still do all of its magic - it is not working yet.  In reality, a 2007 Civil 3D dwg file is only fully compatible with 2007 Civil 3D.  Autodesk has created a situation that is just unacceptable in my opinion.
if they were again opened in Civil 3D and it is doubtful they could open the drawing at all.

it is just a clean dwg. if they can open that, they are fine.

I am pretty sure Adesk will not be too happy with Chucks code. I can say I know of several happy people using it already.
I was meaning that Civil 3D may not be able to open the file again if an object were altered, a recovery sometimes will fix it but one should not depend on that working. . . even saving in something other than Civil 3D usually requires a recover operation.