- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I need help to generate a .txt file with some infos extracted from all open assemblies. Besides that I need check if a open file is a iAssembly, if yes I need run the rule for all members of this iAssembly. I wrote the code bellow, but it works just for the assembly that are open.
Dim oAssembly As AssemblyDocument = ThisDoc.Document
Dim oCompDef As AssemblyComponentDefinition = oAssembly.ComponentDefinition
Dim IsiAssembly As Boolean = oCompDef.IsiAssemblyFactory()
Dim factory As iAssemblyFactory = oCompDef.iAssemblyFactory
Dim myList, mySelect As New ArrayList
Dim Instalacao
TolMax = InputBox("Qual a tolerância superior do diâmetro de passagem do parafuso?", "Tolerância Superior")
TolMin = InputBox("Qual a tolerância superior do diâmetro de passagem do parafuso?", "Tolerância Superior")
myList.Add("Cemented")
myList.Add("Screwed")
myList.Add("N/A")
myList_selected = InputListBox("Cimentado, Parafusado ou N/A?", myList, myList(0), Title := "Selecione abaixo", ListName := "List")
mySelect.Add(myList_selected)
For Each Instalacao In mySelect
MessageBox.Show("Arquivo .txt gerado com sucesso! Todos os itens foram definidos como: " & Instalacao, "Sucesso!")
Next
'____Create and write to a text file_________________
oWrite = System.IO.File.CreateText(ThisDoc.Path & "\" & "VerificarConexoes" & ".txt")
'For Each oAssembly In ThisApplication.Documents.VisibleDocuments
For Each assembly As ComponentOccurrence In oCompDef.Occurrences
oAssembly.Activate()
oWrite.WriteLine(item & ";" & Round(A, 2) & ";" & Round(B, 2) & ";" & Round(Emax, 2) & ";" & Round(Emin, 2) & ";" & Instalacao)
If oCompDef.IsiAssemblyFactory() = False Then
item = iProperties.Value("Project", "Part Number")
A = Parameter("Ap")
Emax = Parameter("DIA") + TolMax
Emin = Parameter("DIA") - TolMin
B = Parameter("B")
End If
If oCompDef.IsiAssemblyFactory() = True Then
Dim factoryRows As iAssemblyTableRows = factory.TableRows
For Each row In factoryRows
item = iProperties.Value("Project", "Part Number")
A = Parameter("Ap")
Emax = Parameter("DIA") + TolMax
Emin = Parameter("DIA") - TolMin
B = Parameter("B")
Next
End If
Next
oWrite.Close()
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
You can look at the visible document collection.
The ilogic snippet will need to be changed to a property set version(API) otherwise the part number will be the document you called the rule from rather than the document in your visible documents loop. If you need help constructing just post back with the visible documents loop in place and also the required property set. Any questions ask away.
Or if this helped you, please, click (like)
Regards
Alan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I changed my code for this:
Dim myList, mySelect As New ArrayList
Dim Instalacao
TolMax = InputBox("Qual a tolerância superior do diâmetro de passagem do parafuso?", "Tolerância Superior")
TolMin = InputBox("Qual a tolerância superior do diâmetro de passagem do parafuso?", "Tolerância Superior")
myList.Add("Cemented")
myList.Add("Screwed")
myList.Add("N/A")
myList_selected = InputListBox("Cimentado, Parafusado ou N/A?", myList, myList(0), Title := "Selecione abaixo", ListName := "List")
mySelect.Add(myList_selected)
For Each Instalacao In mySelect
' MessageBox.Show("Arquivo .txt gerado com sucesso! Todos os itens foram definidos como: " & Instalacao, "Sucesso!")
Next
oWrite = System.IO.File.CreateText(ThisDoc.Path & "\" & "VerificarConexoes" & ".txt")
Dim oDoc As Inventor.Document
For Each oDoc In ThisApplication.Documents.VisibleDocuments
If oDoc.DocumentType = kAssemblyDocumentObject Then
item = iProperties.Value("Project", "Part Number")
A = Parameter("Ap")
Emax = Parameter("DIA") + TolMax
Emin = Parameter("DIA") - TolMin
B = Parameter("B")
oWrite.WriteLine(item & ";" & Round(A, 2) & ";" & Round(B, 2) & ";" & Round(Emax, 2) & ";" & Round(Emin, 2) & ";" & Instalacao)
End If
Next
oWrite.Close()
But still not working. The .txt file that is exporting returns just the infos from the assembly that are visible repeating for all documents opened, as below:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Here is some changes removing the ilogic snippets for iproperty and parameters for API versions. The tolerances retrieval may not be correct, so maybe check that section and test.
Dim myList, mySelect As New ArrayList Dim Instalacao TolMax = InputBox("Qual a tolerância superior do diâmetro de passagem do parafuso?", "Tolerância Superior") TolMin = InputBox("Qual a tolerância superior do diâmetro de passagem do parafuso?", "Tolerância Superior") myList.Add("Cemented") myList.Add("Screwed") myList.Add("N/A") myList_selected = InputListBox("Cimentado, Parafusado ou N/A?", myList, myList(0), Title := "Selecione abaixo", ListName := "List") mySelect.Add(myList_selected) For Each Instalacao In mySelect ' MessageBox.Show("Arquivo .txt gerado com sucesso! Todos os itens foram definidos como: " & Instalacao, "Sucesso!") Next oWrite = System.IO.File.CreateText(ThisDoc.Path & "\" & "VerificarConexoes" & ".txt") Dim oDoc As Inventor.Document For Each oDoc In ThisApplication.Documents.VisibleDocuments If oDoc.DocumentType = kAssemblyDocumentObject Then Dim oAssyDoc As AssemblyDocument = oDoc 'Declare as either an assembly or part to gain access to object collections. Dim Params As Parameters = oAssyDoc.ComponentDefinition.Parameters Dim opn As [Property] opn = oAssyDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number") Try item = opn.Value.ToString 'cannot use ilogic snippet which is only valid in document the rule is ran from first 'iProperties.Value("Project", "Part Number") A = Params("Ap").Value' Value returned in system units cm 'Parameter("Ap") Emax = Params("DIA") + TolMax Emin = Params("DIA") - TolMin B = Params("B") Catch End Try oWrite.WriteLine(item & ";" & Round(A, 2) & ";" & Round(B, 2) & ";" & Round(Emax, 2) & ";" & Round(Emin, 2) & ";" & Instalacao) End If Next oWrite.Close()
Or if this helped you, please, click (like)
Regards
Alan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report