Jump to content

MINOR edits to a lisp? please help


dnovember99

Recommended Posts

If you insert a block as above with 8 attributes you need to provide all 8 attribute values, you could use say "-" for values that you want to change later.

 

Glad you increased to 8 lines I will though look harder for the 1 lisp that does as many lines as you need its way shorter code.

 

Ps may be call getvals1-8.lsp.

Link to comment
Share on other sites

  • Replies 64
  • Created
  • Last Reply

Top Posters In This Topic

  • dnovember99

    30

  • BIGAL

    25

  • Roy_043

    4

  • Grrr

    2

Top Posters In This Topic

Posted Images

hey all,

 

 

so I am new to getting into writing lisp routines. I have done some searching around and I found it once, yet like a smart guy I didn't save this information. but then you have a lisp that you are looking at (not one that I wrote) and you are seeing the following:

 

 

ah:getval5 "Line 1" 5 4 "0.9" "Line 2" 8 7 "wow" "Line 3" 6 4 "123" "Line 4" 6 4 "456" "Line 5" 6 4 "789")

 

 

(sorry I tried to do the code pasting the correct way but it wasn't allowing it.)

 

 

what are the numbers after you see "line 1" "line 2" ETC. see attached screen shot.

 

 

also can someone tell me where I can get this information? I know that it is out in the google world but I for the life of me can think of the term to use nor where to start looking at. can someone flash a light on this and show me the direction?

 

 

thank you all

2017-12-15 23_20_07-C__Users_Owner_Desktop_autocad lisp routine work_WORKING LISP ROUTINES_GETVA.jpg

Link to comment
Share on other sites

This looks like a note in someones lisp, wich explains how the function is supposed to be called.

Since the note above the line says '5 line Dcl'. I think this function calles a dcl with 5 textlines, and the numbers have simething to do with each line...

If you want to know what there for, we need the code of the ah:getvar5 function..

Link to comment
Share on other sites

You should have asked this question in your other post, that way it would make sense to others.

 

http://www.cadtutor.net/forum/showthread.php?102343-MINOR-edits-to-a-lisp-please-help

 

Admin may want to merge.

 

Ok now the explanation, 1st up its important that this the code is a Library routine and has been designed to be used with any lisp rather than an individual hard coded DCL.

 

When you make a dialouge DCL one of the variables is in the size of a input box.

 

The lisp has a defun that requires some information to be passed to it

(defun AH:getval1 (title width limit def1 / fo fname)

 

AH:getval1 is name of defun

title is just that the Title that appears at the top of the DCL

width is the number of characters displayed for the input box

limit is the actual number of allowable characters that can be entered

def1 is a default value entered into the DCL.

 

(ah:getval1 "Line 1" 5 4 "-") this is a single dcl variable box

 

ddgetval : dialog {
: column {
: edit_box {
   key = "key1";
label = "Line 1";
    edit_width = 5;
    edit_limit = 4;
  is_enabled = true;
 }
spacer_1 ;
}
ok_only;}

 

If you want to see the code remove the line (vl-file-delete fname) this stops the file deleting and it is written to where Autocad has the temporary directory set, you can change this using CONFIG and Files support. Mine is C:\acadtemp. It is not obvious name but you should be able to work it out by the date & time.

 

This is the code of the 5 input dcl using

(ah:getval5 "Line 1" 5 4 "0.9" "Line 2" 8 7 "wow" "Line 3" 6 4 "123" "Line 4" 6 4 "456" "Line 5" 6 4 "789")
(defun AH:getval5 (title1 width1 limit1 def1 title2 width2 limit2 def2 title3 width3 limit3 def3  title4 width4 limit4 def4  title5 width5 limit5 def5 / fo fname)

 

File written out.

ddgetval5 : dialog {
: column {
: edit_box {
   key = "key1";
label = "Line 1";
    edit_width = 5;
    edit_limit = 4;
  is_enabled = true ;
   }
spacer_1 ;
: edit_box {
   key = "key2";
label = "Line 2";
    edit_width = 8;
    edit_limit = 7;
  is_enabled = true ;
   }
spacer_1 ;
: edit_box {
   key = "key3";
label = "Line 3";
    edit_width = 6;
    edit_limit = 4;
  is_enabled = true ;
   }
spacer_1 ;
: edit_box {
   key = "key4";
label = "Line 4";
    edit_width = 6;
    edit_limit = 4;
  is_enabled = true ;
   }
spacer_1 ;
: edit_box {
   key = "key5";
label = "Line 5";
    edit_width = 6;
    edit_limit = 4;
  is_enabled = true ;
   }
   }
spacer_1 ;
ok_only;}

 

If you look into the help there should be tutorials about writing DCL I am lucky and have the old books for reference. Others I am sure will provide some tutorial links.

Edited by BIGAL
Link to comment
Share on other sites

You should have asked this question in your other post, that way it would make sense to others.

 

http://www.cadtutor.net/forum/showthread.php?102343-MINOR-edits-to-a-lisp-please-help

 

Admin may want to merge.

 

Ok now the explanation, 1st up its important that this the code is a Library routine and has been designed to be used with any lisp rather than an individual hard coded DCL.

 

When you make a dialouge DCL one of the variables is in the size of a input box.

 

The lisp has a defun that requires some information to be passed to it

(defun AH:getval1 (title width limit def1 / fo fname)

 

AH:getval1 is name of defun

title is just that the Title that appears at the top of the DCL

width is the number of characters displayed for the input box

limit is the actual number of allowable characters that can be entered

def1 is a default value entered into the DCL.

 

(ah:getval1 "Line 1" 5 4 "-") this is a single dcl variable box

 

ddgetval : dialog {
: column {
: edit_box {
   key = "key1";
label = "Line 1";
    edit_width = 5;
    edit_limit = 4;
  is_enabled = true;
 }
spacer_1 ;
}
ok_only;}

If you want to see the code remove the line (vl-file-delete fname) this stops the file deleting and it is written to where Autocad has the temporary directory set, you can change this using CONFIG and Files support. Mine is C:\acadtemp. It is not obvious name but you should be able to work it out by the date & time.

 

This is the code of the 5 input dcl using

(ah:getval5 "Line 1" 5 4 "0.9" "Line 2" 8 7 "wow" "Line 3" 6 4 "123" "Line 4" 6 4 "456" "Line 5" 6 4 "789")
(defun AH:getval5 (title1 width1 limit1 def1 title2 width2 limit2 def2 title3 width3 limit3 def3  title4 width4 limit4 def4  title5 width5 limit5 def5 / fo fname)

File written out.

ddgetval5 : dialog {
: column {
: edit_box {
   key = "key1";
label = "Line 1";
    edit_width = 5;
    edit_limit = 4;
  is_enabled = true ;
   }
spacer_1 ;
: edit_box {
   key = "key2";
label = "Line 2";
    edit_width = 8;
    edit_limit = 7;
  is_enabled = true ;
   }
spacer_1 ;
: edit_box {
   key = "key3";
label = "Line 3";
    edit_width = 6;
    edit_limit = 4;
  is_enabled = true ;
   }
spacer_1 ;
: edit_box {
   key = "key4";
label = "Line 4";
    edit_width = 6;
    edit_limit = 4;
  is_enabled = true ;
   }
spacer_1 ;
: edit_box {
   key = "key5";
label = "Line 5";
    edit_width = 6;
    edit_limit = 4;
  is_enabled = true ;
   }
   }
spacer_1 ;
ok_only;}

If you look into the help there should be tutorials about writing DCL I am lucky and have the old books for reference. Others I am sure will provide some tutorial links.

 

So with all this being said, the 5 4 in (ah:getval5 "line 1" 5 4 0.9) is that referring to line 5 and line 4 within the dcl string? And then the numbers between " " is the size and or what is to be out/calculated into the line/box?

 

Am I understanding that correctly?

Link to comment
Share on other sites

Maybe a slightly different formatting of the inputs would help you understand BIGAL's function:

 

(apply 'AH:getval5
 (apply 'append
   '( ; (Title Width Limit default)
     ("Line 1" 5 4 "0.9")
     ("Line 2" 8 7 "wow")
     ("Line 3" 6 4 "123")
     ("Line 4" 6 4 "456")
     ("Line 5" 6 4 "789")
   )    
 )
)  

Link to comment
Share on other sites

Maybe a slightly different formatting of the inputs would help you understand BIGAL's function:

 

(apply 'AH:getval5
 (apply 'append
   '( ; (Title Width Limit default)
     ("Line 1" 5 4 "0.9")
     ("Line 2" 8 7 "wow")
     ("Line 3" 6 4 "123")
     ("Line 4" 6 4 "456")
     ("Line 5" 6 4 "789")
   )    
 )
)  

 

I guess 2hat I am really wanting to know what the numbers (5 4 8 7 6 4) are associated with? What are they refering to?

 

Because unless you know this then you can write is sideways, it will still just be random numbers.

Link to comment
Share on other sites

I guess 2hat I am really wanting to know what the numbers (5 4 8 7 6 4) are associated with? What are they refering to?

 

Because unless you know this then you can write is sideways, it will still just be random numbers.

 

To the width and the edit_limit attributes of each edit_box tile, although you have to familiar enough with DCL to understand.

Link to comment
Share on other sites

bigal

 

so here are some of the last modifications that i made and i have to super close i think. but then again i could be totally wrong. i took what you said about auto filling all the attributes and took them away.

 

so i am running into an error code still and i see where is it telling me that the issue is but not sure how to correct it.

 

error:Command: (LOAD "I:/WORKING LISP ROUTINES/slope test2.lsp") too few arguments in SETQ: (SETQ PERC (ATOF VAL4) (SETQ FMTVAL (RTOS X 2 2)))

 

here is my current mess that i have made.

 

; simple example of filling in a block attributes with calcs
; by Alan H Dec 2017

(defun c:pipe-calc ( / len ans div slabd inv safety tot totslope)

(if (not ah:getval8) (load "getvals1-8"))

(ah:getval8 "Enter desired slope 1/x 4 8 16" 5 4 "4"  
"Enter Finished FLR Elev. " 5 4  "100" 
"Enter length " 5 4 "50" 
"Fittings Factor " 5 4 "25" 
"Enter inv " 5 4 "24" 
"Enter slab depth" 5 4 "4" 
"Enter safety " 5 4 "6" "")

(setq div (/ 1.0 (atof val1)))
(setq flr (atof val2))
(setq len (atof val3))
(setq perc (atof val4)
(setq fmtval (rtos x 2 2)))
(setq inv (atof val5))
(setq th (atof val6))
(setq safety (atof val7))


(setq totslope (* (* len) perc) div ))
(setq tot (+ (+ (+ totslope inv) safety) slabd))

;(alert (strcat "Value is " (rtos div 2 2)  "\nFinished Flr Elev is " (rtos inv 2 2) "\nLength is " (rtos inv 2 2) "\nFittings factor is " (rtos len 2 2) (strcat "Val% " )  "\nInvert is " (rtos inv 2 2) "\nSlab depth is " (rtos slabd 2 2) "\nSafety is " (rtos slabd 2 2) "\nTotal overall is " (rtos slabd 4 2) "\nAbsolute feet is " (rtos slabd 2 2)))))))

(command "-insert" "PIPE-CALC" (getpoint) 1 1 0  val2 val3 val4 val5 val6 val7 val8 (strcat "1/x 4 8 16" val1)  (rtos TOT 4 2)) (rtos (cvunit a "ft inches" "decimal"))

)
(c:pipe-calc)

 

 

i also attached the block that i modified. dont mind the side notes that is just me adding some notes that i will need to have int he end.

 

also is the last part of this "cvunit" am i using this correctly?

 

thank you

new block (1).dwg

Link to comment
Share on other sites

This may be usefull http://help.autodesk.com/view/OARX/2018/CHS/?guid=GUID-265AADB3-FB89-4D34-AA9D-6ADF70FF7D4B scroll down to Dialouge.

 

To clarify (ah:getval5 "Line 1" 5 4 "0.9" "Line 2" 28 27 "wow"...... would mean the 1st box is 5 characters wide accepting 4 characters as input, the second box is 28 characters wide accepting 27 characters.

 

Will check code soon.

 

Found obvious mistake when you insert your block has 8 attributes but your supplying 10 answers in the code.

Screen Shot 12-19-17 at 01.11 PM.PNG

Link to comment
Share on other sites

  • 2 weeks later...

ok so i havent been able to look at this for about a week due to cad not working right on my home computer.

 

but looking at this again it seems that i have made some changes that just are not working at all. so i started back with square 1 on the lisp that you wrote in the beginning.

 

; simple example of filling in a block attributes with calcs
; by Alan H Dec 2017

(defun c:pipe-calc ( / len ans div slabd inv safety tot totslope)

(if (not ah:getval5) (load "getvals1-5"))

(ah:getval5 "Enter desired slope 1/x 4 8 16" 5 4  "4" "Enter length " 5 4  "50" "Enter inv " 5 4 "24" "Enter slab depth" 5 4 "4" "Enter safety " 5 4 "6")

(setq div (/ 1.0 (atof val1)))
(setq len (atof val2))
(setq inv (atof val3))
(setq slabd (atof val4))
(setq safety (atof val5))

(setq totslope (* len div))
(setq tot (+ (+ (+ totslope inv) safety) slabd))

;(alert (strcat "Value is " (rtos div 2 2)  "\nLength is " (rtos len 2 2) "\nTotal slope is " (rtos totslope 2 2) "\nInvert is " (rtos inv 2 2) "\nSlab depth is " (rtos slabd 2 2) "\n\nTotal overall is " (rtos tot 4 2)))))))

(command "-insert" "PIPE-CALC" (getpoint) 1 1 0  val2 val3 val4 val5  (strcat "1/" val1)  (rtos TOT 4 2))

)
(c:pipe-calc)

 

with this i wanted to see if maybe i could understand this a little better. i want to be able to add a finish floor elevation, total length, fittings factor(this would be 25%, as we have to multiply the total length by 25% to get the true total length), slab thickness, safety factor and have this give me an overall depth. in feet and inches. last thing that i want to be able to have is to take the total O/ALL and convert this to absolute feet (engineering feet and inches example: 91.25 feet below finished floor)

 

sorry for the example but i want to make sure that i am explaining this correctly so i am not leaving anything out.

 

i have taken the block that i updated/modified and removed all the notes that i had on there. just to simplify it and make it a little less messy. for now i can add to this later.

 

sorry if i am sounding like a dumb**** i really am trying to learn what i can with this to understand it better.

 

thank you again for all your help.

invert block with no notes.dwg

Link to comment
Share on other sites

Ok block has 8 entries

 

Need to use a Getval6 even if value is is always the same for that odd occasion.

 

I would change the title "Enter fittings factor %" then use 25 as defualt and do a (atof val5)/100.0

 

ok need to look up RTOS function it will do automatically the feet v's decimal feet. (rtos x 3 0) v's (rtos x 4 2) v's (Rtos x 2 2)

Link to comment
Share on other sites

Ok block has 8 entries

 

Need to use a Getval6 even if value is is always the same for that odd occasion.

 

I would change the title "Enter fittings factor %" then use 25 as defualt and do a (atof val5)/100.0

 

ok need to look up RTOS function it will do automatically the feet v's decimal feet. (rtos x 3 0) v's (rtos x 4 2) v's (Rtos x 2 2)

 

ok so i decided to do a little more reading into lisp and from what i found out this is what i was able to come up with. however i am still running into an error of

 

"Error: malformed list on input" and i am not sure where this is at.

 

; simple example of filling in a block attributes with calcs
; by Alan H Dec 2017

(defun c:pipe-calc ( / len ans div slabd inv safety tot totslope)

(if (not ah:getval8) (load "getvals1-8"))

(ah:getval1-8 "Enter desired slope 1/x 4 8 16" 5 4  "4" "Enter Finished FLR Elev. " 5 4  "100" "Enter length " 5 4 "50"  "Enter Fittings Factor  %" 5 4 "25" "Enter Starting inv " 5 4 "24" "Enter slab depth" 5 4 "4" "Enter safety " 5 4 "6" )

(setq div (/ 1.0 (atof val1)))
(setq flr (atof val2))
(setq len (atof val3))
(setq perc (atof val4))
(setq inv (atof val5))
(setq slabd (atof val6))
(setq safety (atof val7))
(setq fitting (atof val8)/100.0)

(setq totlen (* len prec))
(let ((* len perc)) ; this should return the value of total length multiplied by 25%
(setq totslope (* totlen  div))
(setq tot (+ (+ (+ totslope inv) safety) slabd))
(let ((* totlen  div)) (+ (+ (+ totslope inv) safety) slabd)) ;this should return the value of the total slope at the end of your piping.
(distof abso (substr flr totslope)) ; this should return a value in decimal format for the finished floor elevation - total overall slope. example would be 5' 5-1/2" - 100' = 94.542

;(alert (strcat "Value is " (rtos div 2 2)  "\nLength is " (rtos len 2 2) "\nTotal slope is " (rtos totslope 2 2) "\nInvert is " (rtos inv 2 2) "\nSlab depth is " (rtos slabd 2 2)  "\nFittings factor is " (rtos fitf 2 2) "\nTotal overall is " (rtos tot 4 2)  "\nAbsolute feet is " (rtos tot 2 2)))))))

(command "-insert" "PIPE-CALC" (getpoint) 1 1 0  val2 val3 val4 val5 val6 val7 val8  (strcat "1/" val1) (strcat val6 "%")  (rtos TOT 4 2)  (rtos ABSO 2 2))

)
(c:pipe-calc)

Link to comment
Share on other sites

There is a closing parenthesis missing on line 20. That is the first line where you use 'let'. Note that 'let' is not a built-in function in Autolisp. And I think you have misunderstood its purpose and its syntax.

Link to comment
Share on other sites

There is a closing parenthesis missing on line 20. That is the first line where you use 'let'. Note that 'let' is not a built-in function in Autolisp. And I think you have misunderstood its purpose and its syntax.

 

yes it does sound like i am not understanding it at all. my oh my this stuff is very complex for someone just starting out. but with all the changes that have happened in this post i figured i would add back in the math that i am looking to achieve.

 

so here is the values that i am using (just as an example) along with the long math and conversion math that we use (or like me i use google to get the math done for me.)

 

do you think that it would be easier to have the conversion part of it be a secondary lisp?

2017-12-29 09_34_11-Autodesk AutoCAD 2016 - [J__Phoenix_Programs_Sprouts_1750004557 Sprouts Farm.jpg

Link to comment
Share on other sites

The best help I can give you now is this:

 

It seems you have enrolled in the Copy-Paste School of Lisp Programming.

I advise you to leave that 'institution' as soon as possible. ;)

Link to comment
Share on other sites

Lisp is like a HP calculator polish notation tell what math 1st then supply the 2 aruguments / x y divide x by y

 

You need to look at your code it bit closer count the brackets on each line make sure they balance open = close remember though a IF will say have an extra at start but an extra at end.

 

Amost forgot watch out for typos prec v's perc in your code.

 

(setq div (/ 1.0 (atof val1)))
(setq flr (atof val2))
(setq len (atof val3))
(setq perc (atof val4))
(setq inv (atof val5))
(setq slabd (atof val6))
(setq safety (atof val7))
(setq fitting (/ (atof val8) 100.0)

(setq totslope (* len div))
(setq tot (+ (+ (+ totslope inv) safety) slabd))

Link to comment
Share on other sites

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...