Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
Cosmin_V
407 Views, 1 Reply

Count IDW

Hi

 

I'm trying to write a code that updates all the drawings in relation to an assembly.
So far everything is ok, but I would like to have a dialog box before the update, in which to show me how many drawings there are for the update.
Can anyone help me?

Many thanks!

 

' Check that the active document is an assembly file
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
    MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
    Exit Sub
End If

' Define the active document As an Assembly file
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
Dim oAsmName As String
oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4)

'- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -
' Look at the files referenced by the assembly
Dim oRefDocs As DocumentsEnumerator
oRefDocs = oAsmDoc.AllReferencedDocuments
Dim oRefDoc As Document

' Work the the drawing files for the referenced models
' This expects that the model has a drawing of the same path and name
For Each oRefDoc In oRefDocs
    idwPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "idw"
    ' Check to see that the model has a drawing of the same path and name
    If(System.IO.File.Exists(idwPathName)) Then
        Dim oDrawDoc As DrawingDocument
        oDrawDoc = ThisApplication.Documents.Open(idwPathName, True)
        oDrawDoc.Update
            oDrawDoc.Save
        oDrawDoc.Close

    End If
Next

 

jacobus
in reply to: Cosmin_V

Hello vaida

 

please see code below I added a loop to count the drawings haven't tested it.

May not be the most efficient way but hope this helps 

 

' Check that the active document is an assembly file
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
    MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
    Exit Sub
End If

' Define the active document As an Assembly file
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
Dim oAsmName As String
oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4)
'- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -
' Look at the files referenced by the assembly
Dim oRefDocs As DocumentsEnumerator
oRefDocs = oAsmDoc.AllReferencedDocuments
Dim oRefDoc As Document
'====================================================================
Dim i As Integer
i = 0
For Each oRefDoc In oRefDocs
    idwPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "idw"
    ' Check to see that the model has a drawing of the same path and name
    If(System.IO.File.Exists(idwPathName)) Then
     i = i+1   

    End If
Next
If i = 0 Then 
	MessageBox.Show("No drawings found", "iLogic")
	Exit Sub
ElseIf i > 0 Then
	MessageBox.Show( i + "drawings found", "iLogic")
End If

'====================================================================
' Work the the drawing files for the referenced models
' This expects that the model has a drawing of the same path and name
For Each oRefDoc In oRefDocs
    idwPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "idw"
    ' Check to see that the model has a drawing of the same path and name
    If(System.IO.File.Exists(idwPathName)) Then
        Dim oDrawDoc As DrawingDocument
        oDrawDoc = ThisApplication.Documents.Open(idwPathName, True)
        oDrawDoc.Update
            oDrawDoc.Save
        oDrawDoc.Close

    End If
Next