Getting Title Property from part/assembly

Getting Title Property from part/assembly

euan_mcgowan
Explorer Explorer
103 Views
2 Replies
Message 1 of 3

Getting Title Property from part/assembly

euan_mcgowan
Explorer
Explorer

Afternoon,

I have a rule that when run it produces an excel sheet with all parts/assemblies, whether they have a drawings or not, and then revision states.

 

I am trying to get the rule to pull the Summary Title iProperty from the list of Parts/assemblies, but I cannot get it to return anything but a list of "-".

 

Ive cut off the rule at the point where it fails. If anyone can spot the dumb mistake I've made ill be very grateful. 

 

Thanks

Sub Main
	Dim basePath As String = "C:\Work\Designs"


	Dim mainDirectory As IO.DirectoryInfo = New IO.DirectoryInfo(basePath)
	Dim project_name As New ArrayList
	Dim project_path As New ArrayList

	For Each folder As IO.DirectoryInfo In mainDirectory.GetDirectories()
		Dim foldername As String = folder.Name
		Dim folderpath As String = folder.FullName
		project_name.Add(foldername)
		project_path.Add(folderpath)
	Next
	Dim customPR As PropertySet
	Dim customPRP As PropertySet

	'give input box to choose project, define selected folder to search for idw files
	ArraySelected = InputListBox("Choose a folder", project_name, project_name.Item(0), "Project", "List of Projects", 600, 0)
	If ArraySelected = "" Then
		Return
	End If
	index1 = project_name.IndexOf(ArraySelected)
	searchpath = project_path(index1)
	MessageBox.Show("This tool only displays drawing states on your local drive" & vbCrLf & "Does not necessarily reflect Vault drawing state!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Warning)

	Dim selectedPath As String = searchpath
	Dim modelFiles As New List(Of String)

	' Step 2: Get AST*.ipt and AST*.iam files
	Dim allModels As New List(Of String)
	allModels.AddRange(From f In System.IO.Directory.GetFiles(selectedPath, "AST*.ipt") Where Not System.IO.Path.GetFileName(f).Contains("_") Select f)
	allModels.AddRange(From f In System.IO.Directory.GetFiles(selectedPath, "AST*.iam") Where Not System.IO.Path.GetFileName(f).Contains("_") Select f)
	modelFiles.AddRange(allModels)

	' Step 3: Create array for matching .idw files or "No drawing"
	Dim idwMatches As New List(Of String)
	Dim regPaths As New List(Of String)

	For Each modelFile In modelFiles
		Dim baseName As String = System.IO.Path.GetFileNameWithoutExtension(modelFile)
		Dim idwPath As String = System.IO.Path.Combine(selectedPath, baseName & ".idw")
		Dim regPath As String = System.IO.Path.GetFullPath(modelFile)

		If System.IO.File.Exists(idwPath) Then
			idwMatches.Add(idwPath)
			regPaths.add(regPath)
		Else
			idwMatches.Add("No drawing")
			regPaths.add(regPath)
		End If
	Next

	' Step 4: Open each .idw file (if exists) in background and extract part number
	Dim oInvApp As Inventor.Application = ThisApplication
	Dim partTitle As New List(Of String)
	Dim drawingPartNumbers As New List(Of String)
	Dim drawingRN As New List(Of String)
	Dim drawingDRW As New List(Of String)
	Dim drawingCHK As New List(Of String)
	Dim drawingAPPD As New List(Of String)
	Dim drawingRS As New List(Of String)
	Dim oOpenArgs As NameValueMap = oInvApp.TransientObjects.CreateNameValueMap()
	oOpenArgs.Add("DeferUpdates", True)
	oOpenArgs.Add("FileVersionOption", FileVersionEnum.kOpenCurrentVersion)
	oOpenArgs.Add("SkipAllUnresolvedFiles", True)


	For Each regPath In regPaths
		Dim Doc As Document = Nothing
		Try
			Doc = oInvApp.Documents.OpenWithOptions(regPath, oOpenArgs, False)
			Dim aPT As String = Doc.PropertySets.Item("Inventor Summary Information").Item("Title").Value
			partTitle.Add(aPT)
			Doc.Close(True)
		Catch
			partTitle.Add("-")
		End Try	
	Next

 

0 Likes
104 Views
2 Replies
Replies (2)
Message 2 of 3

C_Haines_ENG
Collaborator
Collaborator

If you take the lines out of the Try Catch statement it will tell you exactly which line is causing the issue.

 

My best guess here is that you are trying to open a document that doesn't exist.

0 Likes
Message 3 of 3

WCrihfield
Mentor
Mentor

Another thing you can try is replacing this:

Doc.Close(True)

...with this:

Doc.ReleaseReference()

Then after that loop, you can call the ThisApplication.Documents.CloseAll(True) method, which will clear out all non-visible, unreferenced documents from Inventor's memory.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes