Jump to content

Recommended Posts

Posted

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))
Posted

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)
) 

Posted

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....

Posted

NOT WORKING

Command: MMNT

Select Object:

Pick a Point: _.layer

Current layer: "0"

Enter an option

Posted

somehow during a copy/paste something was lost... try it now

Posted

Its working

Its in one line i'll divide into 2 lines

Thanks

Posted

You can avoid the variant with:

 

(vlax-get obj 'MomentofInteria)

 

Lee

Posted

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: mmnt

Select Object:

Pick a Point: _.layer

Current layer: "0"

Enter an option

Posted

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))


Posted
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.

Posted
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 :geek:

Posted
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.

Posted
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 :geek:

 

Thanks again for the reminders...

Posted
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.

Posted
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.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...