to search a part based on partnumber

to search a part based on partnumber

formobalaji
Enthusiast Enthusiast
254 Views
3 Replies
Message 1 of 4

to search a part based on partnumber

formobalaji
Enthusiast
Enthusiast

iam looking for an ilogic to open the part from a project location base on its partnumber

0 Likes
255 Views
3 Replies
Replies (3)
Message 2 of 4

bradeneuropeArthur
Mentor
Mentor

You can type the partnumber in the searchbox in the Inventor Assembly browser. No code needed....

https://youtu.be/kequNEtPE9A?si=4J15aBB94XNsSIbw

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 3 of 4

A.Acheson
Mentor
Mentor

Hi @formobalaji 

 

Maybe something like this would work. This rule will expect to find a part number "1234" in a part file in the project folder. This rule is untested so you might find errors. Post back with the error messages on the more info tab.

 

Dim prjfolder As String = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath & "\")
Dim projectDir As New IO.DirectoryInfo(prjfolder)

Dim workFiles As String() = projectDir.GetFiles("*.ipt")
Dim doc As Document
For Each fi As String In workFiles 

	doc = ThisApplication.Documents.Open(fi,False)
	
	Try
		
		Dim designProp As PropertySet = invDoc.PropertySets.Item("Design Tracking Properties")
		Dim partNo as String  = designProp.Item|("Part Number").Value
		If partNo = "1234" Then
			Logger.Info("Found partNo : " & partNo,)
		End If
	Catch ex as Exception
		Logger.Info(ex & "-" & "Error Getting Part Number",)
	End Try

Next

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 4 of 4

Curtis_Waguespack
Consultant
Consultant

@formobalaji 

 

Here is a a quick update to @A.Acheson's example.

 

When I tested his version, my project didn't have a workspace, so this version handles that and uses the project file folder. 

 

This version also closes the opened files, and opens the file with the target part number visibly.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

Dim prjfile As DesignProject = ThisApplication.DesignProjectManager.ActiveDesignProject
Dim prjfolder As String = prjfile.WorkspacePath & "\"

If prjfolder = "\" Then
	prjfolder = IO.Path.GetDirectoryName(prjfile.FullFileName)
End If

Dim projectDir As New IO.DirectoryInfo(prjfolder)

Dim workFiles As IEnumerable(Of String) 
workFiles = IO.Directory.EnumerateFiles(prjfolder, "*.ipt", 1) '1 searches subfolders, use 0 for top level only
Dim doc As Document
Dim targetdoc As Document
For Each fi In workFiles

	doc = ThisApplication.Documents.Open(fi, False)
	Logger.Info("File Opened : " & doc.fullfilename)

	Try
		Dim designProp As PropertySet = doc.PropertySets.Item("Design Tracking Properties")
		Dim partNo As String = designProp.Item("Part Number").Value
		If partNo = "1234" Then
			Logger.Info("Found partNo : " & partNo)
			'open visibly
			targetdoc = ThisApplication.Documents.Open(fi, True)
		End If
	Catch ex As Exception
		Logger.Info(ex.Message & "-" & "Error Getting Part Number")
	End Try

	If Not doc Is ThisDoc.Document And Not doc Is targetdoc Then
		Logger.Info("File Closed : " & doc.fullfilename)
		doc.Close
	End If

	If Not targetdoc Is Nothing Then Exit Sub ' quit looking for files if target is found
Next

 

EESignature

0 Likes