使用CATIA VBA更改工程图链接: 实现工程图链接的修改

Sub ReLink()

   Dim DrawingDoc As DrawingDocument

   Dim DrawingSheets As drawingSheets

   Dim DrawingSheet As drawingSheet

   Dim DrawingView As DrawingView

   Dim DrawingTexts As DrawingTexts

   Dim Text As DrawingText

   Dim Factory As Factory2D

   Dim Point As Point2D

   Dim Line As Line2D

   Dim Circle As Circle2D

   Dim Selection As Selection

   Dim GeometricElements As GeometricElements

   Dim PartName As String

   Dim PartName2 As String

   Dim PartFile As String

   Dim DrawingName As String

   Dim FilePath As String

   Dim Documents As Documents

   Set Documents = CATIA.Documents

   Dim PartDocument As PartDocument

   Dim Product As ProductDocument

   Set DrawingDoc = CATIA.ActiveDocument

   Set DrawingSheets = DrawingDoc.Sheets

   Set Selection = DrawingDoc.Selection

   Set DrawingSheet = DrawingSheets.ActiveSheet

   Set DrawingView = DrawingSheet.Views.ActiveView

   Set DrawingTexts = DrawingView.Texts

   Set Factory = DrawingView.Factory2D

   Set GeometricElements = DrawingView.GeometricElements

   Set MyDrawingDoc = CATIA.ActiveDocument

   MyDrawingDoc.Sheets.Item(1).Activate

   Dim NumberOfViews As Integer

   Dim Windows As Windows

   Set Windows = CATIA.Windows

   DrawingName = CATIA.ActiveWindow.Name

   NumberOfViews = CATIA.ActiveDocument.Sheets.ActiveSheet.Views.Count

   If NumberOfViews > 2 Then

       ' Display file open dialog

       FilePath = CATIA.FileSelectionBox("Choose the file you want to relink to this drawing", "*.*", CatFileSelectionModeOpen)

       If FilePath = "" Then Exit Sub

       Dim a As Integer

       Dim b As Integer

       a = InStr(FilePath, "CATProduct")

       b = InStr(FilePath, "CATPart")

       If a > 0 Then

           Product = Documents.Open(FilePath)

       End If

       If b > 0 Then

           Set PartDocument = Documents.Open(FilePath)

       End If

       Dim NumberOfWindows As Integer

       NumberOfWindows = Windows.Count

       Dim WindowsArray()

       ReDim Preserve WindowsArray(NumberOfWindows)

       For i = 1 To NumberOfWindows

           WindowsArray(i) = Windows.Item(i).Name

           If WindowsArray(i) = DrawingName Then

               Dim SpecsAndGeomWindow As SpecsAndGeomWindow

               Set SpecsAndGeomWindow = Windows.Item(WindowsArray(i))

               SpecsAndGeomWindow.Activate

               Component_Display = "Ok"

           End If

       Next

       For i = 3 To NumberOfViews

           Set DrawingView = CATIA.ActiveDocument.Sheets.ActiveSheet.Views.Item(i)

           ' access links collection

           Dim GenerativeLinks As DrawingViewGenerativeLinks

           Dim LinkedDocument

           DrawingView.GenerativeLinks.RemoveAllLinks

           If a > 0 Then

               DrawingView.GenerativeLinks.AddLink Product.Product

           End If

           If b > 0 Then

               DrawingView.GenerativeLinks.AddLink PartDocument.Product

           End If

           'DrawingView.GenerativeLinks.AddLink

       Next

   Else

       MsgBox ("There are no views to change the links for")

   End If

End Sub

QR Code
微信扫一扫,欢迎咨询~

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 155-2731-8020
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

手机不正确

公司不为空