Make Layer program

Make Layer program

Anonymous
Not applicable
693 Views
14 Replies
Message 1 of 15

Make Layer program

Anonymous
Not applicable
I am working on a program to make layers based on data stored in a file.
I'd like the program to read in a text file file, list the data in a
Listbox control and add members. The layer data will be stored in a text
file with commas delimiting the data in a format as follows:

Name,Color,Linetype,Visibility

Dim, 4, continuous, on
Text, 2, continuous, on
Hidden, 3, hidden, off
Center, 8, center, on

As we have several layering conventions for various projects, the user
will be asked for the name of the file to read using an input box. Has
anyone seen a similar program or can someone help me with this project?
I'd like to know if anyone has any good layer creating programs
available. Thanks, Trevor
0 Likes
694 Views
14 Replies
Replies (14)
Message 2 of 15

Anonymous
Not applicable
Trevor,
I think that you may find it wasier to read from an excel file, and have it
complete a loop until it reaches the end of the file. However there are
several ways to read from a text file. This is probably the trickiest part:

' Open the file, then breakit down into single characters.
' Next eavluate each character
' until the delimiter as specified by AutoCAD is encountered.
oenFile = "c:\temp\layerlist.txt"
Open openFile For Binary As Filenum
filLength = Int(FileLen(openFile))
Chtr = String(1, " ")

' Now have it repeat until it reaches the end of the text file
For intCounter = start to filLength

----What I did after opening the file and establishing the process of
reading each character of the text file, was to stack the characters in a
variable until it reached a comma, then move on to the next and so on. This
is an example of THAT code.

If Chtr = Chr(10) Then GoTo NextChar

If placeholder = 0 Then
If Chtr <> "," Then
varFirstVariable = varFirstVariable + chtr
Else
' Move to the next character
goto NextChar
End If
NextChar:
' There's a bunch of code here that transfers the value(s) of the
' Variable(s) to their respective holders
Next 'this completes the For...Next

I hope that this makes sense, I can't post any more of the code for various
reasons, but that is the idea. Like I said, it is easier to do this from an
excel file b/c then you don't have to parse through every single character.

Rob

[email protected] (Trevor Smith) wrote in
<[email protected]>:
>I am working on a program to make layers based on data stored in a file.
>I'd like the program to read in a text file file, list the data in a
>Listbox control and add members. The layer data will be stored in a text
>file with commas delimiting the data in a format as follows:
>
>Name,Color,Linetype,Visibility
>
>Dim, 4, continuous, on
>Text, 2, continuous, on
>Hidden, 3, hidden, off
>Center, 8, center, on
>
>As we have several layering conventions for various projects, the user
>will be asked for the name of the file to read using an input box. Has
>anyone seen a similar program or can someone help me with this project?
>I'd like to know if anyone has any good layer creating programs
>available. Thanks, Trevor
>
>
>
0 Likes
Message 3 of 15

Anonymous
Not applicable
Parsing isn't as scary as all that (although it's not as easy as it should
be in VBA). You can find some parsing routines at http://www.vbsquare.com By
using text files, Trevor avoids the problem of a machine not having Excel or
possibly the wrong version. Text files are universal and make the program
self-contained. In fact, here's some code to get you started. I haven't
tested any of it, so be sure to debug. Also, be sure to store the layer
visibility as either 0 and 1 or True and False. Hope this helps.

Public Function Parse(Str As String, Delim As String) As Variant

Dim tokens() As String, pos As Long, i As Integer

pos = InStr(1, Str, Delim, vbTextCompare)
i = 0

Do While pos > 0
ReDim Preserve tokens(0 To i)
tokens(i) = Mid$(Str, 1, pos - 1)
Str = Mid$(Str, pos + 1)
i = i + 1
pos = InStr(1, Str, Delim, vbTextCompare)
Loop

If Len(Str) > 0 Then
ReDim Preserve tokens(0 To i)
tokens(i) = Str
End If

Parse = tokens

End Function

Public Sub MakeLayers(fileName As String)

Dim lay As AcadLayer, fh As Integer, tokens

If Dir(fileName) <> "" Then
fh = FreeFile
Open fileName For Input As #fh
While Not EOF(fh)
Line Input #fh, tmp
tokens = Parse(tmp, ",")
On Error Resume Next
Set lay = ThisDrawing.Layers.Add(tokens(LBound(tokens)))
If Err Then Set lay = ThisDrawing.Layers(tokens(LBound(tokens)))
On Error GoTo 0
lay.Color = CInt(tokens(LBound(tokens) + 1))
lay.Linetype = tokens(LBound(tokens) + 2)
lay.LayerOn = CBool(tokens(LBound(tokens) + 3))
Loop
Close #fh
End If

End Sub

--
Get free software and more at
http://msnhomepages.talkcity.com/protectionfault/foquendo

"Robert Brown" wrote in message
news:[email protected]...
> Trevor,
> I think that you may find it wasier to read from an excel file, and have
it
> complete a loop until it reaches the end of the file. However there are
> several ways to read from a text file. This is probably the trickiest
part:
>
> ' Open the file, then breakit down into single characters.
> ' Next eavluate each character
> ' until the delimiter as specified by AutoCAD is encountered.
> oenFile = "c:\temp\layerlist.txt"
> Open openFile For Binary As Filenum
> filLength = Int(FileLen(openFile))
> Chtr = String(1, " ")
>
> ' Now have it repeat until it reaches the end of the text file
> For intCounter = start to filLength
>
> ----What I did after opening the file and establishing the process of
> reading each character of the text file, was to stack the characters in a
> variable until it reached a comma, then move on to the next and so on.
This
> is an example of THAT code.
>
> If Chtr = Chr(10) Then GoTo NextChar
>
> If placeholder = 0 Then
> If Chtr <> "," Then
> varFirstVariable = varFirstVariable + chtr
> Else
> ' Move to the next character
> goto NextChar
> End If
> NextChar:
> ' There's a bunch of code here that transfers the value(s) of the
> ' Variable(s) to their respective holders
> Next 'this completes the For...Next
>
> I hope that this makes sense, I can't post any more of the code for
various
> reasons, but that is the idea. Like I said, it is easier to do this from
an
> excel file b/c then you don't have to parse through every single
character.
>
> Rob
>
> [email protected] (Trevor Smith) wrote in
> <[email protected]>:
> >I am working on a program to make layers based on data stored in a file.
> >I'd like the program to read in a text file file, list the data in a
> >Listbox control and add members. The layer data will be stored in a text
> >file with commas delimiting the data in a format as follows:
> >
> >Name,Color,Linetype,Visibility
> >
> >Dim, 4, continuous, on
> >Text, 2, continuous, on
> >Hidden, 3, hidden, off
> >Center, 8, center, on
> >
> >As we have several layering conventions for various projects, the user
> >will be asked for the name of the file to read using an input box. Has
> >anyone seen a similar program or can someone help me with this project?
> >I'd like to know if anyone has any good layer creating programs
> >available. Thanks, Trevor
> >
> >
> >
>
0 Likes
Message 4 of 15

Anonymous
Not applicable
Trevor,

in the Customer-Files NG I posted a module that I downloaded from the
internet. It will allow you to retrieve a string from a delimited string
given the position of the string that you want and the delimiter.

Since your data is in a consistent order you could use LineInput to retrieve
the line of data and then retrieve your data with the function in the
module.

Let me know if you need an example

Good luck

--
Mark Smith
Air Gage Co.
[email protected]

Trevor Smith wrote in message
news:[email protected]...
> I am working on a program to make layers based on data stored in a file.
> I'd like the program to read in a text file file, list the data in a
> Listbox control and add members. The layer data will be stored in a text
> file with commas delimiting the data in a format as follows:
>
> Name,Color,Linetype,Visibility
>
> Dim, 4, continuous, on
> Text, 2, continuous, on
> Hidden, 3, hidden, off
> Center, 8, center, on
>
> As we have several layering conventions for various projects, the user
> will be asked for the name of the file to read using an input box. Has
> anyone seen a similar program or can someone help me with this project?
> I'd like to know if anyone has any good layer creating programs
> available. Thanks, Trevor
>
>
>
0 Likes
Message 5 of 15

Anonymous
Not applicable
Hi Mark. Let me ask you something. And this is just a discussion type
question. It is not aimed at you or anyone in particular. Personally, I have
never understood the need for a parsing routine that returns only a single
token from a delimited string. It seems much more flexible to tokenize the
entire string and pluck individual tokens from the resulting array. After
all, you never know when you might want something else from the string.
Using the single token method, you have to tokenize the string yet again to
retrieve a different token. So what am I just not seeing?

--
Get free software and more at
http://msnhomepages.talkcity.com/protectionfault/foquendo

"Mark Smith" wrote in message
news:[email protected]...
> Trevor,
>
> in the Customer-Files NG I posted a module that I downloaded from the
> internet. It will allow you to retrieve a string from a delimited string
> given the position of the string that you want and the delimiter.
>
> Since your data is in a consistent order you could use LineInput to
retrieve
> the line of data and then retrieve your data with the function in the
> module.
>
> Let me know if you need an example
>
> Good luck
>
>
> --
> Mark Smith
> Air Gage Co.
> [email protected]
>
>
> Trevor Smith wrote in message
> news:[email protected]...
> > I am working on a program to make layers based on data stored in a file.
> > I'd like the program to read in a text file file, list the data in a
> > Listbox control and add members. The layer data will be stored in a text
> > file with commas delimiting the data in a format as follows:
> >
> > Name,Color,Linetype,Visibility
> >
> > Dim, 4, continuous, on
> > Text, 2, continuous, on
> > Hidden, 3, hidden, off
> > Center, 8, center, on
> >
> > As we have several layering conventions for various projects, the user
> > will be asked for the name of the file to read using an input box. Has
> > anyone seen a similar program or can someone help me with this project?
> > I'd like to know if anyone has any good layer creating programs
> > available. Thanks, Trevor
> >
> >
> >
>
>
0 Likes
Message 6 of 15

Anonymous
Not applicable
Frank,

You're probably right creating an array of the tokens is probably a bit
more useful in the long-run. I personally have done this one token at a
time b/c when I started this kind of process I only had a couple of lines
of text to read and all of the comma seperated values were filling in
seperate variables, much like an *.ini file. I guess that the program just
sort of grew and grew, and this is the way I kept doing things. I have a
VERY fast computer, but it still seems to take a little while to parse
through with my method.

Thanks for the question, it helps to stand back and question how you're
doing things every now and again.

[email protected] (Frank Oquendo) wrote in
<[email protected]>:

>Hi Mark. Let me ask you something. And this is just a discussion type
>question. It is not aimed at you or anyone in particular. Personally, I
>have never understood the need for a parsing routine that returns only a
>single token from a delimited string. It seems much more flexible to
>tokenize the entire string and pluck individual tokens from the
>resulting array. After all, you never know when you might want something
>else from the string. Using the single token method, you have to
>tokenize the string yet again to retrieve a different token. So what am
>I just not seeing?
>
>--
>Get free software and more at
>http://msnhomepages.talkcity.com/protectionfault/foquendo
>
>
>"Mark Smith" wrote in message
>news:[email protected]...
>> Trevor,
>>
>> in the Customer-Files NG I posted a module that I downloaded from the
>> internet. It will allow you to retrieve a string from a delimited
>> string given the position of the string that you want and the
>> delimiter.
>>
>> Since your data is in a consistent order you could use LineInput to
>retrieve
>> the line of data and then retrieve your data with the function in the
>> module.
>>
>> Let me know if you need an example
>>
>> Good luck
0 Likes
Message 7 of 15

Anonymous
Not applicable
Frank,

I guess if you know what you want and where it is why not just go get it.

I don't know if it is any faster or not. With the module that I posted you
only have a single read from the file (per line of data that is). In
Trevor's case, The data is consistently in the same place on the line, i.e.
Layer name is always the first element, Color is always the second element,
and so on. Now, if you want to put them into an array, you can put the code
into a do while not EOF and read the line in and put it into your array.

I am sure that there is better, faster, stronger ways to do this, but it
seams that there is less comparing in this method.

That is my final answer 🙂

Thanks for the question.

--
Mark Smith
Air Gage Co.
[email protected]

Frank Oquendo wrote in message
news:[email protected]...
> Hi Mark. Let me ask you something. And this is just a discussion type
> question. It is not aimed at you or anyone in particular. Personally, I
have
> never understood the need for a parsing routine that returns only a single
> token from a delimited string. It seems much more flexible to tokenize the
> entire string and pluck individual tokens from the resulting array. After
> all, you never know when you might want something else from the string.
> Using the single token method, you have to tokenize the string yet again
to
> retrieve a different token. So what am I just not seeing?
>
> --
> Get free software and more at
> http://msnhomepages.talkcity.com/protectionfault/foquendo
>
>
> "Mark Smith" wrote in message
> news:[email protected]...
> > Trevor,
> >
> > in the Customer-Files NG I posted a module that I downloaded from the
> > internet. It will allow you to retrieve a string from a delimited
string
> > given the position of the string that you want and the delimiter.
> >
> > Since your data is in a consistent order you could use LineInput to
> retrieve
> > the line of data and then retrieve your data with the function in the
> > module.
> >
> > Let me know if you need an example
> >
> > Good luck
> >
> >
> > --
> > Mark Smith
> > Air Gage Co.
> > [email protected]
> >
> >
> > Trevor Smith wrote in message
> > news:[email protected]...
> > > I am working on a program to make layers based on data stored in a
file.
> > > I'd like the program to read in a text file file, list the data in a
> > > Listbox control and add members. The layer data will be stored in a
text
> > > file with commas delimiting the data in a format as follows:
> > >
> > > Name,Color,Linetype,Visibility
> > >
> > > Dim, 4, continuous, on
> > > Text, 2, continuous, on
> > > Hidden, 3, hidden, off
> > > Center, 8, center, on
> > >
> > > As we have several layering conventions for various projects, the user
> > > will be asked for the name of the file to read using an input box. Has
> > > anyone seen a similar program or can someone help me with this
project?
> > > I'd like to know if anyone has any good layer creating programs
> > > available. Thanks, Trevor
> > >
> > >
> > >
> >
> >
>
>
0 Likes
Message 8 of 15

Anonymous
Not applicable
Thanks for your help Robert, I'll try that out.

Robert Brown wrote:

> Trevor,
> I think that you may find it wasier to read from an excel file, and have it
> complete a loop until it reaches the end of the file. However there are
> several ways to read from a text file. This is probably the trickiest part:
>
> ' Open the file, then breakit down into single characters.
> ' Next eavluate each character
> ' until the delimiter as specified by AutoCAD is encountered.
> oenFile = "c:\temp\layerlist.txt"
> Open openFile For Binary As Filenum
> filLength = Int(FileLen(openFile))
> Chtr = String(1, " ")
>
> ' Now have it repeat until it reaches the end of the text file
> For intCounter = start to filLength
>
> ----What I did after opening the file and establishing the process of
> reading each character of the text file, was to stack the characters in a
> variable until it reached a comma, then move on to the next and so on. This
> is an example of THAT code.
>
> If Chtr = Chr(10) Then GoTo NextChar
>
> If placeholder = 0 Then
> If Chtr <> "," Then
> varFirstVariable = varFirstVariable + chtr
> Else
> ' Move to the next character
> goto NextChar
> End If
> NextChar:
> ' There's a bunch of code here that transfers the value(s) of the
> ' Variable(s) to their respective holders
> Next 'this completes the For...Next
>
> I hope that this makes sense, I can't post any more of the code for various
> reasons, but that is the idea. Like I said, it is easier to do this from an
> excel file b/c then you don't have to parse through every single character.
>
> Rob
>
> [email protected] (Trevor Smith) wrote in
> <[email protected]>:
> >I am working on a program to make layers based on data stored in a file.
> >I'd like the program to read in a text file file, list the data in a
> >Listbox control and add members. The layer data will be stored in a text
> >file with commas delimiting the data in a format as follows:
> >
> >Name,Color,Linetype,Visibility
> >
> >Dim, 4, continuous, on
> >Text, 2, continuous, on
> >Hidden, 3, hidden, off
> >Center, 8, center, on
> >
> >As we have several layering conventions for various projects, the user
> >will be asked for the name of the file to read using an input box. Has
> >anyone seen a similar program or can someone help me with this project?
> >I'd like to know if anyone has any good layer creating programs
> >available. Thanks, Trevor
> >
> >
> >
0 Likes
Message 9 of 15

Anonymous
Not applicable
Thanks Frank! I'll try to apply this to my program, hopefully I'll get
somewhere. As usual, your wealth of knowledge is appreciated here.

Frank Oquendo wrote:

> Parsing isn't as scary as all that (although it's not as easy as it should
> be in VBA). You can find some parsing routines at http://www.vbsquare.com By
> using text files, Trevor avoids the problem of a machine not having Excel or
> possibly the wrong version. Text files are universal and make the program
> self-contained. In fact, here's some code to get you started. I haven't
> tested any of it, so be sure to debug. Also, be sure to store the layer
> visibility as either 0 and 1 or True and False. Hope this helps.
>
> Public Function Parse(Str As String, Delim As String) As Variant
>
> Dim tokens() As String, pos As Long, i As Integer
>
> pos = InStr(1, Str, Delim, vbTextCompare)
> i = 0
>
> Do While pos > 0
> ReDim Preserve tokens(0 To i)
> tokens(i) = Mid$(Str, 1, pos - 1)
> Str = Mid$(Str, pos + 1)
> i = i + 1
> pos = InStr(1, Str, Delim, vbTextCompare)
> Loop
>
> If Len(Str) > 0 Then
> ReDim Preserve tokens(0 To i)
> tokens(i) = Str
> End If
>
> Parse = tokens
>
> End Function
>
> Public Sub MakeLayers(fileName As String)
>
> Dim lay As AcadLayer, fh As Integer, tokens
>
> If Dir(fileName) <> "" Then
> fh = FreeFile
> Open fileName For Input As #fh
> While Not EOF(fh)
> Line Input #fh, tmp
> tokens = Parse(tmp, ",")
> On Error Resume Next
> Set lay = ThisDrawing.Layers.Add(tokens(LBound(tokens)))
> If Err Then Set lay = ThisDrawing.Layers(tokens(LBound(tokens)))
> On Error GoTo 0
> lay.Color = CInt(tokens(LBound(tokens) + 1))
> lay.Linetype = tokens(LBound(tokens) + 2)
> lay.LayerOn = CBool(tokens(LBound(tokens) + 3))
> Loop
> Close #fh
> End If
>
> End Sub
>
> --
> Get free software and more at
> http://msnhomepages.talkcity.com/protectionfault/foquendo
>
> "Robert Brown" wrote in message
> news:[email protected]...
> > Trevor,
> > I think that you may find it wasier to read from an excel file, and have
> it
> > complete a loop until it reaches the end of the file. However there are
> > several ways to read from a text file. This is probably the trickiest
> part:
> >
> > ' Open the file, then breakit down into single characters.
> > ' Next eavluate each character
> > ' until the delimiter as specified by AutoCAD is encountered.
> > oenFile = "c:\temp\layerlist.txt"
> > Open openFile For Binary As Filenum
> > filLength = Int(FileLen(openFile))
> > Chtr = String(1, " ")
> >
> > ' Now have it repeat until it reaches the end of the text file
> > For intCounter = start to filLength
> >
> > ----What I did after opening the file and establishing the process of
> > reading each character of the text file, was to stack the characters in a
> > variable until it reached a comma, then move on to the next and so on.
> This
> > is an example of THAT code.
> >
> > If Chtr = Chr(10) Then GoTo NextChar
> >
> > If placeholder = 0 Then
> > If Chtr <> "," Then
> > varFirstVariable = varFirstVariable + chtr
> > Else
> > ' Move to the next character
> > goto NextChar
> > End If
> > NextChar:
> > ' There's a bunch of code here that transfers the value(s) of the
> > ' Variable(s) to their respective holders
> > Next 'this completes the For...Next
> >
> > I hope that this makes sense, I can't post any more of the code for
> various
> > reasons, but that is the idea. Like I said, it is easier to do this from
> an
> > excel file b/c then you don't have to parse through every single
> character.
> >
> > Rob
> >
> > [email protected] (Trevor Smith) wrote in
> > <[email protected]>:
> > >I am working on a program to make layers based on data stored in a file.
> > >I'd like the program to read in a text file file, list the data in a
> > >Listbox control and add members. The layer data will be stored in a text
> > >file with commas delimiting the data in a format as follows:
> > >
> > >Name,Color,Linetype,Visibility
> > >
> > >Dim, 4, continuous, on
> > >Text, 2, continuous, on
> > >Hidden, 3, hidden, off
> > >Center, 8, center, on
> > >
> > >As we have several layering conventions for various projects, the user
> > >will be asked for the name of the file to read using an input box. Has
> > >anyone seen a similar program or can someone help me with this project?
> > >I'd like to know if anyone has any good layer creating programs
> > >available. Thanks, Trevor
> > >
> > >
> > >
> >
0 Likes
Message 10 of 15

Anonymous
Not applicable
Sure Mark, I'd love a sample of that program and module. I'd like to do this on
my own but I'm just getting into VBA and its overwhelming right now. I'm gonna
have to get myself a good book. Thanks for your help. My e-mail is
[email protected]. Is it possible to sent it there? Thanks again. Trevor

Mark Smith wrote:

> Trevor,
>
> in the Customer-Files NG I posted a module that I downloaded from the
> internet. It will allow you to retrieve a string from a delimited string
> given the position of the string that you want and the delimiter.
>
> Since your data is in a consistent order you could use LineInput to retrieve
> the line of data and then retrieve your data with the function in the
> module.
>
> Let me know if you need an example
>
> Good luck
>
> --
> Mark Smith
> Air Gage Co.
> [email protected]
>
> Trevor Smith wrote in message
> news:[email protected]...
> > I am working on a program to make layers based on data stored in a file.
> > I'd like the program to read in a text file file, list the data in a
> > Listbox control and add members. The layer data will be stored in a text
> > file with commas delimiting the data in a format as follows:
> >
> > Name,Color,Linetype,Visibility
> >
> > Dim, 4, continuous, on
> > Text, 2, continuous, on
> > Hidden, 3, hidden, off
> > Center, 8, center, on
> >
> > As we have several layering conventions for various projects, the user
> > will be asked for the name of the file to read using an input box. Has
> > anyone seen a similar program or can someone help me with this project?
> > I'd like to know if anyone has any good layer creating programs
> > available. Thanks, Trevor
> >
> >
> >
0 Likes
Message 11 of 15

Anonymous
Not applicable
Mark, where do I find Customer-Files NG ? Thanks again, Trevor
P.S. this is a lot tougher that I thought, I would have to pick something as
complicated as this
to start on. Maybe I need to start at square one.

Mark Smith wrote:

> Trevor,
>
> in the Customer-Files NG I posted a module that I downloaded from the
> internet. It will allow you to retrieve a string from a delimited string
> given the position of the string that you want and the delimiter.
>
> Since your data is in a consistent order you could use LineInput to retrieve
> the line of data and then retrieve your data with the function in the
> module.
>
> Let me know if you need an example
>
> Good luck
>
> --
> Mark Smith
> Air Gage Co.
> [email protected]
>
> Trevor Smith wrote in message
> news:[email protected]...
> > I am working on a program to make layers based on data stored in a file.
> > I'd like the program to read in a text file file, list the data in a
> > Listbox control and add members. The layer data will be stored in a text
> > file with commas delimiting the data in a format as follows:
> >
> > Name,Color,Linetype,Visibility
> >
> > Dim, 4, continuous, on
> > Text, 2, continuous, on
> > Hidden, 3, hidden, off
> > Center, 8, center, on
> >
> > As we have several layering conventions for various projects, the user
> > will be asked for the name of the file to read using an input box. Has
> > anyone seen a similar program or can someone help me with this project?
> > I'd like to know if anyone has any good layer creating programs
> > available. Thanks, Trevor
> >
> >
> >
0 Likes
Message 12 of 15

Anonymous
Not applicable
Trevor -

The Customer-files group is found at
news://adesknews.autodesk.com/autodesk.autocad.customer-files.
--
Anne Brown
Autodesk Sysop/Moderator
Discussion Q&A: http://www.autodesk.com/discussion

Trevor Smith wrote:
>
> Mark, where do I find Customer-Files NG ? (snip)
0 Likes
Message 13 of 15

Anonymous
Not applicable
Actually you can have it both ways (kind of). Use a tab delimited text
file. These files are easy to pull into Excel and modify/tweak but it can
be done with just about anything. And parsing using a tab as a delimiter is
no more difficult than any other delimiter.

Mike Weaver

"Frank Oquendo" wrote in message
news:[email protected]...
> Parsing isn't as scary as all that (although it's not as easy as it should
> be in VBA). You can find some parsing routines at http://www.vbsquare.com
By
> using text files, Trevor avoids the problem of a machine not having Excel
or
> possibly the wrong version. Text files are universal and make the program
> self-contained. In fact, here's some code to get you started. I haven't
> tested any of it, so be sure to debug. Also, be sure to store the layer
> visibility as either 0 and 1 or True and False. Hope this helps.
>
>
> Public Function Parse(Str As String, Delim As String) As Variant
>
> Dim tokens() As String, pos As Long, i As Integer
>
> pos = InStr(1, Str, Delim, vbTextCompare)
> i = 0
>
> Do While pos > 0
> ReDim Preserve tokens(0 To i)
> tokens(i) = Mid$(Str, 1, pos - 1)
> Str = Mid$(Str, pos + 1)
> i = i + 1
> pos = InStr(1, Str, Delim, vbTextCompare)
> Loop
>
> If Len(Str) > 0 Then
> ReDim Preserve tokens(0 To i)
> tokens(i) = Str
> End If
>
> Parse = tokens
>
> End Function
>
>
> Public Sub MakeLayers(fileName As String)
>
> Dim lay As AcadLayer, fh As Integer, tokens
>
> If Dir(fileName) <> "" Then
> fh = FreeFile
> Open fileName For Input As #fh
> While Not EOF(fh)
> Line Input #fh, tmp
> tokens = Parse(tmp, ",")
> On Error Resume Next
> Set lay = ThisDrawing.Layers.Add(tokens(LBound(tokens)))
> If Err Then Set lay =
ThisDrawing.Layers(tokens(LBound(tokens)))
> On Error GoTo 0
> lay.Color = CInt(tokens(LBound(tokens) + 1))
> lay.Linetype = tokens(LBound(tokens) + 2)
> lay.LayerOn = CBool(tokens(LBound(tokens) + 3))
> Loop
> Close #fh
> End If
>
> End Sub
>
>
> --
> Get free software and more at
> http://msnhomepages.talkcity.com/protectionfault/foquendo
>
>
> "Robert Brown" wrote in message
> news:[email protected]...
> > Trevor,
> > I think that you may find it wasier to read from an excel file, and have
> it
> > complete a loop until it reaches the end of the file. However there are
> > several ways to read from a text file. This is probably the trickiest
> part:
> >
> > ' Open the file, then breakit down into single characters.
> > ' Next eavluate each character
> > ' until the delimiter as specified by AutoCAD is encountered.
> > oenFile = "c:\temp\layerlist.txt"
> > Open openFile For Binary As Filenum
> > filLength = Int(FileLen(openFile))
> > Chtr = String(1, " ")
> >
> > ' Now have it repeat until it reaches the end of the text file
> > For intCounter = start to filLength
> >
> > ----What I did after opening the file and establishing the process of
> > reading each character of the text file, was to stack the characters in
a
> > variable until it reached a comma, then move on to the next and so on.
> This
> > is an example of THAT code.
> >
> > If Chtr = Chr(10) Then GoTo NextChar
> >
> > If placeholder = 0 Then
> > If Chtr <> "," Then
> > varFirstVariable = varFirstVariable + chtr
> > Else
> > ' Move to the next character
> > goto NextChar
> > End If
> > NextChar:
> > ' There's a bunch of code here that transfers the value(s) of the
> > ' Variable(s) to their respective holders
> > Next 'this completes the For...Next
> >
> > I hope that this makes sense, I can't post any more of the code for
> various
> > reasons, but that is the idea. Like I said, it is easier to do this from
> an
> > excel file b/c then you don't have to parse through every single
> character.
> >
> > Rob
> >
> > [email protected] (Trevor Smith) wrote in
> > <[email protected]>:
> > >I am working on a program to make layers based on data stored in a
file.
> > >I'd like the program to read in a text file file, list the data in a
> > >Listbox control and add members. The layer data will be stored in a
text
> > >file with commas delimiting the data in a format as follows:
> > >
> > >Name,Color,Linetype,Visibility
> > >
> > >Dim, 4, continuous, on
> > >Text, 2, continuous, on
> > >Hidden, 3, hidden, off
> > >Center, 8, center, on
> > >
> > >As we have several layering conventions for various projects, the user
> > >will be asked for the name of the file to read using an input box. Has
> > >anyone seen a similar program or can someone help me with this project?
> > >I'd like to know if anyone has any good layer creating programs
> > >available. Thanks, Trevor
> > >
> > >
> > >
> >
>
>
0 Likes
Message 14 of 15

Anonymous
Not applicable
From the Visual Basic Help files of VB Design
http://vbdesign.hypermart.net/cadpages/

Hi Trevor,
I made a project just like this for A.C.A.D. the only thing it does not
include is the layer state information, but that would be a snap to add. The
code is just a bit to long to post here, if you would like I can e-mail you
the letters that contain the code.

Randall Rath
VB Design
0 Likes
Message 15 of 15

Anonymous
Not applicable
Randall, check out the thread "Conversion from decimal. . ."

--
R. Robert Bell, MCSE
Network Administrator (or, Modern-day Wizard)
(remove the "not." in my address for direct e-mail)
0 Likes