asos2000 Posted January 19, 2010 Posted January 19, 2010 Whats wrong with this lisp? (defun c:MMNT ()(vl-load-com) (if (and (setq ent (car (entsel "\nSelect Object: "))) (setq pt (getpoint "\nPick a Point: "))) (progn (setq obj (vlax-ename->vla-object ent)) (if (vlax-property-available-p obj 'momentOfInertia) (progn ; SUBPROGN (setq MNT (rtos (vla-get-MomentOfInertia obj) 2 4)) (entmakex (list (cons 0 "TEXT") (cons 10 pt) (cons 40 (getvar "TEXTSIZE")) (cons 1 MNT) ) ; end LIST ) ; end entmakex ) ; end SUBPROGN (princ "\n** Invalid Object Selected **") ) ;END IF ) ; END PROGN ) ; END IF (princ) ) this line doesnt give any result (setq MNT (rtos (vla-get-MomentOfInertia obj) 2 4)) Quote
lpseifert Posted January 19, 2010 Posted January 19, 2010 Maybe because the (vla-get-MomentOfInertia... returns a variant, not a real try this (not a whole lot of testing) (defun c:MMNT () (vl-load-com) (if (and (setq ent (car (entsel "\nSelect Object: "))) (setq pt (getpoint "\nPick a Point: "))) (progn (setq obj (vlax-ename->vla-object ent)) (if (vlax-property-available-p obj 'momentOfInertia) (progn ; SUBPROGN (setq var (vla-get-MomentOfInertia obj) sa (vlax-variant-value var) lst (vlax-safearray->list sa) MNT (strcat (rtos (car lst) 2 4) " "(rtos (cadr lst) 2 4 )) ) (entmakex (list (cons 0 "TEXT") (cons 10 pt) (cons 40 (getvar "TEXTSIZE")) (cons 1 MNT) ) ; end LIST ) ; end entmakex ) ; end SUBPROGN (princ "\n** Invalid Object Selected **") ) ;END IF ) ; END PROGN ) ; END IF (princ) ) Quote
rkmcswain Posted January 19, 2010 Posted January 19, 2010 Step through the code and inspect the return values.... (vla-get-MomentOfInertia obj) returns a variant and (rtos) expects a real number. (vlax-safearray->list (vlax-variant-value (vla-get-MomentOfInertia obj) ) ) ;;;will return the value in list form. ;;;Then you can format this as desired. EDIT: lpseifert has got it for you already.... Quote
asos2000 Posted January 19, 2010 Author Posted January 19, 2010 NOT WORKING Command: MMNTSelect Object: Pick a Point: _.layer Current layer: "0" Enter an option Quote
lpseifert Posted January 19, 2010 Posted January 19, 2010 somehow during a copy/paste something was lost... try it now Quote
asos2000 Posted January 19, 2010 Author Posted January 19, 2010 Its working Its in one line i'll divide into 2 lines Thanks Quote
Lee Mac Posted January 19, 2010 Posted January 19, 2010 You can avoid the variant with: (vlax-get obj 'MomentofInteria) Lee Quote
asos2000 Posted January 19, 2010 Author Posted January 19, 2010 LEE I'll give a try and tell you what shall I do is, replace (vla-get-MomentOfInertia obj) with (vlax-get obj 'MomentofInteria) I did but this error Command: mmntSelect Object: Pick a Point: _.layer Current layer: "0" Enter an option Quote
Lee Mac Posted January 19, 2010 Posted January 19, 2010 Just using Larry's code: (defun c:MMNT (/ ent pt obj lst MNT) (vl-load-com) (if (and (setq ent (car (entsel "\nSelect Object: "))) (setq pt (getpoint "\nPick a Point: "))) (progn (setq obj (vlax-ename->vla-object ent)) (if (vlax-property-available-p obj 'MomentOfInertia) (progn (setq lst (vlax-get obj 'MomentofInertia) MNT (strcat (rtos (car lst) 2 4) " " (rtos (cadr lst) 2 4))) (entmakex (list (cons 0 "TEXT") (cons 10 pt) (cons 40 (getvar "TEXTSIZE")) (cons 1 MNT)))) (princ "\n** Invalid Object Selected **")))) (princ)) Quote
lpseifert Posted January 19, 2010 Posted January 19, 2010 You can avoid the variant with: (vlax-get obj 'MomentofInteria) Lee I should've thought of that... I just read about that the other day at theSwamp. Much cleaner to avoid those dang variants when possible. Quote
Lee Mac Posted January 19, 2010 Posted January 19, 2010 I should've thought of that... I just read about that the other day at theSwamp. Much cleaner to avoid those dang variants when possible. Yeah, its an undocumented function, but there are mixed results, as some functions don't work with the vlax-get/put Quote
rkmcswain Posted January 19, 2010 Posted January 19, 2010 LEE I'll give a try and tell you what shall I do is, replace .... with .... I did but this error Don't take this the wrong way, but rather than just replace bits of code with other bits of code without understanding what is happening, step through your code and get an understanding of what each function returns before passing that result to the next function, and so on. Quote
rkmcswain Posted January 19, 2010 Posted January 19, 2010 I should've thought of that... Same here. I have used that before, but the syntax just didn't come to me at that moment... Yeah, its an undocumented function, but there are mixed results, as some functions don't work with the vlax-get/put Thanks again for the reminders... Quote
LEsq Posted January 19, 2010 Posted January 19, 2010 I should've thought of that... I just read about that the other day at theSwamp. Much cleaner to avoid those dang variants when possible. It is a left over function from Vital Lisp - the original name of Visual Lisp. Quote
rkmcswain Posted January 19, 2010 Posted January 19, 2010 It is a left over function from Vital Lisp - the original name of Visual Lisp. Ah yes... vital lisp.... http://www.allbusiness.com/technology/software-services-applications-programming/7022066-1.html Quote
LEsq Posted January 19, 2010 Posted January 19, 2010 Ah yes... vital lisp....http://www.allbusiness.com/technology/software-services-applications-programming/7022066-1.html Yep... Now can be consider a vintage application Quote
Lee Mac Posted January 19, 2010 Posted January 19, 2010 Don't take this the wrong way, but rather than just replace bits of code with other bits of code without understanding what is happening, step through your code and get an understanding of what each function returns before passing that result to the next function, and so on. I agree with this - you learn much better that way. 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.