Author Topic: Defining a LISP function  (Read 13507 times)

0 Members and 1 Guest are viewing this topic.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Defining a LISP function
« Reply #30 on: October 18, 2018, 02:57:13 PM »
As someone that is not familiar with AutoLisp, I am inferring AutoLisp doesn't have many other data structures besides lists?
I thought I read earlier in the thread that a point was (xx yy zz), how would a BlockTableRecord be represented in AutoLisp?
Is it a list of its properties & methods?

Talking about 'pure AutoLISP':
- the only AutoLISP  data structure is the LISP list (more accurately a single linked list base on cons cells)
- BlockTableRecord is represented with an ename (which is equivalent to the .NET ObjectId) and the BlockTableRecord properties can be accessed with the 'entget' function which returns a list of dotted pairs containing the object DXF data. These properties can be modified by editing the list and passing this new list to the 'entmod' function.

As LISP (on Windows systems) can acces to the AutoCAD ActiveX/COM API (typically called Visual LISP or vlisp)
- it can also use a data structure similar to arrays (called 'safearrays')
- BlockTableRecord is called a Block which has properties and methods.

dgorsman was faster...
Speaking English as a French Frog

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Defining a LISP function
« Reply #31 on: October 18, 2018, 03:27:19 PM »
As someone that is not familiar with AutoLisp, I am inferring AutoLisp doesn't have many other data structures besides lists?
I thought I read earlier in the thread that a point was (xx yy zz), how would a BlockTableRecord be represented in AutoLisp?
Is it a list of its properties & methods?

Others were faster and probably explained better, still leaving my impressions (may worth something) :
It has primitive data types, like: int, string, real, null, list, symbol, subroutine, userSubroutine
Code - Auto/Visual Lisp: [Select]
  1. _$ (mapcar 'type (list 5 3.212 "Hello world" nil '("list" "of" "strings") 'daisy alert (lambda nil nil)))
  2. (INT REAL STR nil LIST SYM SUBR USUBR)
  3.  
  4. _$ (type (vl-catch-all-apply 'eval '((exit))))
  5. VL-CATCH-ALL-APPLY-ERROR
  6.  

But VLISP can offer access to acad's object model (COM).. so you still work with the built-in properties/methods, access the built-in objects
and there are additional datatypes such as: variant, safearray, vla-object.
However you can't create your own custom objects.
Also there are few ways to call the methods, with the
(<vla>-MethodName <vla-object> args)
or
(vlax-invoke <vla-object> 'MethodName args)
or
(vlax-invoke-method <vla-object> 'MethodName args)


Where in some you can provide the vanilla lisp representation of point, as a list of x/y/z numbers
but others require conversion with the built-in activex lisp function vlax-3d-point,
so it converts that list of '(x y z) into a variant of array of doubles with a value of safearray of doubles, that holds the x y z.
Code - Auto/Visual Lisp: [Select]
  1. (setq CurrentSpace (vla-get-Block (vla-get-ActiveLayout (vla-get-ActiveDocument (vlax-get-acad-object))))) ; obtain the current space, model/paper
  2. (setq pt '(10.0 20.5 5.2)) ; bound our point into a list of x y z
  3.  
  4. ; Few ways to call the same method that does the same thing:
  5. (vlax-invoke CurrentSpace 'AddPoint pt) ; #1 uses vanilla-lisp data as argument for the point
  6. (vla-AddPoint CurrentSpace (vlax-3d-point pt)) ; #2 converting the vanilla lisp point into a variant via (vlax-3D-point) function [required]
  7. ; #3 manual converting, to a variant data for 3D point [required]:
  8. (vla-AddPoint CurrentSpace
  9.   (vlax-make-variant
  10.       (vlax-make-safearray vlax-vbDouble '(0 . 2))
  11.       pt
  12.     )
  13.     (+ vlax-vbArray vlax-vbDouble)
  14.   )
  15. )
  16.  
  17. ; investigating what returns (vlax-3D-point) / or how it converts the input (thats how I came up with #3)
  18. _$ (vlax-3d-point '(10.0 20.5 5.2))
  19. #<variant 8197 ...>
  20. _$ (vlax-variant-type (vlax-3d-point '(10.0 20.5 5.2)))
  21. 8197
  22. ; https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/AutoCAD-AutoLISP/files/GUID-14029CC8-2839-432B-ABFC-F470AFA7606B-htm.html
  23. _$ (+ vlax-vbArray vlax-vbDouble)
  24. 8197
  25. ; hence:
  26. _$ (= (+ vlax-vbArray vlax-vbDouble) (vlax-variant-type (vlax-3d-point '(10.0 20.5 5.2))))
  27. T
  28. _$ (vlax-variant-value (vlax-3d-point '(10.0 20.5 5.2)))
  29. #<safearray...>
  30. _$ (safearray-value (vlax-variant-value (vlax-3d-point '(10.0 20.5 5.2))))
  31. (10.0 20.5 5.2)
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg