Author Topic: Call Funtion in Function  (Read 2111 times)

0 Members and 1 Guest are viewing this topic.

udaaf

  • Guest
Call Funtion in Function
« on: October 14, 2013, 03:26:33 AM »
How to call function with variable in another function.
I have First function :

Code: [Select]
(defun bikintabel (PointList / ActiveDocument mSpace pt myTable
   obj)
  (setq ActiveDocument (vla-get-activedocument
             (vlax-get-acad-object)))
  (setq mSpace(vla-get-modelspace ActiveDocument))
  (setq pt (vlax-make-safearray vlax-vbDouble
                                   '(0 . 2)))
  ;insertion point for the table
  (vlax-safearray-fill pt PointList)
  ;Mebuat table dengan jumlah column 5 dan row 5. Dengan ketinggian cell 5 dan lebar 30
  ;Pola pembuatan table (row column height width)

  (setq myTable
     (vla-addtable mSpace pt 2 13 10 30))
  (setq obj (vlax-ename->vla-object (entlast)))
  );defun

and

Code: [Select]
(defun ulang (Peng_1 Peng_2 PTX PTY PTZ i_1 i_2 TableFunction / Point_List ss_table table)
  (repeat Peng_1
    (setq Point_List (list (+ PTX i_1) (+ PTY i_2) PTZ))
    (setq TableFunction "bikintabel")
    ;read function bikin tabel
    (list (eval (read TableFunction)) Point_List)
    (setq ss_table (ssget "X" (list (cons 0 "ACAD_TABLE") (cons 10 Point_List))))
    ;merubah ename menjadi object
    (setq table (vlax-ename->vla-object(ssname ss_table 0)))
    (repeat Peng_2
      (vla-insertrows  table (1+ (vla-get-rows table)) 1 1)
      );repeat
    (setq i_2 (+ i_2 310))
    );repeat
  );defun ulang

and I wanna execute this with this code
Code: [Select]
(ulang 3 IsiBaris PT1 PT2 PT3 i j bikintable)

But always appear ; error: bad argument type: lselsetp nil.
So how to call function with name bikintable in function ulang. I use
Code: [Select]
(list (eval (read TableFunction)) Point_List)
But this code is can't work.

Thanks,

Udaaf

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: Call Funtion in Function
« Reply #1 on: October 14, 2013, 07:19:52 AM »
Are both functions in the same lisp file ? ( the calling statment only works that way)

To call a different lisp file you need something like this;

Code: [Select]
(load filename)
(apply (read filename) NIL)

The Filename variable needs to include the path if your lisp file is not located in a folder listed as a support path folder..

If you modify the definition to "(defun c:bikintabel (PointList / ActiveDocument mSpace pt myTable  obj)

Actually, never mind the above but i will leave for reference.  Your issue is you are not listing the "point_table" after the "bikintabel".

Bruce
« Last Edit: October 14, 2013, 07:32:39 AM by snownut2 »

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Call Funtion in Function
« Reply #2 on: October 14, 2013, 09:31:43 AM »
Udaaf: Try this:
Code - Auto/Visual Lisp: [Select]
  1. ; Return value: Table object.
  2. (defun bikintabel (PointList / ActiveDocument mSpace pt)
  3.   (setq ActiveDocument
  4.   )
  5.   (setq mSpace (vla-get-modelspace ActiveDocument))
  6.   (setq pt (vlax-3d-point PointList))
  7.   (vla-addtable mSpace pt 2 13 10 30)
  8. )
  9.  
  10. (defun ulang (Peng_1 Peng_2 PTX PTY PTZ i_1 i_2 / Point_List ss_table table)
  11.   (repeat Peng_1
  12.     (setq Point_List (list (+ PTX i_1) (+ PTY i_2) PTZ))
  13.     (setq table (bikintabel Point_List))
  14.     (repeat Peng_2
  15.       (vla-insertrows  table (1+ (vla-get-rows table)) 1 1)
  16.     )
  17.     (setq i_2 (+ i_2 310))
  18.   )
  19. )

reltro

  • Guest
Re: Call Funtion in Function
« Reply #3 on: October 14, 2013, 09:40:29 AM »
Hey...

a simple example:

Code: [Select]
(progn
    (defun example (ptlst / )
        (print ptlst)
        (terpri)
        (princ)
    )

    (defun callingfun (pt1 pt2 fun / )
        (princ "here we go with: ")
        (princ fun)
       
        (princ "\neval it to get this: ")
        (princ (eval fun))
        (princ "  <--- *operator*")
       
        (princ "\nthen use it as an operator:")
        (princ "(*operator* arg1 arg2)\n")
       
        ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        ((eval fun) (list pt1 pt2))
        ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    )

;;USE IT LIKE:

    (callingfun '(0 0 0) '(1 2 3) example)
    (princ "OR\n")
    (callingfun '(0 0 0) '(1 2 3) 'example)
    (princ "OR\n")
    (callingfun '(0 0 0) '(1 2 3) '(lambda (a / ) (alert (vl-princ-to-string a))))
    (princ "OR\n")
    (callingfun '(0 0 0) '(1 2 3) (function (lambda (a / ) (alert (vl-princ-to-string a)))))
    (princ "OR\n")
    (callingfun '(0 0 0) '(1 2 3) (lambda (a / ) (alert (vl-princ-to-string a))))
)

udaaf

  • Guest
Re: Call Funtion in Function
« Reply #4 on: October 14, 2013, 03:08:01 PM »
@roy_043 and @reltro,

Thanks for your reply. Done.
Case close   :wink:.