+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Forum Newbie
    Discipline
    Surveying
    Using
    AutoCAD 2018
    Join Date
    Mar 2018
    Posts
    7

    Default First steps in AutoLISP - too few / too many arguments

    Registered forum members do not see this ad.

    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?

    Code:
    (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.

  2. #2
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,489

    Default

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

  3. #3
    Super Member
    Using
    not applicable
    Join Date
    Jun 2016
    Posts
    699

    Default

    Actually there are more than 5 issues with the code.
    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
    BricsCAD 18

  4. #4
    Forum Newbie
    Discipline
    Surveying
    Using
    AutoCAD 2018
    Join Date
    Mar 2018
    Posts
    7

    Default

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

    Quote Originally Posted by Grrr View Post
    Code:
    (defun c:leveltext1103 ( / 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/tut...e-function.php
    Is the advice on afralisp a bit oversimplified or am I missing something?
    Quote Originally Posted by Roy_043 View Post
    Actually there are more than 5 issues with the code.
    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
    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?

  5. #5
    Quantum Mechanic BIGAL's Avatar
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    10,792

    Default

    Re testing globally

    Code:
    ;(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.
    A man who never made mistakes never made anything

  6. #6
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,489

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by pateksan View Post
    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/tut...e-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 ( <list of variables that are being localised for this function> )

    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.

Similar Threads

  1. 4 steps
    By sergiu_ciuhnenco in forum AutoLISP, Visual LISP & DCL
    Replies: 7
    Last Post: 10th Jan 2015, 01:54 pm
  2. AutoCad commands and their arguments in AutoLisp
    By teknomatika in forum AutoLISP, Visual LISP & DCL
    Replies: 7
    Last Post: 20th Nov 2012, 06:02 am
  3. How to define a function in AutoLISP with arbitrary arguments
    By Ahankhah in forum AutoLISP, Visual LISP & DCL
    Replies: 5
    Last Post: 24th Apr 2011, 06:54 pm
  4. 3D drawing of steps
    By Polly64 in forum AutoCAD 3D Modelling & Rendering
    Replies: 11
    Last Post: 29th Oct 2009, 12:21 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts