Author Topic: Attempt: Function for nested vlax-get with built-in vlax-release-object  (Read 1751 times)

0 Members and 1 Guest are viewing this topic.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
This is related to:
http://www.theswamp.org/index.php?topic=36170.0
http://www.theswamp.org/index.php?topic=2005.0

Inspiration came from:
http://www.visuallisp-tutorial.mapcar.net/schnellzugriff.html
This is part of a tutorial in German. Look for the function vlax*get-property.

Code: [Select]
;;; ======================================================================
;;; Lib function: kg:vl:Get (LibVer20101216)
;;; Purpose:      Generic visual lisp get-function.
;;; Arguments:    lst - list of objects and/or properties
;;;                     Root element first. If the first element in the
;;;                     list is nil then the application object is used
;;;                     as the root.
;;; Return value: Result of vlax-get.
;;; Dependencies: None
;;; Remarks:      http://www.theswamp.org/index.php?topic=2005.0
;;;               http://www.visuallisp-tutorial.mapcar.net/schnellzugriff.html
;;; Examples:     (kg:vl:Get '(nil)) => #<VLA-OBJECT IAcadApplication 020aa128>
;;;               (kg:vl:Get '(nil activedocument activelayer color)) => 7
;;; ======================================================================
(defun kg:vl:Get (lst / tmpLst)
  (setq tmpLst
    (cons
      (cond
        ((car lst))
        ((vlax-get-acad-object))
      )
      tmpLst
    )
  )
  (mapcar
    '(lambda (a)
      (setq tmpLst
        (cons
          (vlax-get ; alternative: vlax-get-property
            (car tmpLst)
            a
          )
          tmpLst
        )
      )
    )
    (cdr lst)
  )
  (mapcar
    '(lambda (a)
      (and
        (not (vlax-object-released-p a))
        (vlax-release-object a)
      )
    )
    (cdr tmpLst)
  )
  ; (gc)
  (car tmpLst)
)

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Attempt: Function for nested vlax-get with built-in vlax-release-object
« Reply #1 on: December 16, 2010, 09:28:35 AM »
Very original idea Roy! I like it  :-)

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Attempt: Function for nested vlax-get with built-in vlax-release-object
« Reply #2 on: December 16, 2010, 10:11:33 AM »
Very original idea Roy! I like it  :-)
All Credits for originality should go to Axel Strube-Zettler (author of the German tutorial).