| Author |
Message |
Tom Hanley
Guest
|
Posted:
Wed Jan 05, 2005 8:47 pm Post subject:
create layer names from text file and add prefix using LISP |
|
|
I am trying to automate creating layers using a text file containing the
list of layer names and adding a prefix to the list of layers. Example:
the text file would have:
Sewer
Sewer-text
Water
Water-text
Utils
Utils-text
the layers to be created would be
Lot01-Sewer
Lot01-Sewer-text
etc...
I want to give the user the option to input first lot number and how many
lots for layers to create. It might be nice to have a dialog box that lists
all the layers in the text file and the user can select the layers they want
to create for all the lots range. It would be even better if the user could
choose a dws file and select the layers from that.
Thanks,
Tom Hanley
|
|
| Back to top |
|
 |
Paul Turvill
Guest
|
Posted:
Wed Jan 05, 2005 8:58 pm Post subject:
Re: create layer names from text file and add prefix using L |
|
|
Show us what you've written so far ...
___
"Tom Hanley" <thanley@lanctully.com> wrote in message
news:41dc0c0b$1_1@newsprd01...
| Quote: | I am trying to automate creating layers using a text file containing the
list of layer names and adding a prefix to the list of layers. |
|
|
| Back to top |
|
 |
Tom Hanley
Guest
|
Posted:
Wed Jan 05, 2005 9:13 pm Post subject:
Re: create layer names from text file and add prefix using L |
|
|
I didn't get very far. I am not sure how to get a list of layer names from
the outside file. This routine just creates a single layer for each lot in
the range so far....
(Defun C:LLC ()
;T.HANLEY FOR L&T 1/5/05
;CREATES LAYERS FOR INDIVIDUAL LOTS
;(Setvar "Cmdecho" 0)
(Setq A (Getint "\nStarting LOT number: "))
(Setq B (Getint "\nEnding LOT number: "))
(If (> A B)
(Setq E -1)
(Setq E 1)
)
(Repeat (+ 1 (Abs (- A B)))
(Setq F (STRCAT "LOT" (Itoa A) "-" "SEWER"))
(Command "_LAYER" "M" F "")
(Setq A (+ A E))
)
;(Setvar "Cmdecho" 1)
)
"Paul Turvill" <nospam@turvill.com> wrote in message
news:41dc0e9c_1@newsprd01...
| Quote: | Show us what you've written so far ...
___
"Tom Hanley" <thanley@lanctully.com> wrote in message
news:41dc0c0b$1_1@newsprd01...
I am trying to automate creating layers using a text file containing the
list of layer names and adding a prefix to the list of layers.
|
|
|
| Back to top |
|
 |
Paul Turvill
Guest
|
Posted:
Wed Jan 05, 2005 9:26 pm Post subject:
Re: create layer names from text file and add prefix using L |
|
|
To get data from a file, you'll need the (open ... "r") and (read-line ...)
functions.
___
"Tom Hanley" <thanley@lanctully.com> wrote in message
news:41dc1231$1_2@newsprd01...
| Quote: | I didn't get very far. I am not sure how to get a list of layer names from
the outside file. |
|
|
| Back to top |
|
 |
Paul Turvill
Guest
|
Posted:
Wed Jan 05, 2005 9:28 pm Post subject:
Re: create layer names from text file and add prefix using L |
|
|
Oh, and after you've retrieved the data, the (close ...) function as well.
"Paul Turvill" <nospam@turvill.com> wrote in message
news:41dc153c_1@newsprd01...
| Quote: | To get data from a file, you'll need the (open ... "r") and (read-line
...) functions.
___
"Tom Hanley" <thanley@lanctully.com> wrote in message
news:41dc1231$1_2@newsprd01...
I didn't get very far. I am not sure how to get a list of layer names from
the outside file.
|
|
|
| Back to top |
|
 |
Tom Hanley
Guest
|
Posted:
Wed Jan 05, 2005 9:33 pm Post subject:
Re: create layer names from text file and add prefix using L |
|
|
Thx Paul. I did find that in the LISP reference in the help but I was
looking for a working example to alter. You can see that my LISP skills are
limited looking at my code.
"Paul Turvill" <nospam@turvill.com> wrote in message
news:41dc153c_1@newsprd01...
| Quote: | To get data from a file, you'll need the (open ... "r") and (read-line
...) functions.
___
"Tom Hanley" <thanley@lanctully.com> wrote in message
news:41dc1231$1_2@newsprd01...
I didn't get very far. I am not sure how to get a list of layer names from
the outside file.
|
|
|
| Back to top |
|
 |
Paul Turvill
Guest
|
Posted:
Wed Jan 05, 2005 9:41 pm Post subject:
Re: create layer names from text file and add prefix using L |
|
|
Example:
(setq filename (open "data.txt" "r"))
(while (setq layname (read-line filename))
(<<process the layname you just retrieved>>)
(<<you can include any number of functions here>>)
);; while
(close filename)
This snippet opens the file DATA.TXT as filename, then reads in and
processes one line at a time. The (while ...) loop terminates after the last
line is processed (end of file reached), and then the file is closed.
___
"Tom Hanley" <thanley@lanctully.com> wrote in message
news:41dc16ef$1_3@newsprd01...
| Quote: | Thx Paul. I did find that in the LISP reference in the help but I was
looking for a working example to alter. |
|
|
| Back to top |
|
 |
Tom Hanley
Guest
|
Posted:
Wed Jan 05, 2005 9:48 pm Post subject:
Re: create layer names from text file and add prefix using L |
|
|
Thx... This should keep me out of trouble for awhile! :)
"Paul Turvill" <nospam@turvill.com> wrote in message
news:41dc18a8_3@newsprd01...
| Quote: | Example:
(setq filename (open "data.txt" "r"))
(while (setq layname (read-line filename))
(<<process the layname you just retrieved>>)
(<<you can include any number of functions here>>)
);; while
(close filename)
This snippet opens the file DATA.TXT as filename, then reads in and
processes one line at a time. The (while ...) loop terminates after the
last line is processed (end of file reached), and then the file is closed.
___
"Tom Hanley" <thanley@lanctully.com> wrote in message
news:41dc16ef$1_3@newsprd01...
Thx Paul. I did find that in the LISP reference in the help but I was
looking for a working example to alter.
|
|
|
| Back to top |
|
 |
hawstom
Guest
|
Posted:
Wed Jan 05, 2005 9:59 pm Post subject:
Re: create layer names from text file and add prefix using L |
|
|
Better yet, why not get color and linetype information from the file too?
First, make the file like this:
("Layer1" "yellow" "dashed")
("Layer2" "red" "")
Then read the file and make the LIST like this:
(setq
f1
(open
(if (= (getvar "filedia") 1)
(GETFILED "Layer import file"
(strcat
(getvar "dwgprefix")
(substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname") 4)
)
"txt"
0
)
(findfile "layersettings.txt")
)
"r"
)
)
(while (setq rdlin (read-line f1))
(if (setq layerinput (read rdlin)) (setq layerlist (cons layerinput layerlist)))
Then you lust have to creat the layers:
(foreach layer layerlist
(command "._layer" "m" (car layer) "c" (cadr layer) "" "lt" (caddr later) "" "")
)
Does that help?
Tom Haws
Find Thomas Gail Haws at Google |
|
| Back to top |
|
 |
Tom Hanley
Guest
|
Posted:
Wed Jan 05, 2005 10:06 pm Post subject:
Re: create layer names from text file and add prefix using L |
|
|
Yes that was my next step and that is why I thought about using the dws
file.
"hawstom" <nospam@address.withheld> wrote in message
news:8830948.1104944414025.JavaMail.jive@jiveforum2.autodesk.com...
| Quote: | Better yet, why not get color and linetype information from the file too?
First, make the file like this:
("Layer1" "yellow" "dashed")
("Layer2" "red" "")
Then read the file and make the LIST like this:
(setq
f1
(open
(if (= (getvar "filedia") 1)
(GETFILED "Layer import file"
(strcat
(getvar "dwgprefix")
(substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname") 4)
)
"txt"
0
)
(findfile "layersettings.txt")
)
"r"
)
)
(while (setq rdlin (read-line f1))
(if (setq layerinput (read rdlin)) (setq layerlist (cons layerinput
layerlist)))
Then you lust have to creat the layers:
(foreach layer layerlist
(command "._layer" "m" (car layer) "c" (cadr layer) "" "lt" (caddr later)
"" "")
)
Does that help?
Tom Haws
Find Thomas Gail Haws at Google |
|
|
| Back to top |
|
 |
Paul Turvill
Guest
|
Posted:
Wed Jan 05, 2005 10:32 pm Post subject:
Re: create layer names from text file and add prefix using L |
|
|
The syntax of your (open ...) function is incorrect:
(SETQ LNFILE (OPEN fil) "R")
should be
(setq LNFILE (open fil "r"))
___
"Tom Hanley" <thanley@lanctully.com> wrote in message
news:41dc1f22$1_1@newsprd01...
| Quote: | Okay... This does find the file and reads the first line and builds the
layer for the whole range but stops after the first line in my text file.
attached is the text file. |
|
|
| Back to top |
|
 |
Tom Smith
Guest
|
Posted:
Wed Jan 05, 2005 11:05 pm Post subject:
Re: create layer names from text file and add prefix using L |
|
|
He has a good suggestion, but it doesn't address your need to create the
layers lot by lot. Also, per your previous post, I would not open and read
the text file again for each lot. I'd get all the "base" layer info in one
list as per Tom's suggestion, then process that list for each lot number.
Something roughly like this (untested):
(foreach n layerlist ;get the list of layer lists per Tom Haws
(setq currentlotnum startlotnum) ;cycle from starting to ending lot
numbers
(while (<= currentlotnum endlotnum)
(command "._layer" "m" (strcat "LOT" (itoa currentlotnum) "-" (car
layer)) "c" (cadr layer) "" "lt" (caddr later) "" "")
(setq currentlotnum (1+ currentlotnum))
)
) |
|
| Back to top |
|
 |
Tom Hanley
Guest
|
Posted:
Fri Jan 07, 2005 1:58 am Post subject:
Re: create layer names from text file and add prefix using L |
|
|
Thanks for the help. I now have the list of one lot number with all the
layers being built but I get an error bad argument type: streamp
"S:/DRAFTING STANDARDS/LOTLAYERS.TXT" and it stops running. I have been
trying to understand what Tom Haws and Tom Smith have been offering but I
can't seem to figure it out. I guess I need to find a working example and
reverse engineer it to understand what is happening. Thanks for all who
tried to help.
"Paul Turvill" <nospam@turvill.com> wrote in message
news:41dc248b_2@newsprd01...
| Quote: | The syntax of your (open ...) function is incorrect:
(SETQ LNFILE (OPEN fil) "R")
should be
(setq LNFILE (open fil "r"))
___
"Tom Hanley" <thanley@lanctully.com> wrote in message
news:41dc1f22$1_1@newsprd01...
Okay... This does find the file and reads the first line and builds the
layer for the whole range but stops after the first line in my text file.
attached is the text file.
|
|
|
| Back to top |
|
 |
Tom Smith
Guest
|
Posted:
Fri Jan 07, 2005 2:08 am Post subject:
Re: create layer names from text file and add prefix using L |
|
|
Don't despair, Tom! If I have time this weekend I'll try to cobble together a working example, if someone doesn't beat me to it.
It can be very frustrating trying to get a handle on lisp, but hang in there & it will eventually get easier. |
|
| Back to top |
|
 |
Tom Hanley
Guest
|
Posted:
Fri Jan 07, 2005 2:22 am Post subject:
Re: create layer names from text file and add prefix using L |
|
|
Thanks for the inspiration. I used to write a few programs years back but
usually I start with something close and the tweak it in for what I need.
"Tom Smith" <nospam@address.withheld> wrote in message
news:11624151.1105045744489.JavaMail.jive@jiveforum1.autodesk.com...
| Quote: | Don't despair, Tom! If I have time this weekend I'll try to cobble
together a working example, if someone doesn't beat me to it.
It can be very frustrating trying to get a handle on lisp, but hang in
there & it will eventually get easier. |
|
|
| Back to top |
|
 |
|
|
|
|