Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change drawing links 3

Status
Not open for further replies.

TiagoFigueiredo

Industrial
May 22, 2013
494
PT
I have a drawing with several views, that drawing corresponds to several similar parts. So I create a drawing that I create a template, and now I want to recreate those drawings.

What's the easiest way to do it?

Replace links one by one?

Any macro? Anyone have built something similar, how?

Tiago Figueiredo
Tooling Engineer

Youtube channel:
 
Replies continue below

Recommended for you

if you create a 3D template and a drawing linked to that 3D template, and if all 3D parts are made from the 3D template (or from a part made from the template) then you will be able to modify the link of the drawing to the 3D part. (the template here is just a regular part, it is just that you use it to make the other part using files save as, of file new from)

if you made your 3D part as new file then you wont be able to link your drawing to it.

Eric N.
indocti discant et ament meminisse periti
 
2017-06-19_08_56_38-_tyxvqc.png


Regards
Fernando

- Romania
- EU
 
Ferdo Need your help.

What should be in Product1?

I have tried the document file, and there is an error


DrwView.GenerativeLinks.AddLink Product1

I have tried open the file and use the value of Product1, and error again
Product1 = documents1.Open(strFilePath)

Can you help me?

Tiago Figueiredo
Tooling Engineer

Youtube channel:
 
This is what I wrote.
Code:
Sub ReLink()

Dim DrwDocument         As DrawingDocument
Dim DrwSheets           As DrawingSheets
Dim DrwSheet            As DrawingSheet
Dim DrwView             As DrawingView
Dim DrwTexts            As DrawingTexts
Dim Text                As DrawingText
Dim Fact                As Factory2D
Dim Point               As Point2D
Dim Line                As Line2D
Dim Cicle               As Circle2D
Dim Selection           As Selection
Dim GeomElems           As GeometricElements
Dim Part_name           As String
Dim Drawing_name        As String
Dim strFilePath         As String
Dim documents1          As Documents
Dim partDocument1       As PartDocument
Dim Product1            As ProductDocument
Dim Number_View         As Integer
Dim windows1            As Windows
Dim a                   As Integer
Dim b                   As Integer
Dim specsAndGeomWindow1 As SpecsAndGeomWindow

  Set documents1 = CATIA.Documents
  Set DrwDocument = CATIA.ActiveDocument
  Set DrwSheets = DrwDocument.Sheets
  Set Selection = DrwDocument.Selection
  Set DrwSheet = DrwSheets.ActiveSheet
  Set DrwView = DrwSheet.Views.ActiveView
  Set DrwTexts = DrwView.Texts
  Set Fact = DrwView.Factory2D
  Set GeomElems = DrwView.GeometricElements
  Set MyDrawingDoc = CATIA.ActiveDocument
  
  
  MyDrawingDoc.Sheets.Item(1).Activate
  Set windows1 = CATIA.Windows
  Drawing_name = CATIA.ActiveWindow.Name
  Number_View = CATIA.ActiveDocument.Sheets.ActiveSheet.Views.Count

If Number_View > 2 Then

 strFilePath = CATIA.FileSelectionBox("Select the CATPart or CATProduct, that you want to relink to this drawing", "*.*", CatFileSelectionModeOpen)

If strFilePath = "" Then
Exit Sub
End If


a = InStr(strFilePath, "CATProduct")
b = InStr(strFilePath, "CATPart")

If a > 0 Then

Product1 = documents1.Open(strFilePath)

End If

If b > 0 Then

Set partDocument1 = documents1.Open(strFilePath)
End If

 Dim Num_Janelas As Integer
 Num_Janelas = windows1.Count
 Dim Janelas_array()

 ReDim Preserve Janelas_array(Num_Janelas)
       
        For i = 1 To Num_Janelas
            Janelas_array(i) = windows1.Item(i).Name
            
            If Janelas_array(i) = Drawing_name Then
            Set specsAndGeomWindow1 = windows1.Item(Janelas_array(i))
            specsAndGeomWindow1.Activate
            End If
            
        Next


For i = 3 To Number_View
Set DrwView = CATIA.ActiveDocument.Sheets.ActiveSheet.Views.Item(i)

' access links collection
Dim oGenLinks As DrawingViewGenerativeLinks
Dim linkedDocument

DrwView.GenerativeLinks.RemoveAllLinks

If a > 0 Then

DrwView.GenerativeLinks.AddLink Product1

End If

If b > 0 Then

DrwView.GenerativeLinks.AddLink partDocument1

End If

'DrwView.GenerativeLinks.AddLink
Next

Else
MsgBox ("There is no view to change links")

End If

End Sub


Tiago Figueiredo
Tooling Engineer

Youtube channel:
 
Found it. I was forgeting to put in addlink Product1.Product
Code:
Sub ReLink()

Dim DrwDocument   As DrawingDocument
Dim DrwSheets     As drawingSheets
Dim DrwSheet      As drawingSheet
Dim DrwView       As DrawingView
Dim DrwTexts      As DrawingTexts
Dim Text          As DrawingText
Dim Fact          As Factory2D
Dim Point         As Point2D
Dim Line          As Line2D
Dim Cicle         As Circle2D
Dim Selection     As Selection
Dim GeomElems     As GeometricElements
Dim Part_name     As String
Dim Part_name2     As String
Dim Part_File     As String
Dim Drawing_name As String
Dim strFilePath As String


Dim documents1 As Documents
Set documents1 = CATIA.Documents

Dim partDocument1 As PartDocument
Dim Product1 As ProductDocument


  Set DrwDocument = CATIA.ActiveDocument
  Set DrwSheets = DrwDocument.Sheets
  Set Selection = DrwDocument.Selection
  Set DrwSheet = DrwSheets.ActiveSheet
  Set DrwView = DrwSheet.Views.ActiveView
  Set DrwTexts = DrwView.Texts
  Set Fact = DrwView.Factory2D
  Set GeomElems = DrwView.GeometricElements
 Set MyDrawingDoc = CATIA.ActiveDocument
 MyDrawingDoc.Sheets.Item(1).Activate
Dim Number_View As Integer
Dim windows1 As Windows
 Set windows1 = CATIA.Windows


Drawing_name = CATIA.ActiveWindow.Name


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

If Number_View > 2 Then



'Display file open dialog
 strFilePath = CATIA.FileSelectionBox("Escolha o ficheiro que pretende fazer o relink para este desenho", "*.*", CatFileSelectionModeOpen)

If strFilePath = "" Then
Exit Sub
End If

Dim a As Integer
Dim b As Integer
a = InStr(strFilePath, "CATProduct")
b = InStr(strFilePath, "CATPart")


If a > 0 Then

Product1 = documents1.Open(strFilePath)

End If

If b > 0 Then

Set partDocument1 = documents1.Open(strFilePath)

End If


Dim Num_Janelas As Integer
 Num_Janelas = windows1.Count
 Dim Janelas_array()


 ReDim Preserve Janelas_array(Num_Janelas)

       
        For i = 1 To Num_Janelas
            Janelas_array(i) = windows1.Item(i).Name
            If Janelas_array(i) = Drawing_name Then
             Dim specsAndGeomWindow1 As SpecsAndGeomWindow
           Set specsAndGeomWindow1 = windows1.Item(Janelas_array(i))
            specsAndGeomWindow1.Activate
            Component_display = "Ok"
            End If
            
        Next


For i = 3 To Number_View
Set DrwView = CATIA.ActiveDocument.Sheets.ActiveSheet.Views.Item(i)

' access links collection
Dim oGenLinks As DrawingViewGenerativeLinks
Dim linkedDocument

DrwView.GenerativeLinks.RemoveAllLinks


If a > 0 Then

DrwView.GenerativeLinks.AddLink Product1.Product

End If

If b > 0 Then

DrwView.GenerativeLinks.AddLink partDocument1.Product

End If

'DrwView.GenerativeLinks.AddLink
Next

Else
MsgBox ("Não existe nehuma vista, para trocar os links")

End If



End Sub




Tiago Figueiredo
Tooling Engineer

Youtube channel:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top