Ilogic for adding purchased files to folder in structure browser

Ilogic for adding purchased files to folder in structure browser

koenroovers
Enthusiast Enthusiast
736 Views
6 Replies
Message 1 of 7

Ilogic for adding purchased files to folder in structure browser

koenroovers
Enthusiast
Enthusiast

Hello everyone,

 

I am dealing with large assemblies and i want to create a better overview of the structure browser.

 

I want to create a ilogic that checks if a "purchased" folder is created, and if not -> create it. After i want it to put all my purchased files into this folder. I have been searching for a iLogic but couldn't find it, i could only find a piece of ilogic to create a new folder. Not the check part and move purchased part.

 

I have now got a piece of iLogic code to create the purchased folder:

 

Dim oFolderName As String = "Purchased"
Dim oDoc As Document = ThisDoc.Document
Dim oPane As BrowserPane = oDoc.BrowserPanes.ActivePane
Dim oFolder As BrowserFolder = Nothing
Try
	oFolder = oPane.BrowserFolders(oFolderName)
Catch
	oFolder = oPane.AddBrowserFolder(oFolderName, Nothing)
End Try

Can somebody help me with this?

 

Kind regards,

Koen

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

WCrihfield
Mentor
Mentor
Accepted solution

Hi @koenroovers.  You can try this bit of iLogic code, and see if it works OK for you.

Dim oADoc As AssemblyDocument = ThisDoc.Document
'get the 'Model' pane
Dim oModelPane As BrowserPane = oADoc.BrowserPanes.Item("AmBrowserArrangement")
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oOccs As ComponentOccurrences = oADef.Occurrences
Dim oPurchasedOccs As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
For Each oOcc As ComponentOccurrence In oOccs
	If oOcc.Suppressed Then Continue For
	If oOcc.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure Then
		Dim oOccNode As BrowserNode = oModelPane.GetBrowserNodeFromObject(oOcc)
		oPurchasedOccs.Add(oOccNode)
	End If
Next
Dim oFolderName As String = "Purchased"
Dim oPFolder As BrowserFolder = Nothing
Try
	oPFolder = oModelPane.TopNode.BrowserFolders.Item(oFolderName)
Catch
	oPFolder = oModelPane.AddBrowserFolder(oFolderName, oPurchasedOccs)
End Try
For Each oPOccNode In oPurchasedOccs
	Try : oPFolder.Add(oPOccNode) : Catch : End Try
Next

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 7

koenroovers
Enthusiast
Enthusiast

@WCrihfield 

You are the best! thanks so much.

0 Likes
Message 4 of 7

koenroovers
Enthusiast
Enthusiast

@WCrihfield 

When using this code i can't move the folder in the structure browser (there are no patterns in the folder). Is this because of the used code? Is there a possibility to add a piece of code to position the folder below the "origin" folder?

0 Likes
Message 5 of 7

WCrihfield
Mentor
Mentor

Hi @koenroovers.  I was away for a few days, but am back now.  When you create a new browser folder by code, it does not always allow you to specify where you want to put it (BrowserPane.AddBrowserFolder).  If you create an empty folder, it just puts it at the end of all existing browser nodes.  But if you include some browser nodes in the folder when you create it, the folder will be positioned according to where those nodes were that you are putting into it.  Similarly to if you right-click on a component in the model browser, and choose 'Add to New Folder'...it puts the folder where that component was in the browser.  But if you right click on the top node, without having any other nodes selected, then choose 'Create New Folder', it simply puts a new empty folder at the end.  There is a method of the BrowserPane object called Reorder though, that sounds like it would allow you to move the folder after you have created it, but the nodes involved all need to be on the same (top) level, or it will error out.  When using that method, you specify a 'target' node as a position reference, then a Boolean representing either Before or After that position, then the first (or only) node that you want to move, then optionally the last node that you want to move (if more than one).  The funny thing about browser nodes though, is that there are often more of them present than you can see, because some of them are not always visible, so iterating them is not usually as simple as it may seem.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 7

koenroovers
Enthusiast
Enthusiast

hi @WCrihfield 

Thanks for your explanation. 


Other thing i noted with this rule is that members of a pattern are also copied to the sub folder. The problem with this is that they are now doubled inside the assembly. Deleting the folder does not help with removing the double existing parts. Right clicking one of the parts that are also in the pattern also doesn't give me the option to "add to new folder" and i cant drag it to a different position. This might be part of the problem.

 

Is there a possibility to filter the purchased parts added to the folder to only buyparts outside of a pattern?

0 Likes
Message 7 of 7

WCrihfield
Mentor
Mentor

Hi @koenroovers.  Yes, patterns definitely mess with your ability to reorganize the browser nodes freely, and I don't fully understand all of the restrictions there are to our ability to move browser nodes around the way we want.  Some situations are fairly self explanatory, such as things that are dependent on a source object can not be listed before the object they are dependent on.  But other situations are not so simple.  The ComponentOccurrence object has a property named "IsPatternElement", which returns a Boolean, indicating if it is part of a pattern of components.  Then, if it returns True, the ComponentOccurrence object also has a property called PatternElement that you can use to get the actual OccurrencePatternElement object that it represents in the context of that pattern.  You may be able to use this to help filter out the ones you can and can not move freely to the browser folder.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes