Author Topic: External References  (Read 1761 times)

0 Members and 1 Guest are viewing this topic.

DogBone

  • Guest
External References
« on: November 10, 2011, 02:06:07 PM »
I tried to translate Gabriels C code to VB from here: http://www.theswamp.org/index.php?topic=31863.0

I only needed a little bit of it, so below is what I tried:
The problem is when I get to "xREF = Trans.GetObject(xrefID, OpenMode.ForRead)" I get an error saying it can't convert MText object to an external reference object.
I don't understand how an MText object is getting past XrefStatus.Resoved.
I also don't understand...maybe I just answered my own question.

Is the "xREF = Trans.GetObject(xrefID, OpenMode.ForRead)" jumping back over the BTR.XrefStatus and retrieving the parent object ?

Oi...   :ugly:

Code: [Select]
        Dim Doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim CurDb As Database = Doc.Database
        Dim xREF As AcadExternalReference = Nothing
        Dim xrefID As ObjectId = ObjectId.Null

        Using Trans As Transaction = CurDb.TransactionManager.StartTransaction
            Dim BT As BlockTable = Trans.GetObject(CurDb.BlockTableId, OpenMode.ForRead)
            For Each ObjID As ObjectId In BT
                Dim BTR As BlockTableRecord = Trans.GetObject(ObjID, OpenMode.ForRead)
                If BTR.IsFromExternalReference Then
                    If BTR.XrefStatus = XrefStatus.Resolved Then
                        Dim XrefCol As New ObjectIdCollection
                        For Each xrefID In BTR
                            xREF = Trans.GetObject(xrefID, OpenMode.ForRead)
                            If xREF.Name = "SK1-IR" And xREF.Visible Then
                                XrefCol.Add(xrefID)
                                CurDb.UnloadXrefs(XrefCol)
                            ElseIf xREF.Name = "SK1-IR" And Not xREF.Visible Then
                                XrefCol.Add(xrefID)
                                CurDb.ReloadXrefs(XrefCol)
                            End If
                        Next
                    End If
                End If
            Next
        End Using
« Last Edit: November 10, 2011, 02:54:06 PM by DogBone »

DogBone

  • Guest
Re: External References
« Reply #1 on: November 10, 2011, 02:52:45 PM »
Nope...didn't answer my own question.  :blank:

Jeff H

  • Needs a day job
  • Posts: 6150
Re: External References
« Reply #2 on: November 10, 2011, 03:45:03 PM »
You a iterating through the BlockTableRecord of the external reference.
 
Maybe think of it as a special blockdefintion containing all the entities from the xref which are edited from the xref.
 
 

DogBone

  • Guest
Re: External References
« Reply #3 on: November 10, 2011, 07:07:24 PM »
Thanks.
I misunderstood the .IsFromExternalReference to mean the external refrence itself, not the entities in the external reference.

I caught another problem.
The check for XrefStatus.Resolved worked until it was unloaded. Then I couldn't load it again because there was nothing to Resolve. XrefStatus.NotAnXref is much better for my needs.

Now it is a toggle.

Code: [Select]
  <Autodesk.AutoCAD.Runtime.CommandMethod("IRToggle")> _
    Public Sub XrefToggle()
        Dim Doc As Document = Autodesk.AutoCAD.ApplicationServices. _
                         Application.DocumentManager.MdiActiveDocument
        Dim CurDb As Database = Doc.Database

        Using Trans As Transaction = CurDb.TransactionManager.StartTransaction
            Dim BT As BlockTable = Trans.GetObject(CurDb.BlockTableId, OpenMode.ForRead)
            For Each ObjID As ObjectId In BT
                Dim BTR As BlockTableRecord = ObjID.GetObject(OpenMode.ForRead)
                If BTR.XrefStatus = XrefStatus.NotAnXref Then
                Else
                    Dim XrefCol As New ObjectIdCollection
                    If BTR.Name = "SK1-IR" Then
                        If BTR.IsUnloaded Then
                            XrefCol.Add(ObjID)
                            CurDb.ReloadXrefs(XrefCol)
                        Else
                            XrefCol.Add(ObjID)
                            CurDb.UnloadXrefs(XrefCol)
                        End If
                    End If
                End If
            Next
            Trans.Commit()
        End Using
    End Sub

Jeff H

  • Needs a day job
  • Posts: 6150
Re: External References
« Reply #4 on: November 10, 2011, 09:12:15 PM »
You can also do
Quote
If Not BTR.XrefStatus = XrefStatus.NotAnXref Then
                Else