.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Renaming Xref changing the layer display

4 REPLIES 4
Reply
Message 1 of 5
Ajilal.Vijayan
999 Views, 4 Replies

Renaming Xref changing the layer display

Hi,

I am trying to rename all the xref's on the drawing with suffix "_renamed"
With the code shown below , I am able to do this.
But the problem I am facing is once the code renamed and reloaded the xref, the Xref-dependent layer properties are changing to Xref source layer properties.

Also the VISRETAIN variable is 1.

Please find the code below.

 

 

Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput

Namespace ATK_XRF_RENAME
    Public Class ATK_XRF_RENAME
        <CommandMethod("ATK-XRF-RENAME-TEST")> _
        Public Sub ATK_XRF_RENAME()

            Dim DOC As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
            Dim ED As Editor = DOC.Editor
            Dim DB As Database = DOC.Database
            Dim TM As Autodesk.AutoCAD.DatabaseServices.TransactionManager = DB.TransactionManager
            Dim Xref_Rslvd_name_frm_Path As List(Of String) = New List(Of String)
            Dim Xref_Rslvd_id_col As ObjectIdCollection = New ObjectIdCollection

            Dim Xref_Not_Found_Name As List(Of String) = New List(Of String)
            Dim Xref_Not_Found_id_col As ObjectIdCollection = New ObjectIdCollection

            'Get the Xref Graph for the Current Drawing.
            Dim Xref_Graph As XrefGraph = DB.GetHostDwgXrefGraph(True)

            'If the Xref Graph contains one node then No Xref is attached and EXIT the program.
            If Xref_Graph.NumNodes = 1 Then
                ED.WriteMessage(vbCrLf + "Xref not found on this drawing")
                Return
            End If

            'Get the Current Drawing name to check and avoid finding the same reference.
            Dim Crnt_Dwg_Name As String = System.Convert.ToString(Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("DWGNAME"))
            Crnt_Dwg_Name = Crnt_Dwg_Name.Substring(0, Crnt_Dwg_Name.Length - 4)

            'Loop through each xref node to get the actual xref drawing name , not the screen name
            For X = 0 To Xref_Graph.NumNodes - 1
                Dim XNODE As XrefGraphNode = Xref_Graph.Node(X)


                If XNODE.Name.ToLower <> Crnt_Dwg_Name.ToLower Then 'If not the current drawing itself.
                    If XNODE.IsNested = False Then 'If the xref is not Nested.
                        If XNODE.XrefStatus = XrefStatus.Resolved Then
                            Dim File_name_frm_Path As String = System.IO.Path.GetFileName(XNODE.Database.OriginalFileName)
                            File_name_frm_Path = File_name_frm_Path.Substring(0, File_name_frm_Path.Length - 4)
                            Xref_Rslvd_name_frm_Path.Add(File_name_frm_Path)
                            Xref_Rslvd_id_col.Add(XNODE.BlockTableRecordId)
                        Else
                            'If XNODE.XrefStatus = XrefStatus.FileNotFound Then
                            'Xref_Not_Found_Name.Add(XNODE.Name)
                            'Xref_Not_Found_id_col.Add(XNODE.BlockTableRecordId)
                        End If
                    End If
                End If
            Next


            If Not Xref_Rslvd_id_col.Count = 0 Then
                Using TR As Transaction = TM.StartTransaction
                    For Each ID As ObjectId In Xref_Rslvd_id_col
                        Dim obj As DBObject = TR.GetObject(ID, OpenMode.ForWrite)
                        Dim BLK As BlockTableRecord = DirectCast(obj, BlockTableRecord)
                        BLK.Name = BLK.Name + "_renamed"
                    Next
                    DB.ReloadXrefs(Xref_Rslvd_id_col)
                    TR.Commit()
                End Using
            End If


        End Sub
    End Class
End Namespace

 

4 REPLIES 4
Message 2 of 5
pendean
in reply to: Ajilal.Vijayan

>>>...But the problem I am facing is once the code renamed and reloaded the xref, the Xref-dependent layer properties are changing to Xref source layer properties...<<<

 

That's how AutoCAD works: a core function/feature: you probably did not notice, but Xref-Dependent block names changed too.

 

May I ask what is the exact purpose of tagging an XREF as "renamed"? How is that critical to your workflow? Perhaps other ways are available.

Message 3 of 5
Ajilal.Vijayan
in reply to: pendean

Hi,

Thanks for the reply.

 

I have a spread sheet with two columns named Old Xref name and New Xref name.

My program looking for a match with the Old Xref name column, and if its find one , will rename to the new name corresponding to the New Xref name found in the spreadsheet.

 

 

Message 4 of 5

See my reply on theswamp.org

Message 5 of 5

Hi,

 

I tried as per the reply , but no luck.

Please see my reply in Swamp.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost