My advice at this point would be to eliminate the whole first section of code where it is getting 'all' drawing curves in the whole view, and putting them all into a List. That step is not necessary. You are already iterating through the 'filtered' collection of DrawingCurves in the second section of your code. Plus that 'List.Contains()' method call within that second iteration is likely taking a long time to process, and is completely unnecessary. Instead of taking curves out of the List at that point, that should be where you are initially putting them into the List. Not only that, but since you are only using that list to later iterate through each individual segment within it, turning their visibility off, you could just be doing that visibility change within the primary iteration directly, without needing to ever put them into a list. That would prevent the whole secondary iteration loop, and all the processing associated with that.
Try this edited version of your code, and see if it works a little faster.
Sub Main
Dim StartTime As DateTime = Now
Dim oView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select Drawing View")
If oView Is Nothing Then Return
Dim oAsm As AssemblyDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
For Each oComp As ComponentOccurrence In oAsm.ComponentDefinition.Occurrences.AllLeafOccurrences
If oComp.Suppressed Then Continue For
If TypeOf oComp.Definition Is VirtualComponentDefinition Then Continue For
For Each iFeat As Inventor.iFeature In oComp.Definition.Features.iFeatures
Dim iFeatProxy As Inventor.iFeatureProxy = Nothing
oComp.CreateGeometryProxy(iFeat, iFeatProxy)
Dim oDCurves As DrawingCurvesEnumerator = Nothing
'if proxy was obtained from lower level component in sub assembly, then
'proxy obtained may not yet be in context of main assembly yet
'a top level proxy can only be obtained directly from top level components
'or from the proxies of lower level components that exist at highest level
'proxies at deeper levels will need to be stepped up to highest level
Try : oDCurves = oView.DrawingCurves(iFeatProxy) : Catch : End Try
If oDCurves Is Nothing OrElse oDCurves.Count = 0 Then Continue For
For Each oiFeatCurve As DrawingCurve In oDCurves
For Each oiFeatSegment As DrawingCurveSegment In oiFeatCurve.Segments
If oiFeatSegment.HiddenLine = True Then oiFeatSegment.Visible = False
Next oiFeatSegment
Next oiFeatCurve
Next iFeat
Next oComp
Logger.Info("ALL SEGMENTS HIDDEN [" & Round(Now.Subtract(StartTime).TotalSeconds, 1) & "s]")
End Sub
...Or, you can do it with the Layer idea, like this...
Sub Main
Dim StartTime As DateTime = Now
Dim oView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select Drawing View")
If oView Is Nothing Then Return
Dim oAsm As AssemblyDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oObjColl As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
For Each oComp As ComponentOccurrence In oAsm.ComponentDefinition.Occurrences.AllLeafOccurrences
If oComp.Suppressed Then Continue For
If TypeOf oComp.Definition Is VirtualComponentDefinition Then Continue For
For Each iFeat As Inventor.iFeature In oComp.Definition.Features.iFeatures
Dim iFeatProxy As Inventor.iFeatureProxy = Nothing
oComp.CreateGeometryProxy(iFeat, iFeatProxy)
Dim oDCurves As DrawingCurvesEnumerator = Nothing
'if proxy was obtained from lower level component in sub assembly, then
'proxy obtained may not yet be in context of main assembly yet
'a top level proxy can only be obtained directly from top level components
'or from the proxies of lower level components that exist at highest level
'proxies at deeper levels will need to be stepped up to highest level
Try : oDCurves = oView.DrawingCurves(iFeatProxy) : Catch : End Try
If oDCurves Is Nothing OrElse oDCurves.Count = 0 Then Continue For
For Each oiFeatCurve As DrawingCurve In oDCurves
For Each oiFeatSegment As DrawingCurveSegment In oiFeatCurve.Segments
If oiFeatSegment.HiddenLine = True Then oObjColl.Add(oiFeatSegment)
Next oiFeatSegment
Next oiFeatCurve
Next iFeat
Next oComp
Dim oSheet As Inventor.Sheet = oView.Parent
Dim oDDoc As DrawingDocument = oSheet.Parent
Dim oMyLayer As Inventor.Layer = oDDoc.StylesManager.Layers.Item(1).Copy("Hidden iFeature Curves")
oMyLayer.Visible = False
oView.Parent.ChangeLayer(oObjColl, oMyLayer)
Logger.Info("ALL SEGMENTS HIDDEN [" & Round(Now.Subtract(StartTime).TotalSeconds, 1) & "s]")
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
After looking back at the title of this discussion, I may have misunderstood the task you were trying to do in these two code examples. You are not trying to control the visibility of iFeature hidden lines, but trying to turn off 'all other' hidden lines that do not belong to any iFeatures. My mistake. But you probably understand the process better now than you did before, so maybe this will still help somehow.
Wesley Crihfield

(Not an Autodesk Employee)