Creating a custom iproperty based on assembly folder name in tree

Creating a custom iproperty based on assembly folder name in tree

Thomas-P-White
Explorer Explorer
405 Views
6 Replies
Message 1 of 7

Creating a custom iproperty based on assembly folder name in tree

Thomas-P-White
Explorer
Explorer

I've done some searching and tried playing with iLogic but haven't had much success yet.

We need to identify the manufacture process of our parts so that purchasing know which suppliers to contact. For example it could be Cut, Folded or Rolled. We need to do this for hundreds of parts, so the idea I've had to make this as painless as possible is to manually sort each part into Cut/Folded/Rolled folders in the model tree and then run an iLogic rule that will run for all parts in the assembly to create a custom iProperty called "Process" with the value as the folder name that part is in.

 

Is anyone able to point me in the right direction to achieve this? I'm also open to other suggestions if someone has a better way to handle a similar situation.

Most iLogic I've created before is manipulating parameters and component rules so I'm struggling to understand what I've read so far about how to target assembly tree folders.

0 Likes
Accepted solutions (1)
406 Views
6 Replies
Replies (6)
Message 2 of 7

Hubert_Los
Advocate
Advocate

Hi,

 

Try this code,  change the folder number to the one you are interested in

 

filePath = ThisDoc.Path
filePathArray = Split(filePath, System.IO.Path.DirectorySeparatorChar)

Dim propertyName As String = "Process"
Dim propertyValue As String = filePathArray(2) ' number of Folder in my. In my case : (0) - E, (1) - Inventor, (2) - Folder "Cut"

customPropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")
Try
      customPropertySet.Item(propertyName).value = propertyValue
Catch
      ' Assume error means not found
      customPropertySet.Add("", propertyName)
      customPropertySet.Item(propertyName).value = propertyValue
End Try

 

0 Likes
Message 3 of 7

Thomas-P-White
Explorer
Explorer

Thanks for the response.

From running the rule I can see it creates the custom iproperty and then for the file the rule is in it will grab the name of the folder its in from the file directory.

It's not quite what I'm trying to do - I have assemblies with all of the parts placed into folders in the model tree, not the file directory. I need to have it run at assembly level for all of the parts and use the name of the model tree folder as the value of the iproperty. 

Between your code and what I've been trying it feels like its close but i'm missing something. 

0 Likes
Message 4 of 7

A.Acheson
Mentor
Mentor

@Thomas-P-White 

Here is an article that works with the browser nodes to suppresses the occurrences inside a given folder. Remove the suppression part and you can replace with iproperty checking. As you can see you have to deal with patterns as well but hopefully you can grasp the concept. Any questions just post the code your using. 

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

marcin_otręba
Advisor
Advisor
Accepted solution

i made it couple times, from manualyy filling properties on new document for full automatization depending from model.

 

if you want to use folders then  try this:

 

Dim iam As AssemblyDocument = ThisApplication.ActiveEditDocument
Dim oc As ComponentOccurrence
Dim browser As BrowserPane = iam.BrowserPanes.ActivePane


For Each oc In iam.ComponentDefinition.Occurrences
	
	Dim node = browser.GetBrowserNodeFromObject(oc)

			Dim parentNode As BrowserNode = node.Parent
			Do While parentNode IsNot Nothing
				If parentNode.NativeObject.Type = ObjectTypeEnum.kBrowserFolderObject Then
					prompt = parentNode.BrowserNodeDefinition.Label
					Dim propertyName As String = "Process"



Dim  customPropertySet As PropertySet = oc.Definition.Document.PropertySets.Item("Inventor User Defined Properties")
Try
      customPropertySet.Item(propertyName).Value = prompt
Catch
      ' Assume error means not found
      customPropertySet.Add(prompt, propertyName)
      customPropertySet.Item(propertyName).Value = prompt
End Try
End If
				
				parentNode = Nothing
				Try 
					parentNode = parentNode.Parent
					Catch
					End Try
				
			Loop
	
	Next

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 6 of 7

marcin_otręba
Advisor
Advisor

.

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 7 of 7

Thomas-P-White
Explorer
Explorer
That works perfectly, thank you!

There's a couple things in there I don't quite grasp but I'll keep looking at it and searching functions so I understand how it works.
0 Likes