Author Topic: How to call a function ?  (Read 302 times)

0 Members and 1 Guest are viewing this topic.

vincent.r

  • Newt
  • Posts: 42
How to call a function ?
« on: September 18, 2019, 06:01:52 AM »
Prepared function to arrange blocks in sequence i.e. closest from 0,0,0 (closest first longest last). calling it from main routine but it gives an error: too many arguments.
Independently it works as expectation. How can I call it from some other function?

Code - Auto/Visual Lisp: [Select]
  1. (defun pl:closestsort ( / i B1 Enamelst dist combolst distlst distsortlst dist1 distcompare counter )
  2.   (setq i (sslength IOC))
  3.   (while (/= i 0) ;repeat process for all blocks of selection set ;;;;;;;;;;;;;;;;;;REPEAT 1
  4. (setq B1 (ssname ioc (setq i (1- i)))) ;get first entity
  5. (setq Enamelst (cons B1 Enamelst))
  6. (setq dist (distance '(0 0 0) (cdr (assoc 10 (entget B1))))) ;get distance from 000
  7. (setq Enamelst (cons dist Enamelst))
  8.     (setq combolst (cons Enamelst combolst))
  9.     (setq Enamelst nil)
  10.     )
  11. (setq distlst (mapcar '(lambda (x) (car x)) combolst))
  12. (setq distsortlst (vl-sort distlst '<))
  13. (while (/= distsortlst nil)
  14.   (setq dist1 (car distsortlst))
  15.         (repeat (setq counter (length combolst))
  16.         (setq distcompare (car (nth (setq counter (1- counter)) combolst)))
  17.         (if (= dist1 distcompare) (progn (setq distsorted (cons (cadr (nth counter combolst)) distsorted))))
  18.         )
  19.   (setq distsortlst (cdr distsortlst))
  20. )
  21. (setq distsorted (reverse distsorted))
  22. )
  23. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;return variable is - distsorted
  24.  
  25. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;(setq Enamelst nil)(setq closest nil)
  26. (setq IOC (ssget "_x" (list (cons 0 "INSERT") (cons 2 "RackSlot")))) ;Select IO Cards
  27. (pl:closestsort IOC)


Thanks in advance


EDIT (John): Added code tags.
« Last Edit: September 18, 2019, 07:55:17 AM by John Kaul (Se7en) »

ribarm

  • Water Moccasin
  • Posts: 2167
  • Marko Ribar, architect
Re: How to call a function ?
« Reply #1 on: September 18, 2019, 06:14:23 AM »
(defun pl:closestsort ( IOC / i B1 Enamelst dist combolst distlst distsortlst dist1 distcompare counter )
...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

vincent.r

  • Newt
  • Posts: 42
Re: How to call a function ?
« Reply #2 on: September 18, 2019, 06:21:44 AM »
(defun pl:closestsort ( IOC / i B1 Enamelst dist combolst distlst distsortlst dist1 distcompare counter )
...

Got it ! Thanks for you kind co-operation.

BIGAL

  • Bull Frog
  • Posts: 352
  • 30 + years of using Autocad
Re: How to call a function ?
« Reply #3 on: September 22, 2019, 01:40:15 AM »
It is possible to do a sort way deeper than 1 item so you could sort on X & Y for instance
A man who never made a mistake never made anything