Message 1 of 1
Open all drawing on vault from assembly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I would like to open all drawing on vault from an assembly.
I have found a rule on web (rule 1). This rule open idw on vault from one part/assembly.
I whrite a second rule to call "Rule 1" in each part/assembly from the top assembly.
It's not working I have a problem :
Do you know why? Thanks a lot
Here is the error and the rules.
System.InvalidCastException: Impossible d'effectuer un cast d'un objet COM de type 'System.__ComObject' en type de classe 'System.String'. Les instances de types qui représentent des composants COM ne peuvent pas être castées en types qui ne représentent pas des composants COM ; toutefois, elles peuvent être castées en interfaces tant que le composant COM sous-jacent prend en charge les appels QueryInterface pour l'IID de l'interface.
à ThisRule.Main()
à Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
à iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
My rule
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
Exit Sub
End If
Dim aDoc As AssemblyDocument
aDoc = ThisApplication.ActiveDocument
Dim iDoc As Document
For Each iDoc In aDoc.AllReferencedDocuments
iLogicVb.RunExternalRule(iDoc, "OuvreIDWDepuisVault")
Next
Rule 1: find on web
AddReference "Autodesk.Connectivity.WebServices.dll"
Imports ACW = Autodesk.Connectivity.WebServices
AddReference "Autodesk.DataManagement.Client.Framework.Vault.dll"
AddReference "Autodesk.DataManagement.Client.Framework.dll"
Imports VDF = Autodesk.DataManagement.Client.Framework
AddReference "Connectivity.Application.VaultBase.dll"
Imports VB = Connectivity.Application.VaultBase
Public Class ThisRule
Sub Main()
Dim oApp As Inventor.Application = ThisApplication
Dim oDoc As Document = ThisDoc.Document
If TypeOf ThisDoc.Document Is AssemblyDocument Then
If ThisDoc.Document.SelectSet.Count > 0 Then
oDoc = ThisDoc.Document.SelectSet(1).Definition.Document
End If
End If
Dim docfullfilename As String = oDoc.FullFileName
Dim docfilename As String = RPointToBackSlash(oDoc.FullFileName)
'Alle Zeichnungen aus dem Vault abrufen
'Auf Vault-Connection zugreifen und ggf. rausgehen
Dim mVltCon As VDF.Vault.Currency.Connections.Connection = VB.ConnectionManager.Instance.Connection
If mVltCon Is Nothing Then Exit Sub
'Auf ACW-PropertyDefininition Status zugreifen
Dim filePropDefs As ACW.PropDef() = mVltCon.WebServiceManager.PropertyService.GetPropertyDefinitionsByEntityClassId("FILE")
Dim ACWNamePropDef As ACW.PropDef
For Each def As ACW.PropDef In filePropDefs
If def.DispName = "Name" Then
ACWNamePropDef = def
Exit For
End If
Next def
'Suchoptionen festlegen
Dim namesucheoptionen As New ACW.SrchCond() With { _
.PropDefId = ACWNamePropDef.Id, _
.PropTyp = ACW.PropertySearchType.SingleProperty, _
.SrchOper = 1, _
.SrchRule = ACW.SearchRuleType.Must, _
.SrchTxt = docfilename & " idw" _
}
Dim bookmark As String = String.Empty
Dim status As ACW.SrchStatus = Nothing
Dim results As ACW.File() = mVltCon.WebServiceManager.DocumentService.FindFilesBySearchConditions(New ACW.SrchCond() {namesucheoptionen }, Nothing, Nothing, False, True, bookmark, status)
Dim settings As New VDF.Vault.Settings.AcquireFilesSettings(mVltCon)
If results Is Nothing Then
MessageBox.Show("Zu dem Dokument " & docfilename & " ist keine Zeichnung im Vault vorhanden.", "Info")
Else
For Each res In results
Dim oFileIteration As VDF.Vault.Currency.Entities.FileIteration = New VDF.Vault.Currency.Entities.FileIteration(mVltCon, res)
settings.OptionsRelationshipGathering.FileRelationshipSettings.IncludeRelatedDocumentation = True
settings.OptionsRelationshipGathering.FileRelationshipSettings.VersionGatheringOption = VDF.Vault.Currency.VersionGatheringOption.Latest
settings.AddFileToAcquire(oFileIteration, VDF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download)
Next
End If
Dim aquiresults As VDF.Vault.Results.AcquireFilesResults = mVltCon.FileManager.AcquireFiles(settings)
'Alle heruntergeladenen idw's in Liste
Dim idwList As New ArrayList
For Each aquiresult As VDF.Vault.Results.FileAcquisitionResult In aquiresults.FileResults
Dim aquiresultpath As String = aquiresult.LocalPath.FullPath
If UCase(aquiresultpath).Contains(".IDW") Then
idwList.Add(aquiresultpath)
End If
Next
'idw's öffnen
For Each idw As String In idwList
oApp.Documents.Open(idw, True)
Next
End Sub
Function RPointToBackSlash(ByVal strText As String) As String
strText = Left(strText, InStrRev(strText, ".") - 1)
RPointToBackSlash = Right(strText, Len(strText) - InStrRev(strText, "\"))
End Function
End Class
Thanks a lot