Se7en Posted July 20, 2009 Posted July 20, 2009 Well here is where we could get in trouble; meaning we are going to get into subjects i dont really have the ability to answer --i.e. you are going to start asking questions and WE autolispers dont have the docs to answer -e.g. I know your going to ask about releasing objects and i cant wait to see your reaction as to what our rule of thumb is for that little gem of a subject. *sigh*. So i will try to tell ya the 'preferred' *eye roll* way. So take some areas with a grain of salt. Real quick explination as to what Visual Lisp is. We have access to an ARX (a dll written in C++) which provides a structured *ah-huh* interface to the AutoCAD.exe object model. The "same" (different interface) model VBA uses. ;; load the object model (vl-load-com) ;; create access to objects (setq acaddoc (vla-get-activedocument (vlax-get-acad-object))) (setq mspace (vla-get-modelspace acaddoc)) ;; add a line (vla-AddLine mspace (vlax-3d-point '(5.0 5.0 0.0)) (vlax-3d-point '(5.0 10.0 0.0)) ) Or more end user interactive... (setq PT1 (getpoint "\nSpecify First Point: ")) (setq PT2 (getpoint PT1 "\nSpecify next point: ")) (vla-addline mspace (vlax-3d-point PT1)(vlax-3d-point PT2)) Now lets give you something to play with. Here are some property dumps for you to look at (the last argument "true" is to dump the methods you have access to, remove it and you get just the props.) (vlax-dump-object (vlax-get-acad-object) T ) (vlax-dump-object (vla-get-documents (vlax-get-acad-object)) t) (vlax-dump-object (vla-get-ActiveDocument (vlax-get-acad-object)) t) (vlax-dump-object (vla-get-Groups (vla-get-ActiveDocument (vlax-get-acad-object))) t) (vlax-dump-object (vla-get-PlotConfigurations(vla-get-ActiveDocument (vlax-get-acad-object))) t) (vlax-dump-object (vla-get-files (vla-get-Preferences (vlax-get-acad-object))) T) ... Now load this and start selecting objects you can select on your screen to see all the stuff you can do. (defun C:PropDump () (vlax-Dump-Object (vlax-Ename->Vla-Object (car (entsel))) T ) (textscr) (princ) ) Quote
Se7en Posted July 20, 2009 Posted July 20, 2009 Oh and in autocad you can use an "IDE" too. "vlide" is the command. ...i mostly use Vim myself. Sorry for going fast, i dont have a whole lot of time right now (just started a NASTY proj). so you may have to do some leg work. Gotta run. Quote
Lee Mac Posted July 20, 2009 Posted July 20, 2009 techjunkie, You could go the Visual LISP route, as Se7en says, but to answer your question, the reason your code acted differently was due to the OSnaps being on. You will need to add a line of code to turn these off, then back on at the end (and in an error handler if you have one). Lee PS. If you wanted to go the VL route, to add a Lightweight Polyline, you need to make a Variant, something like this: (defun mk_poly (lst) (vla-addLightWeightPolyline (vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-acad-object))) (vlax-make-variant (vlax-safearray-fill (vlax-make-safearray vlax-vbdouble (cons 0 (1- (length lst)))) lst))))) ;; (mk_poly '((1 2) (3 4) (5 6))) Where your "lst" argument is a list of 2D points Quote
Se7en Posted July 20, 2009 Posted July 20, 2009 snaps?! *argh* ...I'm sorry techjunkie09. That is about as simple as (In cpp terms) ``using namespace std;'' Quote
Lee Mac Posted July 20, 2009 Posted July 20, 2009 snaps?! *argh* ...I'm sorry techjunkie09. That is about as simple as (In cpp terms) ``using namespace std;'' What are you implying here? Missing the OSnaps is an easy mistake to make. Quote
Se7en Posted July 20, 2009 Posted July 20, 2009 What are you implying here? Missing the OSnaps is an easy mistake to make. yeah. Whenever you draw via lisp you turn off the osnaps right? Quote
Lee Mac Posted July 20, 2009 Posted July 20, 2009 yeah. Whenever you draw via lisp you turn off the osnaps right? No, I don't normally use the "command" function, but all the same, this guy is just starting out, no need to patronise him... Quote
Se7en Posted July 20, 2009 Posted July 20, 2009 *blink-blink* i'm not patronizing anyone! Im slamming myself for not thinking about it. I guarantee that techjunkie09 didnt/wouldnt take it that way. Besides, (s)hes not a total newbie (s)he just needs help with some minor details (syntax, process, etc and (s)he will be teaching us). Quote
Lee Mac Posted July 20, 2009 Posted July 20, 2009 Sorry, perhaps I took your post the wrong way Quote
Se7en Posted July 20, 2009 Posted July 20, 2009 And now the question becomes: how many others do the same? I't no wonder why people dont engage in academic discussions with me; they think I'm an ogre! ...Thanx for the confidence boost! *And if it wasn't obvious: I'm joking around.* Quote
Lee Mac Posted July 21, 2009 Posted July 21, 2009 I'm sure we don't all think that, just on this particular occasion, I misinterpreted your post. Quote
mjensen61 Posted March 31, 2020 Posted March 31, 2020 (edited) LISP 101: LISP is not like other languages. The philosophy of LISt Processing (LISP) is that lists (enclosed in brackets) are processed and a value is returned. Each list may have some side effects e.g. a list starting with princ will output the second item to the screen. But the primary purpose of the list is to return/evaluate a value. The last element evaluated in a (defun list is returned from the list. There may have been many side effects in the (defun such as printing, setting values etc. But again the primary purpose of the list processing (LISP) is to return/evaluate a value. It's odd to think that the primary purpose of a (princ list is to return a value and that the act of printing is only a side effect. Google LISP "side effect" for more information. Instead of (princ, you could use (setq to avoid the side effect of sending a value to the screen. (return does not work in AutoLISP. You can have write your own... (defun return (value / retval) (setq retval value) ) But this will still only evaluate as the last element in the (defun list. You can create a temporary storage for your return value named retval and pass it out of the evaluation of the list. Note the pointer to retval at the end of this (defun list. (defun compareString(string1 string2) (if (= (string1) (string2)) (setq retval"true") (setq retval"false") ) retval ) On one of my projects I had an error with the retval pointer so I could use (setq retval retval) instead. That would evaluate and fall through to the evaluation of the list. If you don't want to evaluate a value you can put a blank (princ) at the end of the (defun. This will return a NIL value. (defun myfunction (string1 string2) * dosomething (princ) ) Note also the (load list also returns a value which is printed to the screen. This is why we put the blank (princ) statement at the end of our lisp files Edited March 31, 2020 by mjensen61 grammar 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.