Lee Mac Posted January 11, 2009 Posted January 11, 2009 Hi All, Previously, I have posted a thread asking for a function that will successfully retrieve a list of all the layers in the active document. ASMI kindly provided me with this: (defun laylist (/ oLst) (vl-load-com) (vlax-for l (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object) ) ;_ end vla-get-ActiveDocument ) ;_ end vla-get-Layers (setq oLst (cons (vla-get-Name l) oLst) ) ; end setq ) ; end vlax-for (setq oLst (reverse oLst)) ) ;_ end defun However, when I have tried to analyse this with the aid of the Vlide Help file, I am having no luck in pinning down what the function actually does. I realise there is probably an easier way to retrieve such a list without dabbling with Active X methods, maybe: (defun laylist (/ lay oLst) (setq lay (tblnext "LAYER" T)) (while lay (setq oLst (cons (cdr (assoc 2 lay)) oLst) lay (tblnext "LAYER") ) ;_ end setq ) ;_ end while (setq oLst (reverse oLst)) ) ;_ end defun But I would really like to start to understand VL, as I find it can do a lot more than Common LISP, - (judging by a few of ASMI's examples...) Any help with a step by step explanation of ASMI's code would be highly appreciated. Thanks Guys, Lee Quote
wizman Posted January 11, 2009 Posted January 11, 2009 i am not the best to explain this but here's my simplest explanations: whenever you're in doubt of what's happening inside a vla expression you can always dump to see whats inside: you can run this in your vlide one by one: (vl-load-com) (vlax-dump-Object (vlax-get-acad-object) t) (vlax-dump-object (vla-get-ActiveDocument (vlax-get-acad-object)) t) (vlax-dump-object(vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object) ) ;_ end vla-get-ActiveDocument ) ;_ end vla-get-Layers t) vlax-for is like foreach in autolisp, which is used here to step/loop through the layer collection also known as layer table in autolisp. you need also to understand the autocad object model hierarchy to know which are The Application Object, The Document Object, The Collection Objects, The Graphical and Nongraphical Objects, The Preferences, Plot, and Utility Objects Quote
David Bethel Posted January 11, 2009 Posted January 11, 2009 (while (setq tdef (tblnext "LAYER" (not tdef))) (setq laylst (cons (cdr (assoc 2 tdef)) laylst))) Lee, I never thought the vl functions were anywhere need as readable or efficient. Yes, they can do some things AutoLisp has problems with, but the overall it wasn't for me. -David Quote
Lee Mac Posted January 11, 2009 Author Posted January 11, 2009 (while (setq tdef (tblnext "LAYER" (not tdef))) (setq laylst (cons (cdr (assoc 2 tdef)) laylst))) Lee, I never thought the vl functions were anywhere need as readable or efficient. Yes, they can do some things AutoLisp has problems with, but the overall it wasn't for me. -David Ok David first, I understand where you are coming from - I don't really like them either, but I feel that I am at a disadvantage in not knowing what they can do. Some of the problems on here I feel stumped, and then someone comes and solves them with the use of VL, so I thought it best to delve and see what it was all about. Thanks for providing that short snippet there to retrieve layers, you simplified my routine somewhat. I take it (tblnext "layer" (not tdef)) returns (tblnext "layer" T) on the first iteration and (tblnext "layer" nil) otherwise, hence starting at the start of the table. Is this correct? Thanks once again. Quote
Lee Mac Posted January 11, 2009 Author Posted January 11, 2009 i am not the best to explain this but here's my simplest explanations:whenever you're in doubt of what's happening inside a vla expression you can always dump to see whats inside: you can run this in your vlide one by one: (vl-load-com) (vlax-dump-Object (vlax-get-acad-object) t) (vlax-dump-object (vla-get-ActiveDocument (vlax-get-acad-object)) t) (vlax-dump-object(vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object) ) ;_ end vla-get-ActiveDocument ) ;_ end vla-get-Layers t) vlax-for is like foreach in autolisp, which is used here to step/loop through the layer collection also known as layer table in autolisp. you need also to understand the autocad object model hierarchy to know which are The Application Object, The Document Object, The Collection Objects, The Graphical and Nongraphical Objects, The Preferences, Plot, and Utility Objects Wizman, Thanks for your reply, I really appreciate the time you have taken to help me understand this. Proceeding through your posted code I can see how the VL is built up, command by command. I see how, with each additional code section, the item to be retrieved is narrowed down. Thank you for your helpful walkthrough. Cheers Lee Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.