Perform a task, ignoring locked parts.

Perform a task, ignoring locked parts.

Anonymous
Not applicable
455 Views
5 Replies
Message 1 of 6

Perform a task, ignoring locked parts.

Anonymous
Not applicable

I have a rule that looks through the parts in an assembly, and if it finds the rule its looking for, runs it in the part before moving on. Problem is it does it through locked parts too. How can I get it to skip the locked parts? Im guessing it has to do with adding the vault reference?

 

SyntaxEditor Code Snippet

Sub Main RunPropertiesRule()


    'Set reference to Document Counter
    Dim oDocCount As Integer
    'Set Document Counter to 0
    oDocCount = 0
    
    ' Get the active assembly document. 
    Dim oAsmDoc As AssemblyDocument  
    oAsmDoc = ThisApplication.ActiveDocument 
    
    Vault = AddReference "Autodesk.DataManagement.Addin.Vault.dll"
    Dim oVault As Object
    oVault = Vault

    
    Auto = iLogicVb.Automation
    Dim iLogicAuto As Object
    iLogicAuto = Auto
    Dim oDoc As Document
    oDoc = ThisApplication.ActiveDocument

    For Each oDoc In oAsmDoc.AllReferencedDocuments
    
        'Increase oDocCount Counter by 1 within For loop
        oDocCount = oDocCount + 1
        
            If oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
            
            Dim rules As Object
            rules = iLogicAuto.rules(oDoc)
            
                'Remove rules
                If Not (rules Is Nothing) Then
                    For Each rule In rules
                    ruleName = rule.Name
                        If Left(ruleName, 3) = "ipr" Or Left(ruleName, 3) = "Ipr" Then
                            auto.RunRule(oDoc, ruleName)
                    End If

                    
                    Next 
                
                End If
            End If 
    Next
    
        



End Sub

 In the code you can see where I tried to add the reference but it gives me an error "End of Statement Expected", It works fine without  

 

    Vault = AddReference "Autodesk.DataManagement.Addin.Vault.dll"
    Dim oVault As Object
    oVault = Vault

Any suggestions?

 

0 Likes
456 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable

By a 'locked' part do you mean one that is read-only ?

0 Likes
Message 3 of 6

Anonymous
Not applicable

Yes, one that has been released in Vault.

0 Likes
Message 4 of 6

TONELLAL
Collaborator
Collaborator

When you try to modify a part (by the macro), if you work with a Vault project you'll have the message to check it out. If it is already checked out, you can only modify it locally, you can not check it in. So even if your macro has modified the part, in Vault the part is not modified. Finally, you waste time to modify parts you cannot check in, but your Vault part is not modified.

0 Likes
Message 5 of 6

bradeneuropeArthur
Mentor
Mentor
Hi,

Use the fileinfo object file readonly= true or false to slip the task. Like:

Dim fio as fileinfo()
If fio.readonly = false

Do the task

End if

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 6 of 6

bradeneuropeArthur
Mentor
Mentor

Hi,

 

Here is my complete Code to loop throught the assembly, only for files that are write enabled!

 

Public Sub SaveAllDesign(oTopDoc As Document)
        Dim fioTop As System.IO.FileInfo = New System.IO.FileInfo(oTopDoc.FullFileName)
        If fioTop.IsReadOnly = False Then

            Dim oInvDoc As Document

            For Each oInvDoc In oTopDoc.ReferencedDocuments
                Dim fio As System.IO.FileInfo = New System.IO.FileInfo(oInvDoc.FullFileName)

                If fio.IsReadOnly = False Then
                    'MsgBox(oInvDoc.FullFileName)

                    oInvDoc.Save()

                    If oInvDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
                        Try
                            SaveAllDesign(oInvDoc)
                        Catch ex As Exception

                        End Try
                    End If

                    If oInvDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then

                        Try
                            SaveAllDesign(oInvDoc)
                        Catch ex As Exception

                        End Try

                    End If

                End If
            Next
        End If
    End Sub

 

 

Regards,

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes