Jump to content

First steps in AutoLISP - too few / too many arguments


pateksan

Recommended Posts

Hello

 

My first post here, so I will start with a brief introduction. I'm an engineering surveyor working in BricsCAD 18 (it's not listed as an option in this forum's registration form), most of my work is editing/tidying drawings exported from other software. I also do a fair bit of data manipulation in spreadsheets, and LISP is the next thing I want to get into.

 

Unfortunately I have very limited time for troubleshooting. I wrote my first script today and guess what - too few / too many arguments. Can anyone cast their eye please?

 

(defun c:leveltext1103 (datum levpoint ydatum ypoint levdistance)
(setq datum (getpoint "\nDatum line:"))
(setq point (getpoint "\nSurvey point:"))

(setq ydatum (cadr (datum)))
(setq ypoint (cadr (levpoint)))

(setq levdistance 
(rtos (* 2 (- point datum) 2 2))
);setq
(command "text" levpoint "0.15" "0" levdistance "")
);defun

The code is intended to produce a piece of text based on a scaled measurement of the y distance between two points on paperspace. Naturally this is just a dimension but I will later need to apply offsets etc to the calculation. I tried a few changes already and still get the error. I hope this is enough information for someone to resolve. Thanks in advance.

Link to comment
Share on other sites

Actually there are more than 5 issues with the code.

(defun c:leveltext1103 ( / datum levpoint ydatum ypoint levdistance)
 (setq datum (getpoint "\nDatum line:"))
 (setq levpoint (getpoint "\nSurvey point:"))

 (setq ydatum (cadr datum))
 (setq ypoint (cadr levpoint))

 (setq levdistance 
   (rtos (* 2 (- ypoint ydatum)) 2 2)
 ) ;setq
 (command "_.text" "_non" levpoint "0.15" "0" levdistance)
 (princ)
) ;defun

Link to comment
Share on other sites

Thank you both for your rapid responses, that's great.

 

(defun c:leveltext1103 ( [b][color="red"]/[/color][/b] datum levpoint ydatum ypoint levdistance)

I was going by this:

It's a good idea to leave all variables as global whilst you are writing your

program so that you can check their values during debugging.

taken from the bottom of http://www.afralisp.net/autolisp/tutorials/the-define-function.php

Is the advice on afralisp a bit oversimplified or am I missing something?

Actually there are more than 5 issues with the code.

(defun c:leveltext1103 ( / datum levpoint ydatum ypoint levdistance)
 (setq datum (getpoint "\nDatum line:"))
 (setq [color="red"]lev[/color]point (getpoint "\nSurvey point:"))

 (setq ydatum (cadr datum))
 (setq ypoint (cadr levpoint))

 (setq levdistance 
   (rtos (* 2 (- [color="red"]y[/color]point [color="red"]y[/color]datum)) 2 2)
 ) ;setq
 (command "[color="red"]_.text[/color]" "[color="red"]_non[/color]" levpoint "0.15" "0" levdistance)
 ([color="red"]princ[/color])
) ;defun

I've put red colour on any of your edits which I noticed. Coding is not forgiving, is it... Your code works! Did you make any more edits which I am missing?

Link to comment
Share on other sites

Re testing globally

 

;(defun c:leveltext1103 ( / datum levpoint ydatum ypoint levdistance)
(defun c:leveltext1103 ( )

 

Sometimes though doing with global you will need to type say (setq datum nil) on command line to clear a variable.

Link to comment
Share on other sites

Thank you both for your rapid responses, that's great.

 

 

I was going by this:

It's a good idea to leave all variables as global whilst you are writing your

program so that you can check their values during debugging.

 

taken from the bottom of http://www.afralisp.net/autolisp/tutorials/the-define-function.php

Is the advice on afralisp a bit oversimplified or am I missing something?

 

Global variables.. well I hope you understand:

 

(defun c:something ( )

 

This means you didn't used global variables either,

Main issue with your code is that you excluded '/' so your function became this structure:

 

(defun example ( ex1 ex2 ex3 )

 

where to call it you must provide arguments to it, like:

(example "string" 1 (list "this" "is" "a list"))

 

so if it was:

(defun example ( / ex1 ex2 ex3 )

the call would be just:

(example)

because now 'ex ex2 and ex3' are variables that the example functions uses inside.

 

Yeah afralisp's examples are oversimplified and thats great for someone new to learn easily LISP.

I'd suggest checking Lee Mac's tutorials, Localising Variables is related to your problem.

Tho each tutorial requires very careful reading and re-reading it n-times, but you won't regret it.

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