Creating "shaded with no edges" views by moving curves to new layers

Creating "shaded with no edges" views by moving curves to new layers

Lewis.Young
Collaborator Collaborator
106 Views
1 Reply
Message 1 of 2

Creating "shaded with no edges" views by moving curves to new layers

Lewis.Young
Collaborator
Collaborator

Hi All,

 

I'm currently creating a tool for Inv 2026 that when ran, will move all drawing curve segments in an idw view to a new layer, so that the new layer can be turned off when creating pdf's. This allows us to create a "shaded with no edges" style view, so that we can really clearly show shaded colours on large views. This could be done manually of course by select as edges, but we have massive views with 200,000+ segments, so we need it to be automated.

 

When the code first runs, it goes through the curve segments and scans them to see what current layer they're on. It then builds them into an object collection, and executes a change layer for all curves in each layer type to it's new respective "Invisible - " layer. This works really well and fast on the initial run.

 

However, If I re-run the code on the same view - which has already had all of it's curves overridden to a new layer - the scanning takes longer and longer and also massively builds ram, even if the new layer visibility is turned on, so it's not a visibility on/off problem.

 

I can see that by default, a drawing curve layer is set to "By Standard". So it seems like on the first scan, it goes quicker because it's reading the "By Standard" layer status without having to look up anything. When ran the second time - with the curves already overridden to a new layer - it seems like it's having to check each curve more than before, which in turn is storing something in the cache each time, hence the increasingly slow scan rate & ram build up. For reference, on a view with 50,000 segments. First run takes 4 seconds to scan, second run takes 1 hour to scan (starts off fast, but gets slower)

 

What I'd love to know is:

1. Is there a way in the API to set a drawing curve back to "By Standard" layer, not just the original name? The setting is there in the UI (top of the layer dropdown in the annotate tab), but I can't seem to find a way to access it through the API. At the moment, it starts as "By Standard (Visible (ISO))", it gets changed to "Invisible - Visible (ISO)", and then if i try set it back it goes to original using API it gets set to "Visible (ISO)" without the By standard at the top.

2. Is there a way of detecting if a curves layer has it's visibility already turned off? This would make the scanning quicker, as I can turn off the new layers at the start, and essentially the overridden curves.

3. If anyone has any other different approaches that might be useful for this sort of thing?

 

Thanks

0 Likes
107 Views
1 Reply
Reply (1)
Message 2 of 2

marcin_otręba
Advisor
Advisor

if you have only shaded views in your drawing and you want to show it in pdf than you just can make list of layer to hide and hide it:

Dim edgeLayers As New List(Of String) From {
    "Widoczne (ISO)-1",
    "Widoczne wąskie (ISO)-1",
    "Ukryte (ISO)-1",
    "Ukryte wąskie (ISO)-1"
}

Dim drw As DrawingDocument = ThisDoc.Document
Dim layers = drw.StylesManager.Layers

For Each layerName In edgeLayers
	
    Try:    layers(layerName).Visible = False : Catch : End Try
    
Next


i see two option, 1 - changing layer, 2- making all curvesegments hidden.  in both scenarios i would hide it export pdf, and close idw without saving, then i do not need to clean anything up. but if you insist then just name new layer as invisible_originallayername, than you can easily change it back. in both i suggest to set ivisilible layers to false first like : 

view.ViewStyle=drawingviewstyleenum.kShadedDrawingViewStyle

it will speed up it alot!

 

1: 

Dim drw As DrawingDocument = ThisApplication.ActiveDocument
Dim sm As DrawingStylesManager = drw.StylesManager
Dim view As DrawingView = drw.ActiveSheet.DrawingViews(1)
view.ViewStyle=DrawingViewStyleEnum.kShadedDrawingViewStyle
' Dictionary: nazwa warstwy → kolekcja segmentów
Dim dict As New Dictionary(Of String, ObjectCollection)

' Zbieranie segmentów wg warstw
For Each cu As DrawingCurve In view.DrawingCurves
    For Each se As DrawingCurveSegment In cu.Segments
		If Not se.Visible Then Continue For
        Dim layerName As String = se.Layer.Name

        If Not dict.ContainsKey(layerName) Then
            dict(layerName) = ThisApplication.TransientObjects.CreateObjectCollection
        End If

        dict(layerName).Add(se)
    Next
Next

' Tworzenie nowych warstw i przenoszenie segmentów
For Each kvp In dict
    Dim oldName As String = kvp.Key
    Dim newName As String = "invisible_" & oldName
	Dim cntnais As Boolean = False
    ' Jeśli warstwa nie istnieje — utwórz
	For Each lay As Layer In sm.Layers
	If lay.Name=newName Then  cntnais=True : Exit For
	Next
    If Not cntnaisThen
		Try : sm.Layers.Item(oldName).Copy(newName)  : Catch : End Try
    End If
sm.Layers.Item(newName).Visible=False
    ' Przeniesienie segmentów na nową warstwę
    drw.ActiveSheet.ChangeLayer(kvp.Value, sm.Layers(newName))
	
Next

and switching back:

 

Dim drw As DrawingDocument = ThisApplication.ActiveDocument
Dim sm As DrawingStylesManager = drw.StylesManager
Dim view As DrawingView = drw.ActiveSheet.DrawingViews(1)

' Dictionary: nazwa warstwy → kolekcja segmentów
Dim dict As New Dictionary(Of String, ObjectCollection)

' Zbieranie segmentów wg warstw
For Each cu As DrawingCurve In view.DrawingCurves
    For Each se As DrawingCurveSegment In cu.Segments
		If Not se.Visible Then Continue For
        Dim layerName As String = se.Layer.Name
If layerName.StartsWith("invisible_") Then
'se.Layer.Visible=True
        If Not dict.ContainsKey(layerName) Then
            dict(layerName) = ThisApplication.TransientObjects.CreateObjectCollection
        End If

        dict(layerName).Add(se)
	End If
    Next
Next

' Tworzenie nowych warstw i przenoszenie segmentów
For Each kvp In dict
    Dim oldName As String = Replace(kvp.Key,"invisible_","")
    
	Dim cntnais As Boolean = False
    ' Jeśli warstwa nie istnieje — utwórz
	For Each lay As Layer In sm.Layers
	If lay.Name = oldName Then cntnais = True :		Exit For
	Next
    If  cntnais Then
	

    ' Przeniesienie segmentów na nową warstwę
    drw.ActiveSheet.ChangeLayer(kvp.Value, sm.Layers(oldName))
	 End If
Next

 

2:

Dim drw As DrawingDocument = ThisApplication.ActiveDocument
Dim sm As DrawingStylesManager = drw.StylesManager
Dim view As DrawingView = drw.ActiveSheet.DrawingViews(1)
view.ViewStyle=DrawingViewStyleEnum.kShadedDrawingViewStyle
Dim drw_curves As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
For Each cu As DrawingCurve In view.DrawingCurves 
For Each se As DrawingCurveSegment In cu.Segments
	drw_curves.Add(se)
Next
Next
ThisApplication.ActiveDocument.SelectSet.SelectMultiple(drw_curves)
ThisApplication.CommandManager.ControlDefinitions("DrawingEntityVisibilityCtxCmd").Execute

use

view.ShowHiddenCurves

to unhide it.

Hi, maybe you want to vote my:

Ideas

or check my apps:

DrawingTools   View&ColoringTools   MRUFolders   auto-save-replace

0 Likes