|
Tutorials
|
|
When inserting objects into AutoCad its useful to set different layer to keep it all organised. The code below shows how to create a new layer
Show/Hidden vbnet code Function CreateLayer(ByVal namelayer As String, ByVal R, G, B As Double)
'****************************************
'*** Code from VisibleVisual.com ********
'****************************************
On Error Resume Next
Dim color As AcadAcCmColor
Dim newlayer As AcadLayer
'Select Layer or if not exists create a new layer
Set newlayer = ThisDrawing.Layers.Add(namelayer)
If Err > 0 Then
Set newlayer = ThisDrawing.Layers.Item(namelayer)
Err.Clear
End If
'Set AutoCAD Color Objects
If Left(AutoCAD.Application.ActiveDocument.GetVariable("acadver"), 2) = "16" Then
Set color = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor.16")
ElseIf Left(AutoCAD.Application.ActiveDocument.GetVariable("acadver"), 2) = "17" Then
Set color = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor.17")
Else
MsgBox "Wrong Autocad version fro this function"
Exit Function
End If
'R,B,G stands for Red, Green, Blue value
Call color.SetRGB(R, G, B)
'Create a Layer and make it the active layer
newlayer.TrueColor = color
ThisDrawing.ActiveLayer = newlayer
End Function
Attachments:
| File | Description | File size | Downloads |
Addlayer.dvb | Add Layer | 12 Kb | 376 |
|