Search Assembly from Drawing for iProperties to create custom table from list

Search Assembly from Drawing for iProperties to create custom table from list

KWarrenCA
Advocate Advocate
2,092 Views
23 Replies
Message 1 of 24

Search Assembly from Drawing for iProperties to create custom table from list

KWarrenCA
Advocate
Advocate

I'm looking for some help on iLogic to create a custom table on a drawing after looking through the assembly of parts and sub assembly iProperties to find any that have the value ACC in the cost center. Then it will put the stock number of those files in the custom table to show that those are the accessories required for the full assembly. I was able to find this code from Clint Brown that can take an assembly and put it in a text file but I'd like to try and stream line it and possibly put the quantity of accessories needed in the table as well.

 

Sub Main()
Dim oAsmDoc As AssemblyDocument 
oAsmDoc = ThisApplication.ActiveDocument  

Dim oAppend As System.IO.StreamWriter
oAppend = IO.File.AppendText("C:\Temp\iProperties.txt")
oAppend.WriteLine("ACCESSORY LIST: " & ThisDoc.PathAndFileName(True))
oAppend.Flush()
oAppend.Close()

Call Iterate(oAsmDoc.ComponentDefinition.Occurrences, 1)
End Sub 

Private Sub Iterate(Occurrences As ComponentOccurrences, Level As Integer) 
'Iterate through Assembly
Dim oOcc As ComponentOccurrence 
For Each oOcc In Occurrences 

'Find Parts in Assembly
Dim oPart As String
oPart = oOcc.Name
Try 

'Write iProps to Parts
If iProperties.Value(oPart,"Design Tracking Properties", "Cost Center") = "ACC" Then
	oInfo = iProperties.Value(oPart, "Design Tracking Properties", "Stock Number") & " - " & iProperties.Value(oPart,"Design Tracking Properties", "Cost Center") 

	'____Open and append to an existing text file_______
Dim oAppend As System.IO.StreamWriter
oAppend = IO.File.AppendText("C:\Temp\iProperties.txt")
oAppend.WriteLine(oInfo)
oAppend.Flush()
oAppend.Close()
End If

Catch
MessageBox.Show("Something went wrong", "Check your assembly")
End Try

'Run through the sub assemblies 
If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
Call Iterate(oOcc.SubOccurrences, Level + 2) 
End If 
Next

End Sub

 

0 Likes
Accepted solutions (4)
2,093 Views
23 Replies
Replies (23)
Message 21 of 24

Andrii_Humeniuk
Advisor
Advisor

Made some small changes to your code. Please check if it works as you want.

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 22 of 24

KWarrenCA
Advocate
Advocate

@Andrii_Humeniuk That code worked correctly! One last question I have is I'm trying to limit the code to look at the first page for the view. I have another rule where I try to find a view and would like to use this because the current code will find the last assembly view to create the list and I just want it to run on the first page.

oBaseSheet = odoc.Sheets.Item(1)
		'Check to see if view is on the cover page.

		Try
			oView = oBaseSheet.DrawingViews.Item(1)
		Catch
			MessageBox.Show("There is no view on the cover page", "Place a view", MessageBoxButtons.OK, MessageBoxIcon.Error)
		End Try

		oModelDoc = oBaseSheet.DrawingViews.Item(1)

 

0 Likes
Message 23 of 24

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

The code takes into account only the first Sheet and the first DrawingView.

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 24 of 24

KWarrenCA
Advocate
Advocate

@Andrii_Humeniuk I'm running into issues where if I have the same assembly placed multiple times which has sub assemblies in them it it will only show the quantity of those sub assemblies for one assembly not the total qty of placed assemblies. Is there a way for it to include the multiple sub assemblies in those assemblies for the qty?

0 Likes