Ah! the dilemma, and the posibilities...
CADForums.net Forum Index CADForums.net
Discussion of AutoCAD and other CAD software.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web cadforums.net
Ah! the dilemma, and the posibilities...

 
Post new topic   Reply to topic    CADForums.net Forum Index -> Customization
Author Message
Rudy Tovar
Guest





Posted: Tue Dec 21, 2004 10:51 pm    Post subject: Ah! the dilemma, and the posibilities... Reply with quote

Before I actually get started, perhaps someone has already done this... it's
actually a no brainer, but like to see if anyone has come up with a
condensed version that's a bit more efficient...

OK...

First a text a file that contains...

****THIS COMMENT OR THAT****

**122 LINE ONE
**123 LINE TWO
**124 LINE THREE

********************************

Considering it may contain spaces and more comments, I'd like to be able to
use vl-position to located number "122" in a list that I'll be creating of a
file reference.

Also, eliminate any spaces, or tabs when returning the reference number
"LINE ITEM NOTE".

<list> = ("****THIS COMMENT OR THAT****" "" "**122 LINE ONE"
.....etc.....)

In the end I'd like to say (get-note "123" <list>) and all it returns is
"LINE TWO" without any spaces or tabs in front of the note...

I'd like to eliminate possibilities that someone may use spaces, tabs or
both when writing the line item note.

I know I could come up with a simple solution, but I'd like to see if
someone may have a more efficient method, instead of having to compare each
character in the LINE considering that the list could contain hundreds or
items listed.

Thank you for your comments

Back to top
Michael Puckett
Guest





Posted: Tue Dec 21, 2004 11:13 pm    Post subject: Re: Ah! the dilemma, and the posibilities... Reply with quote

What about using vl-string-trim, vl-string-search etc. to suit ...

(vl-string-trim " */t" "***122 LINE ONE")

=> "122 LINE ONE"

(if
(setq pos
(vl-string-search
" "
(setq temp
(vl-string-trim
" */t"
"**122 LINE ONE"
)
)
)
)
(substr temp 1 pos)
)

=> "122"

Etc.

"Rudy Tovar" <Rudy@CadentityNoSpam.com> wrote in message news:41c861bd$1_3@newsprd01...
Quote:
Before I actually get started, perhaps someone has already done this... it's
actually a no brainer, but like to see if anyone has come up with a
condensed version that's a bit more efficient...

OK...

First a text a file that contains...

****THIS COMMENT OR THAT****

**122 LINE ONE
**123 LINE TWO
**124 LINE THREE

********************************

Considering it may contain spaces and more comments, I'd like to be able to
use vl-position to located number "122" in a list that I'll be creating of a
file reference.

Also, eliminate any spaces, or tabs when returning the reference number
"LINE ITEM NOTE".

list> = ("****THIS COMMENT OR THAT****" "" "**122 LINE ONE"
....etc.....)

In the end I'd like to say (get-note "123" <list>) and all it returns is
"LINE TWO" without any spaces or tabs in front of the note...

I'd like to eliminate possibilities that someone may use spaces, tabs or
both when writing the line item note.

I know I could come up with a simple solution, but I'd like to see if
someone may have a more efficient method, instead of having to compare each
character in the LINE considering that the list could contain hundreds or
items listed.

Thank you for your comments

Back to top
Rudy Tovar
Guest





Posted: Tue Dec 21, 2004 11:26 pm    Post subject: Re: Ah! the dilemma, and the posibilities... Reply with quote

Thanks Michael, but I don't think the number reference would be to
difficult, rather the contents after the number, which could include tabs or
spaces, as I illustrated...I just don't want to go through another loop to
get the note contents...

Here's what I have...(masi-get-reference) is stored in drawing, but could be
any file name.

(defun c:test (/ file ofile oline olist)

(setq file (masi-get-reference))

(if (findfile file)
(progn

(setq ofile (open file "r"))
(while (setq oline (read-line ofile))
(setq olist (cons oline olist)
nlist (cons (substr oline 1 5) nlist)
)

);end of while
(close ofile)
)
)

(list (reverse nlist)(reverse olist))
)



"Michael Puckett" <Sp@mYourself.Sucka> wrote in message
news:41c867cf$1_1@newsprd01...
Quote:
What about using vl-string-trim, vl-string-search etc. to suit ...

(vl-string-trim " */t" "***122 LINE ONE")

=> "122 LINE ONE"

(if
(setq pos
(vl-string-search
" "
(setq temp
(vl-string-trim
" */t"
"**122 LINE ONE"
)
)
)
)
(substr temp 1 pos)
)

=> "122"

Etc.

"Rudy Tovar" <Rudy@CadentityNoSpam.com> wrote in message
news:41c861bd$1_3@newsprd01...
Before I actually get started, perhaps someone has already done this...
it's
actually a no brainer, but like to see if anyone has come up with a
condensed version that's a bit more efficient...

OK...

First a text a file that contains...

****THIS COMMENT OR THAT****

**122 LINE ONE
**123 LINE TWO
**124 LINE THREE

********************************

Considering it may contain spaces and more comments, I'd like to be able
to
use vl-position to located number "122" in a list that I'll be creating
of a
file reference.

Also, eliminate any spaces, or tabs when returning the reference number
"LINE ITEM NOTE".

list> = ("****THIS COMMENT OR THAT****" "" "**122 LINE ONE"
....etc.....)

In the end I'd like to say (get-note "123" <list>) and all it returns is
"LINE TWO" without any spaces or tabs in front of the note...

I'd like to eliminate possibilities that someone may use spaces, tabs or
both when writing the line item note.

I know I could come up with a simple solution, but I'd like to see if
someone may have a more efficient method, instead of having to compare
each
character in the LINE considering that the list could contain hundreds or
items listed.

Thank you for your comments





Back to top
Rudy Tovar
Guest





Posted: Tue Dec 21, 2004 11:31 pm    Post subject: Re: Ah! the dilemma, and the posibilities... Reply with quote

Just so you know I could now use the vl-position to return the remaining
values, but would like to see if it could be condensed a bit more to strip
any spaces and or tabs.

The illustrated function returns 2 list, one that contains the first 5
charcters, and the second listing that returns anything remaining on that
line...



"Rudy Tovar" <Rudy@CadentityNoSpam.com> wrote in message
news:41c86a01$1_2@newsprd01...
Quote:
Thanks Michael, but I don't think the number reference would be to
difficult, rather the contents after the number, which could include tabs
or spaces, as I illustrated...I just don't want to go through another loop
to get the note contents...

Here's what I have...(masi-get-reference) is stored in drawing, but could
be any file name.

(defun c:test (/ file ofile oline olist)

(setq file (masi-get-reference))

(if (findfile file)
(progn

(setq ofile (open file "r"))
(while (setq oline (read-line ofile))
(setq olist (cons oline olist)
nlist (cons (substr oline 1 5) nlist)
)

);end of while
(close ofile)
)
)

(list (reverse nlist)(reverse olist))
)



"Michael Puckett" <Sp@mYourself.Sucka> wrote in message
news:41c867cf$1_1@newsprd01...
What about using vl-string-trim, vl-string-search etc. to suit ...

(vl-string-trim " */t" "***122 LINE ONE")

=> "122 LINE ONE"

(if
(setq pos
(vl-string-search
" "
(setq temp
(vl-string-trim
" */t"
"**122 LINE ONE"
)
)
)
)
(substr temp 1 pos)
)

=> "122"

Etc.

"Rudy Tovar" <Rudy@CadentityNoSpam.com> wrote in message
news:41c861bd$1_3@newsprd01...
Before I actually get started, perhaps someone has already done this...
it's
actually a no brainer, but like to see if anyone has come up with a
condensed version that's a bit more efficient...

OK...

First a text a file that contains...

****THIS COMMENT OR THAT****

**122 LINE ONE
**123 LINE TWO
**124 LINE THREE

********************************

Considering it may contain spaces and more comments, I'd like to be able
to
use vl-position to located number "122" in a list that I'll be creating
of a
file reference.

Also, eliminate any spaces, or tabs when returning the reference number
"LINE ITEM NOTE".

list> = ("****THIS COMMENT OR THAT****" "" "**122 LINE ONE"
....etc.....)

In the end I'd like to say (get-note "123" <list>) and all it returns is
"LINE TWO" without any spaces or tabs in front of the note...

I'd like to eliminate possibilities that someone may use spaces, tabs or
both when writing the line item note.

I know I could come up with a simple solution, but I'd like to see if
someone may have a more efficient method, instead of having to compare
each
character in the LINE considering that the list could contain hundreds
or
items listed.

Thank you for your comments





Back to top
Luis Esquivel
Guest





Posted: Tue Dec 21, 2004 11:49 pm    Post subject: Re: Ah! the dilemma, and the posibilities... Reply with quote

Hi Rudy,

How many times are you going to open/read the file? or is just going to be a
single call?

Quote:
(if (findfile file)
(progn

(setq ofile (open file "r"))
(while (setq oline (read-line ofile))
(setq olist (cons oline olist)
nlist (cons (substr oline 1 5) nlist)
)

);end of while
(close ofile)
Back to top
Rudy Tovar
Guest





Posted: Wed Dec 22, 2004 12:20 am    Post subject: Re: Ah! the dilemma, and the posibilities... Reply with quote

One call in the beginning, it wouldn't be efficient to call the file several
times.

I gather the listing first then actually compare to a list of possible
numbers.

Although I only mention one number, it could be a list of random numbers.

(list 122 123)
read file
return line for each number



"Luis Esquivel" <nospam@address.withheld> wrote in message
news:41c87038$1_2@newsprd01...
Quote:
Hi Rudy,

How many times are you going to open/read the file? or is just going to be
a
single call?

(if (findfile file)
(progn

(setq ofile (open file "r"))
(while (setq oline (read-line ofile))
(setq olist (cons oline olist)
nlist (cons (substr oline 1 5) nlist)
)

);end of while
(close ofile)

Back to top
Dick Coy
Guest





Posted: Wed Dec 22, 2004 5:29 pm    Post subject: Re: Ah! the dilemma, and the posibilities... Reply with quote

Can you store the text file in list format ie.
((1 . 1)(2 . "Solid Surface")(10 . "SS1")(20 . "Fossil")(30 . "Corian")(40 .
"1")(50 . "Tops and splash"))

((1 . 2)(2 . "Solid Surface")(10 . "SS2")(20 . "Pompeii Red")(30 .
"Corian")(40 . "1")(50 . "Lavatories"))

((1 . 3)(2 . "Solid Surface")(10 . "SS4")(20 . "Anthracite")(30 .
"Corian")(40 . "1")(50 . "Base"))

then search it like the acad database?



"Rudy Tovar" <Rudy@CadentityNoSpam.com> wrote in message
news:41c876be_2@newsprd01...
Quote:
One call in the beginning, it wouldn't be efficient to call the file
several
times.

I gather the listing first then actually compare to a list of possible
numbers.

Although I only mention one number, it could be a list of random numbers.

(list 122 123)
read file
return line for each number



"Luis Esquivel" <nospam@address.withheld> wrote in message
news:41c87038$1_2@newsprd01...
Hi Rudy,

How many times are you going to open/read the file? or is just going to
be
a
single call?

(if (findfile file)
(progn

(setq ofile (open file "r"))
(while (setq oline (read-line ofile))
(setq olist (cons oline olist)
nlist (cons (substr oline 1 5) nlist)
)

);end of while
(close ofile)



Back to top
BillZ
Guest





Posted: Wed Dec 22, 2004 7:00 pm    Post subject: Re: Ah! the dilemma, and the posibilities... Reply with quote

One possibility?

R2005:

(setq test '("****THIS COMMENT OR THAT****" " " "**122 LINE ONE" " " "" "**133 LINE FIVE" "" "" "**142 LINE SIX"))

Just to make the list longer:

(repeat 10 (setq test (append test test)))

(length test) = 9216

(defun get-note (itm) ;integer input
(setq itm (itoa itm)
searchitem (strcat "*" itm "*"))
(car (apply 'append (mapcar '(lambda (x)(if (wcmatch x searchitem)(list (vl-position x test)))) test)))
)
2

Command: timer
Elapsed time: 0.015000 seconds



Bill
Back to top
BillZ
Guest





Posted: Wed Dec 22, 2004 7:06 pm    Post subject: Re: Ah! the dilemma, and the posibilities... Reply with quote

Or:
If you just want the item returned.

Command:
Command: (car (apply 'append (mapcar '(lambda (x)(if (wcmatch x "*122*")(list
(vl-string-trim "*/t" x)))) test)))
"122 LINE ONE"

Command: (car (apply 'append (mapcar '(lambda (x)(if (wcmatch x "*133*")(list
(vl-string-trim "*/t" x)))) test)))
"133 LINE FIVE"

Bill
Back to top
BillZ
Guest





Posted: Wed Dec 22, 2004 7:44 pm    Post subject: Re: Ah! the dilemma, and the posibilities... Reply with quote

Or maybe you could just filter the list with this once and do you vl-position after that?

Bill
Back to top
Rudy Tovar
Guest





Posted: Thu Dec 23, 2004 12:11 am    Post subject: Re: Ah! the dilemma, and the posibilities... Reply with quote

Thanks Bill for your comments in insight...

"BillZ" <nospam@address.withheld> wrote in message
news:86186.1103726704543.JavaMail.jive@jiveforum1.autodesk.com...
Quote:
Or maybe you could just filter the list with this once and do you
vl-position after that?

Bill
Back to top
Rudy Tovar
Guest





Posted: Thu Dec 23, 2004 12:12 am    Post subject: Re: Ah! the dilemma, and the posibilities... Reply with quote

The file is external...

"Dick Coy" <iwiest@attglobal.net> wrote in message
news:41c96897$1_3@newsprd01...
Quote:
Can you store the text file in list format ie.
((1 . 1)(2 . "Solid Surface")(10 . "SS1")(20 . "Fossil")(30 . "Corian")(40
.
"1")(50 . "Tops and splash"))

((1 . 2)(2 . "Solid Surface")(10 . "SS2")(20 . "Pompeii Red")(30 .
"Corian")(40 . "1")(50 . "Lavatories"))

((1 . 3)(2 . "Solid Surface")(10 . "SS4")(20 . "Anthracite")(30 .
"Corian")(40 . "1")(50 . "Base"))

then search it like the acad database?



"Rudy Tovar" <Rudy@CadentityNoSpam.com> wrote in message
news:41c876be_2@newsprd01...
One call in the beginning, it wouldn't be efficient to call the file
several
times.

I gather the listing first then actually compare to a list of possible
numbers.

Although I only mention one number, it could be a list of random numbers.

(list 122 123)
read file
return line for each number



"Luis Esquivel" <nospam@address.withheld> wrote in message
news:41c87038$1_2@newsprd01...
Hi Rudy,

How many times are you going to open/read the file? or is just going to
be
a
single call?

(if (findfile file)
(progn

(setq ofile (open file "r"))
(while (setq oline (read-line ofile))
(setq olist (cons oline olist)
nlist (cons (substr oline 1 5) nlist)
)

);end of while
(close ofile)





Back to top
 
Post new topic   Reply to topic    CADForums.net Forum Index -> Customization All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Windows Server DSP VoIP Electronics New Topics
Powered by phpBB