Create layer from file

Create layer from file

Anonymous
Not applicable
778 Views
2 Replies
Message 1 of 3

Create layer from file

Anonymous
Not applicable

Hi

 

I need some help

 

I try to create list of layer from a files, but I don't understand the Do /While and I have a message error like missing  information for the creation of layer

 

Ex. of my list files

;Layername, colour,linetype

 

*Layer1

layer1a, 7, continuous

Layer1b,12,hidden

 

*layer2

layer2a,70,continous

Layer2b,82,hidden

 

The code I have from now

 

Dim sTemp As String
Dim sTemp1 As String
Dim nFile As Integer
Dim sLAYER As String
Dim sColor As String
Dim sLinetype As String

Dim objLayer As AcadLayer

 

sTemp = ListBox1.Text

 

nFile = FreeFile

 

Open sFile For Input As #nFile

    While Not EOF(nFile)

        Line Input #nFile, sTemp1

       

         If sTemp1 = "*" & sTemp Then

         Input #nFile, sLAYER, sColor, sLinetype
        
             Set objLayer = ThisDrawing.Layers.Add(sLAYER)
             objLayer.color = sColor
             objLayer.Linetype = sLinetype

        End If
        
    Wend

 

So is there someone could tell me how fix it

 

Thanks!

 

0 Likes
779 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

I'm not good at reading files, so I can only suggest you to try the following

1) use the following for adding your layer

             On Error Resume Next
             Set objLayer = ThisDrawing.Layers.Add(sLAYER)
             If Err Then Set objLayer = ThisDrawing.Layers.Item(sLAYER)
             On Error GoTo 0

 so that if the layer already exists, you simply set your objLayer variable to it instead of adding it that would result in an error

2) use "objLayer.color = CInt(sColor)", to have an integer number assigned to color property, instead of a string

3) use "objLayer.Linetype = UCase(sLinetype)", to have always uppercase characters ("CONTINUOUS" instead of "continuous")

 

Finally as for the "While-Wend" loop, it looks like it should work but I'm not used at it and I'd code a "Do While-Loop" one as follows 

Do While Not EOF(1)
    '....
Loop

 

hope what above helps

 

bye

 

Message 3 of 3

Anonymous
Not applicable

Thanks for your help!

0 Likes