Home AutoCad VB Create New Layer
20 | 05 | 2012
This site has been updated and renewed. You have followed an old link.

Click here to go to the new site

http://www.visiblevisual.com/jupgrade

Create New Layer PDF Print E-mail
User Rating: / 1
PoorBest 
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

View source
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:
FileDescriptionFile sizeDownloads
Download this file (Addlayer.dvb)Addlayer.dvbAdd Layer12 Kb376
 

Add comment


Security code
Refresh

This site has been updated and renewed. You have followed an old link.

Click here to go to the new site

http://www.visiblevisual.com/jupgrade