I had another look through the API help and it looks like they haven't provided a section method which is a pity because their is a lot of work to get the command to work. I would suggest post this in the idea section if it isn't there already.
I kind of wanted to do this for myself as I also have a need for it so here is the method to select the browser node of the occurrence based on the view selected and occurrence name given.
Selecting the view through the command manager has the added benefit of being the starting point for the browser node loop this means you don't have to loop through other views improving the speed.
Sub Main
Dim doc As Document = ThisDoc.Document
'Make this a single transaction.
Dim trans As Transaction = ThisApplication.TransactionManager.StartTransaction(doc, "Sectioning Occurrence")
ThisApplication.StatusBarText = "Sectioning Occurrence..."
Dim bp As BrowserPane = doc.BrowserPanes("DlHierarchy")
'Option for Section Method.
Dim sectionView As SectionDrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a Section drawing view")
secBool = InputRadioBox("Pick One", "Section", "No Section ", secBool, Title := "iLogic")
Dim occName As String = InputBox("Enter an OccurrenceName", "OccurrenceName", "Coupling:1")
'Select the view in order to pick up the view node and reduce recursion time.
ThisApplication.CommandManager.DoSelect(sectionView)
'Find the occurrence by imputting occurrence name.
occ = GetOccurrence(occName ,sectionView.DrawingCurves)
'Find valid nodes with occurrence name in their path.
GetViewNode(bp.TopNode.BrowserNodes, occName)
ThisApplication.CommandManager.ControlDefinitions.Item("AppBrowserCollapseAllCmd").Execute2(True)
trans.End
ThisApplication.StatusBarText = "Rule Finished"
End Sub
Dim occ As ComponentOccurrence
Dim secBool As Boolean
Function GetOccurrence(occName As String, curves As DrawingCurvesEnumerator) As ComponentOccurrence
For Each curve As DrawingCurve In curves
For Each curveSegment As DrawingCurveSegment In curve.Segments
Try
Dim modelGeom As Object = curve.ModelGeometry
occ = modelGeom.ContainingOccurrence
Catch
End Try
If occ.Name = occName Then
Logger.Info("found occ from curve " & occ.Name)
Return occ
End If
Next
Next
End Function
'Get Drawing view node selected
Sub GetViewNode(nodes As BrowserNodesEnumerator, occName As String)
For Each node As BrowserNode In nodes
If node.Selected Then
'Slow down events to allow node to be found.
ThisApplication.UserInterfaceManager.DoEvents()
node.EnsureVisible
node.DoSelect
'Logger.Info("Drawing View found" & node.FullPath)
'Loop through found view nodes.
GetoOccurrenceNode(node.BrowserNodes,occName)
Exit For
End If
'Not found so call sub routine again.
GetViewNode(node.BrowserNodes,occName)
Next
End Sub
Sub GetoOccurrenceNode(nodes As BrowserNodesEnumerator,occName As String)
For Each node As BrowserNode In nodes
If node.BrowserNodeDefinition.Label = occName Then
SectionCmd(secBool,node)
'Logger.Info(node.FullPath)
Exit For
End If
'Not found so call sub routine again.
GetoOccurrenceNode (node.BrowserNodes,occName)
Next
End Sub
Sub SectionCmd(secBool As Boolean, bn As BrowserNode)
bn.EnsureVisible
bn.DoSelect
Dim cd As ControlDefinition
If secBool = True
cd = ThisApplication.CommandManager.ControlDefinitions(“AllowSectionParticipation”)
ElseIf secBool = False
cd = ThisApplication.CommandManager.ControlDefinitions(“AllowNoneParticipation”)
End If
cd.Enabled = True
cd.Execute
End Sub
If this solved a problem, please click (accept) as solution.
Or if this helped you, please, click (like)
Regards
Alan