找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 2096|回复: 0

[分享] Analysing nested Xref in drawings

[复制链接]

已领礼包: 6个

财富等级: 恭喜发财

发表于 2013-7-29 11:35:28 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×

When a drawing has nested external references to other drawings, you may want to know the Xref dependencies that exist within the Xref nodes. For example :  Consider three drawings A, B and C where A is the main drawing, B is an external reference in A and C is an external reference in B. In this case, traversing the Xref graph of A will provide Xref graph nodes for A, B and C, but you may need to be able to get that B is the parent of C and is inserted in A.
Here is a sample code :

<CommandMethod("AnalyseXrefGraph")> _
       Public Shared Sub AnalyseXRefGraphMethod()
    Dim relations As Dictionary(Of [String], [String]) = NewDictionary(Of String, String)()
    AnalyseXref("c:\Temp\Test.dwg", "Test", relations)

    ' Print the results
    Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
    For Each kv As KeyValuePair(Of [String], [String]) In relations
        ed.WriteMessage([String].Format(vbLf & "{0} - {1}", kv.Key, kv.Value))
    Next
End Sub

Public Shared Sub AnalyseXref(ByVal drawingFilePath As [String], ByValbaseNodeName As [String], ByRef relations As Dictionary(Of [String], [String]))
    Dim doc As Document = Application.DocumentManager.MdiActiveDocument
    Dim ed As Editor = doc.Editor

    Using db As New Database(False, True)
        db.ReadDwgFile(drawingFilePath, FileOpenMode.OpenForReadAndWriteNoShare, False, "")
        db.ResolveXrefs(True, False)

        Using tr As Transaction = db.TransactionManager.StartTransaction()
            Dim xg As XrefGraph = db.GetHostDwgXrefGraph(True)
            Dim root As GraphNode = xg.RootNode

            Dim numOfNodes As Integer = xg.NumNodes

            For cnt As Integer = 0 To xg.NumNodes - 1
                Dim node As XrefGraphNode =TryCast(xg.GetXrefNode(cnt), XrefGraphNode)
                If Not node.Database.Filename.Equals(drawingFilePath)Then
                    AnalyseXref(node.Database.Filename, node.Name, relations)
                End If

                If Not node.IsNested Then
                    If Not relations.ContainsKey(node.Name) Then
                        relations.Add(node.Name, baseNodeName)
                    End If
                End If
            Next
            tr.Commit()
        End Using
    End Using
End Sub


Consider a drawing "Test.dwg" that has external references to other drawings as shown in this graph.
The above code snippet will then print the Xref dependencies as :





评分

参与人数 1D豆 +3 收起 理由
ScmTools + 3 资料分享奖!

查看全部评分

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-12-23 07:10 , Processed in 0.406285 second(s), 38 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表