Q:
How can I change the objects layer in Drawingdocument ?
A:
Each drawing object has its own "Layer" property. If you need to change object's layer you can simply assign a new layer, where the object should be placed.
Note: For some symbols, such as TitleBlock, it's necessary to edit the definition object in order to change objects within TitleBlock.
The VB.Net code below does the following:
1. Creates a new layer as a copy of Title (ISO) layer.
2. Sets the layer's color to Red and linetype to Continuous.
3. Edits TitleBlockDefinition and changes layer of each TextBox to a new layer.
Sub ChangeTextBoxLayer(ByVal app As Inventor.Application)
Dim doc As DrawingDocument = app.ActiveDocument
' find base layer
Dim oBaseLayer As Layer
oBaseLayer = doc.StylesManager.Layers.Item("Title (ISO)")
If oBaseLayer Is Nothing Then
Debug.Print("Base layer doesn't exist")
Exit Sub
End If
' create new layer
Dim oNewLayer As Layer
oNewLayer = doc.StylesManager.Layers.Item("Text")
If oNewLayer Is Nothing Then
oNewLayer = oBaseLayer.Copy("Text")
End If
' change color to red
Dim oColor As Color
oColor = oNewLayer.Color
oColor.Red = 255
oColor.Green = 0
oColor.Blue = 0
oNewLayer.Color = oColor
oNewLayer.LineType = LineTypeEnum.kContinuousLineType
' retrieve title block
Dim oTitleBlock As TitleBlock
oTitleBlock = doc.ActiveSheet.TitleBlock
Dim oTitleBlockDef As TitleBlockDefinition
oTitleBlockDef = oTitleBlock.Definition
' edit titleblock sketch and set layer of each textbox to new layer
Dim oSketch As DrawingSketch = Nothing
Call oTitleBlockDef.Edit(oSketch)
Dim oTextBox As Inventor.TextBox
For Each oTextBox In oSketch.TextBoxes
oTextBox.Layer = oNewLayer
Next
' finish titleblock edit
Call oTitleBlockDef.ExitEdit()
End Sub