VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Create layer from file

2 REPLIES 2
Reply
Message 1 of 3
joh_richard
433 Views, 2 Replies

Create layer from file

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!

 

2 REPLIES 2
Message 2 of 3
RICVBA
in reply to: joh_richard

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
joh_richard
in reply to: RICVBA

Thanks for your help!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost