Jump to content

Recommended Posts

Posted

Hi rlx,

Managed to run the program and get the dialog with calculations being done correctly. However If I change data manually they do not get updated. What I get over and over again is the calculations based on initial data. If the data are outside the limits the dialog vanishes. What can be the problem?. The lisp file is attached.

aloy.lspFetching info...

  • Replies 151
  • Created
  • Last Reply

Top Posters In This Topic

  • aloy

    72

  • rlx

    67

  • Lee Mac

    6

  • stevesfr

    3

Top Posters In This Topic

Posted Images

Posted
  aloy said:
Hi rlx,

Managed to run the program and get the dialog with calculations being done correctly. However If I change data manually they do not get updated. What I get over and over again is the calculations based on initial data. If the data are outside the limits the dialog vanishes. What can be the problem?. The lisp file is attached.

 

 

Without knowing what function pipeflow2 or (pipe) is doing , when you call an action_tile you do something with the value but you should also store it.

 

 

so : (action_tile "eb_pipesize" "(update_pipesize dia)") , which btw should be 'update_pipesize $value' , passes your value to update_pipesize but it doesn't keep it. One way could be to change your code slightly to (action_tile "eb_pipesize" "(update_pipesize (setq dia $value))")

 

 

And with every call to 'aloy_init_dialog' you (re)set dia , man , flo & slo. To prevent that you could use (if (= dia nil)(setq dia "450"))

 

 

btw , do you use the lisp editor in autocad? If you select pull down menu 'Debug' and then 'Break on error' you can inspect the point of error. The program pauses and then select pull down menu 'View' and then 'error' trace from where you can see what went wrong.

 

 

gr. Rlx

Posted

rlx,

see the dialog when data are withing the ranges. As long as they are within the ranges the results changes when you click or enter with different data. However the moment they are out side the dialog collapses. I give an example:

(defun update_pipesize (val)

(cond

((

(mapcar '(lambda (x) (set_tile x "invalid") eb_list1)))

((>= (atof val) 1500.0)

(mapcar '(lambda (x) (set_tile x "too large") eb_list1)))

(t

 

(pipe)

(set_tile "eb_depthofflow" gdx)

(set_tile "eb_centralangle" thita1)

(set_tile "eb_fullboreflow" gq2)

(set_tile "eb_fullborevel" gv1)

(set_tile "eb_radius" r1)

(set_tile "eb_wetted_peri" p1)

(set_tile "eb_hydra_rai" ar1)

(set_tile "eb_nn_full" rt)

(set_tile "eb_cross_sect" a1)

(set_tile "eb_pipe_full" pf)

(set_tile "eb_ave_velocity" gv)

(set_tile "eb_roughness" n1)

)))

Error checking says "too few arguments". What could that be?.

Capture1.JPG

Posted
  aloy said:
rlx,

see the dialog when data are withing the ranges. As long as they are within the ranges the results changes when you click or enter with different data. However the moment they are out side the dialog collapses. I give an example:

(defun update_pipesize (val)

(cond

((

(mapcar '(lambda (x) (set_tile x "invalid") eb_list1)))

((>= (atof val) 1500.0)

(mapcar '(lambda (x) (set_tile x "too large") eb_list1)))

(t

 

(pipe)

(set_tile "eb_depthofflow" gdx)

(set_tile "eb_centralangle" thita1)

(set_tile "eb_fullboreflow" gq2)

(set_tile "eb_fullborevel" gv1)

(set_tile "eb_radius" r1)

(set_tile "eb_wetted_peri" p1)

(set_tile "eb_hydra_rai" ar1)

(set_tile "eb_nn_full" rt)

(set_tile "eb_cross_sect" a1)

(set_tile "eb_pipe_full" pf)

(set_tile "eb_ave_velocity" gv)

(set_tile "eb_roughness" n1)

)))

Error checking says "too few arguments". What could that be?.

 

 

you missed a spot in your code

 

 

(defun update_pipesize (val)
 (cond
   ((<= (atof val) 0.0)
    [color=red](mapcar '(lambda (x) (set_tile x "invalid"))[/color] eb_list1))
   ((>= (atof val) 1500.0)
    [color=red](mapcar '(lambda (x) (set_tile x "too large"))[/color] eb_list1))
   (t
    (pipe)
    (set_tile "eb_depthofflow" gdx)
    (set_tile "eb_centralangle" thita1)
    (set_tile "eb_fullboreflow" gq2)
    (set_tile "eb_fullborevel" gv1)
    (set_tile "eb_radius" r1)
    (set_tile "eb_wetted_peri" p1)
    (set_tile "eb_hydra_rai" ar1)
    (set_tile "eb_nn_full" rt)
    (set_tile "eb_cross_sect" a1)
    (set_tile "eb_pipe_full" pf)
    (set_tile "eb_ave_velocity" gv)
    (set_tile "eb_roughness" n1)
   )
 )
)

But you're learning verry fast grasshopper :geek:

 

 

 

(mapcar '(lambda (x) (set_tile x "invalid")) eb_list1 )

Gr. Rlx

Posted

Yes, that is it. Now the colour and diagram. App will be ready. How can I reward you?.

Regards,

Aloy

Posted
  aloy said:
Yes, that is it. Now the colour and diagram. App will be ready. How can I reward you?.

Regards,

Aloy

 

 

You just did :-)

 

 

btw mapcar has it's uses , no question there , but in some cases it's just showing off ;-) You can also write the line as:

 

 

 (foreach tile-name eb_list (set_tile tile-name "invalid")) 

 

 

it has to do with speed and memory which could be important with large data sets , but for normal use I think it's just b.s. in terms of efficiency. But it's fun to do , to mapcar your way around , it's addictive for me and other persons (but I won't mention any names haha)

 

 

good luck

 

 

gr. Rlx

Posted

It was in '87 I first use mapcar, lambda on a problem which my self as a young engineer and an Asian Development Bank expert (an Indian) were trying to solve. He was using Basic language and I, Autolisp. There happened to be a book on AI in British council library in Colombo and that helped me to crack it before the expert. And it was really addictive. However it helped me to design few roads in an ASEAN country where I am working up to present time. Lisp truly is an interesting language, but I had forgotten most of it. I was inspired by a book on Waste Water Collection Systems by Bentley Systems on this code snippet, but it turned out to be very useful for my work here.

 

Aloy

Posted
  aloy said:
It was in '87 I first use mapcar, lambda on a problem which my self as a young engineer and an Asian Development Bank expert (an Indian) were trying to solve. He was using Basic language and I, Autolisp. There happened to be a book on AI in British council library in Colombo and that helped me to crack it before the expert. And it was really addictive. However it helped me to design few roads in an ASEAN country where I am working up to present time. Lisp truly is an interesting language, but I had forgotten most of it. I was inspired by a book on Waste Water Collection Systems by Bentley Systems on this code snippet, but it turned out to be very useful for my work here.

 

Aloy

 

 

Late 80's I started to work with autocad for the first time and it didn't take long before I started to learn lisp. But the use of mapcar and even VL- command's 'scared' me until a couple of years ago. When my former employer asked me if I could write an app to generate loops from an excel sheet I decided it was time to go to the next level and only since that time I started to get the feeling I was beginning to understand what I was doing (yeah slow learner). But guys like Lee or in the old days Tony Tanzillo blow me out of the water everytime by showing just how much there still is possible. I'm glad that where I work at this moment , as a simple drawing dragon , they also appriciate me for my abillity to uphold their vision of : don't work harder , work smarter.

 

 

gr. Rlx

Posted

Rlx,

One more question: How to prevent the user from entering a character instead of a number?. I tried to search but couldn't find an answer.

Aloy

Posted
  aloy said:
Rlx,

One more question: How to prevent the user from entering a character instead of a number?. I tried to search but couldn't find an answer.

Aloy

 

Hi Aloy,

 

You can use function 'numberp' or for a string something like

 

(defun isnum (n)(vl-every '(lambda (x)(if (wcmatch (chr x) "#,.,+,-") t nil))(vl-string->list n)))

 

other way is to see if all characters have ascii code between the range 48-57 but you have to account for . or , too.

 

Or test if each character is member number list etc , number of ways to tackle this.

 

but for me isnum will do : (if (isnum inp) (go for it) (reject input))

 

awel, i have to get up in 5 hours so i'm gonna hit the deck...

 

gr. Rlx

Posted

Hi Rlx,

(isnum val) works. However I need to study the definition. Thanks.

Hope you had a good night's sleep.

 

Aloy

Posted (edited)
  aloy said:
Hi Rlx,

(isnum val) works. However I need to study the definition. Thanks.

Hope you had a good night's sleep.

 

Aloy

 

 

Hi Aloy,

 

 

Didn't want to wake the wife so I slept on the sofa but the bed would have been better pfff.

 

 

isnum first converts all characters in a string to a list of ascii numbers and then test every character if its a numer , a point , a plus or a minus. If all (vl-every) characters pass this test then function delivers T otherwise nil.

 

 

gr. Rlx

 

 

btw other way to code could be

 

 

(defun isnum (n)
 (vl-every '(lambda (x)
                    (if (member x '(43 45 46 48 49 50 51 52 53 54 55 56 57)) t nil))
                  (vl-string->list n)
 )
)

works too of cource but the other version is more readable , matter of taste.

Edited by rlx
Posted

Rlx,

I now understand the isnum function. Thanks for that. I want to include a picture something similar to shown in the attachment. The limit to the level of water inside will be removed and the n/nfull equation will be replaced with a fourth degree polynomial. Is it possible to include it, perhaps a scaled down version?.

Aloy

Capture2.jpg

Posted
  aloy said:
Rlx,

I now understand the isnum function. Thanks for that. I want to include a picture something similar to shown in the attachment. The limit to the level of water inside will be removed and the n/nfull equation will be replaced with a fourth degree polynomial. Is it possible to include it, perhaps a scaled down version?.

Aloy

 

 

 

wow long time i did some math ;-)

 

 

To include a picture , mmm , my first choise would be to make a slide from your picture (or you first draw it in autocad and then make a slide) and add an image_tile to your dialog to show it. The other , more professional option would be to use vectors to draw the lines to the image_tile. I know Lee Mac has some pretty impressive examples on his site. I do sometimes use them , last time was in my RlxIso routine to highlite a selected 'cell'.

 

 

Anywayz , I'm not sure if lisp has the capabilities to directly show a tif or jpg. But you can use startapp command to lauch a viewer to show your picture.

 

 

gr. Rlx

 

 

btw , you do mean a static picture / slide because if it has to be dynamic you have no choise but use 'vector_image'.

Posted

Sorry to bother you with all these maths, but it is just to explain what comes as a picture. There is no zooming, hence no need of vectors I suppose. I think this is a static picture about the size of the present dialog itself and large enough to be in the autocad screen.

Posted

Just a quicky because i'm late already (for dinner)

 

 

(defun c:aloyi ( / dcl-id)
 (setq dcl-id (load_dialog "Aloyi.DCL"))
 (new_dialog "itest" dcl-id)
 (start_image "i_tst")
 (slide_image 0 0 (dimx_tile "i_tst")(dimy_tile "i_tst") "Aloyi2.sld")
 (end_image)
 (action_tile "i_tst" "(done_dialog)")
 (start_dialog)
 (unload_dialog dcl-id)
 (princ)
)

 

 

itest : dialog {
label = "Aloy - image test";
: image_button { color = -2; key = "i_tst"; width = 60; aspect_ratio = 1.5;
                 allow_accept=true; is_default=true;}}

 

 

made i slide from your picture but it was to large to upload ...

 

 

awel, have to hurry home now or there will be trouble with the wife ;-)

 

 

gr. R

Aloyi2.sldFetching info...

Posted

Rlx,

downloaded the slide but cannot open. Will revise the picture and have it in two parts to have them on either or on the same side of present dialog.

I will be engaged on writing a report for the next one week and get back. In the meantime need to change 'isnum' to reject multiple occurrence of point (.) in the input string. The + and - also to be rejected in this case.

 

With Best Regards

Aloy

Posted
  aloy said:
Rlx,

downloaded the slide but cannot open. Will revise the picture and have it in two parts to have them on either or on the same side of present dialog.

I will be engaged on writing a report for the next one week and get back. In the meantime need to change 'isnum' to reject multiple occurrence of point (.) in the input string. The + and - also to be rejected in this case.

 

With Best Regards

Aloy

 

 

Hi Aloy , good luck with your report. If I can find the time i'll have a look at the dialog.

 

 

to check for duplicates , try something like this

 

 

(defun tfd ( / lst duplist dup)
 (setq lst '(1 2 3 4 5 1 2 6 7 8 9) duplist '(1 2 3))
 (mapcar '(lambda (x)
     (if (and (member x lst)
       (cdr (member x lst))
       (member x (cdr (member x lst))))
       (setq dup t))) duplist)
 dup
)

 

 

you then make the duplist and test list parameters where the duplist are the ascii's for . , - and + and the test list the list of ascii's from your editbox string. Sure there will be better code around but I rather have something that works and is easy to comprehend and easy to maintain than code that looks good and one year later you think , wtf... how did i do that ;-)

 

 

Gr. Rlx

Posted

Hi Rlx,

I thought vl-string-search would be a better idea, but couldn't find anything useful for my work. Does a list represent a string?.

Did not try your code yet.

Regards,

Aloy

Posted
  aloy said:
Hi Rlx,

I thought vl-string-search would be a better idea, but couldn't find anything useful for my work. Does a list represent a string?.

Did not try your code yet.

Regards,

Aloy

 

 

Sure , no problem , actually maybe even better...

 

 

(defun sfd (str);scan for duplicates
 (vl-some '(lambda (x)
      (if (and (vl-string-search x str)(vl-string-search x str (1+ (vl-string-search x str)))) t))
   '("+" "-" ".")))

(defun c:t1 ( / test)
 (setq test (list "123..456" "123+456" "1+1+2" "0.00.1"))
 (mapcar '(lambda (txt)
     (if (sfd txt)
       (princ (strcat "\n" txt " contains duplicates"))
       (princ (strcat "\n" txt " does not contains duplicates"))))
  test
 )
 (princ)
)


gr. Rlx

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...