Jump to content

a lisp routine to have an object rotate 360


djw

Recommended Posts

I am trying to write a lisp routine to have an object (say a bolt) rotate 360 say, 50 times & move @ the same time? As I do a video animation, just can’t seem to get it.

Link to comment
Share on other sites

  • Replies 32
  • Created
  • Last Reply

Top Posters In This Topic

  • djw

    9

  • alanjt

    8

  • Hippe013

    8

  • Freerefill

    3

Top Posters In This Topic

Posted Images

There are a few ways to do this. The first is to write a LISP to physically rotate the object, but this would only be useful if the demonstration was done in AutoCAD or if you had a third-party program that would record the images on your monitor into a video. The other option is decidedly more complex, but it would allow you to directly export a video. Check out the Motion Path Animations available in AutoCAD to see if those will do what you're looking for.

Link to comment
Share on other sites

Thanks for your reply..

"The first is to write a LISP to physically rotate the object", ya that is what I am try'n to do, in AutoCAD 2007, & yes third-party program to record the images on the monitor into a video, Motion Path Animations N.G.

Link to comment
Share on other sites

Quick and dirty, though I would recommend you take a look at the motion path animations available in AutoCAD, as they would offer a better product. Code like this is dependent upon your system, and may lag or speed up depending on what you've got going on.

 

(defun c:rotob( / e p a b c i)
 (vl-load-com)
 (setvar "cmdecho" 0)
 (setq e (vlax-ename->vla-object (car (entsel "\nSelect object: "))))
 (setq p (getpoint "\nSelect rotation point: "))
 (setq a 5    ; Number of revolutions
   b 5    ; Degrees per increment (must be a factor of 360)
   c 10    ; Delay between incremental rotation
   i 0)    ; Counter
 (if (= 0 (rem (setq d (/ 360 b)) 1))
   (while (< i a)
     (repeat d
   (vla-rotate e (vlax-3d-point p) (* (/ pi 180.0) b))
   (vl-cmdf "delay" c "regen")
   )
     (setq i (1+ i))
     )
   )
 )

Link to comment
Share on other sites

Hey this might get you started!

I wrote it a while back just for fun... :P

 
(defun c:spin (/ obj rot rot+)
 (setq obj (vlax-ename->vla-object (car (entsel))))
 (setq rot (vla-get-rotation obj))
 (setq rot+ (/ (* 2 pi) 500))
 (repeat 500
   (setq rot (+ rot+ rot))
   (vla-put-rotation obj rot)
   (vla-update obj)
   )
 (vlax-release-object obj)
 (princ)
 )

Link to comment
Share on other sites

thanks again..

Ok new to the lisp writing, so I’m slow, I have an example of what I’m try’n to-do in a video, the blue bolts need to spin / rotate as they move in.

(1) How to pick the bolt.

(2) How to apply the lisp to one bolt at time.

oil spill in the gulf, pipe cap

Link to comment
Share on other sites

That's a whole other ball of wax.

 

I would suggest you take the code that's been posted and try to tweak it so that it rotates about a specific axis (you'll need to specify this for 3D). You should then be able to add in extra data to get the translation you requested. Once you get the code for one object done, you should be able to copy it for the rest of them.

Link to comment
Share on other sites

I think I've posted it before somewhere:

 

(defun c:bored ( / cir cnt gr lst n d )
 ;; © Lee Mac 2010
 (setq lst (list (getvar 'viewctr) (getvar 'viewctr)) cnt 0)
 
 (while (eq 5 (car (setq gr (grread nil 13 0))))
   (redraw)
   (setq cir nil n 0 lst (append lst (list (last lst) (cadr gr)))
         cnt (1+ cnt))
   
   (if (< 100 cnt) (setq lst (cddr lst)))
   
   (repeat 50
     (setq d (/ (distance (car lst) (last lst)) 4.))
     (repeat 4
       (setq cir (cons (polar (car lst) (* (setq n (1+ n)) (/ (* pi 2) 50)) d) cir))
       (setq d (/ d 2.))
     )
   )
   (grvecs (append (list (rem (/ cnt 100) 255)) lst cir))
 )
 (redraw)
 (princ)
)

Link to comment
Share on other sites

alanjt:

 

Care to upload that lisp for your spinning / moving thing-a-ma-jig?

 

Sure, they were pretty simple. I added a second one that will rotate and move a selection set.

 

(defun c:Test (/ obj block gr)
 ;; Alan J. Thompson, 06.22.10
 (if
   (and
     ;;(setq obj (AT:Entsel nil "\nSelect block: " '("LV" (0 . "INSERT")) nil))
     (setq obj (car (entsel "\nSelect block: ")))
     (eq "INSERT" (cdr (assoc 0 (entget obj))))
     ;;(setq block (vla-copy obj))
     (not
       (vl-catch-all-error-p
         (setq block (vl-catch-all-apply
                       (function vla-copy)
                       (list (vlax-ename->vla-object obj))
                     )
         )
       )
     )
   )
    (while (and (eq 5 (car (setq gr (grread T 15 2)))) (vl-consp (cadr gr)))
      (vla-put-insertionpoint block (vlax-3d-point (trans (cadr gr) 1 0)))
      (vla-put-rotation block (+ (vla-get-rotation block) 0.02))
    )
 )
 (princ)
)



(defun c:Test2 (/ ss lst)
 ;; Alan J. Thompson, 06.22.10
 (if (setq ss (AT:SS->List (ssget "_:L") T))
   (while (and (eq 5 (car (setq gr (grread T 15 2)))) (vl-consp (cadr gr)))
     (if (> (length (setq lst (cons (vlax-3d-point (trans (cadr gr) 1 0)) lst))) 1)
       (foreach x ss
         (vla-move x (cadr lst) (car lst))
         (vla-rotate x (car lst) 0.015)
       )
     )
   )
 )
 (princ)
)



(defun AT:SS->List (SS VLA)
 ;; Convert selection set to list of ename or vla objects
 ;; SS - SSGET selection set
 ;; VLA - T for vla objects, nil for ename
 ;; Alan J. Thompson, 04.01.10
 (if (eq 'PICKSET (type SS))
   ((lambda (i / l)
      (while (setq e (ssname SS (setq i (1+ i))))
        (cond (VLA (setq l (cons (vlax-ename->vla-object e) l)))
              ((setq l (cons e l)))
        )
      )
    )
     -1
   )
 )
)

Link to comment
Share on other sites

Lee Mac & AlanJT: Thanks for posting your code.... Fun stuff! :)

 

To the OP:How about something like this?

 

 
(defun c:spinbolt (/ obj rot rot+)
 (vl-load-com)
 (setq obj (vlax-ename->vla-object (car (entsel))))
 (setq rot (vla-get-rotation obj))
 (setq inspnt (vlax-safearray->list (vlax-variant-value (vlax-get-property obj 'InsertionPoint))))
 (setq x (nth 0 inspnt))
 (setq y (nth 1 inspnt))
 (setq z (nth 2 inspnt))
 (setq rot+ (/ (* 2 pi) 100))
 (setq rot- (- rot+ (* rot+ 2)))
 (setq drop (/ 0.3 100))
 (repeat 1000
   (setq inspnt (vlax-safearray->list (vlax-variant-value (vlax-get-property obj 'InsertionPoint))))
   (setq z (nth 2 inspnt))
   (setq nz (- z drop))
   (setq nins (vlax-3d-point (list x y nz)))
   (vlax-put-property obj 'InsertionPoint nins)
   (setq rot (+ rot- rot))
   (vla-put-rotation obj rot)
   (vla-update obj)
   )
 (vlax-release-object obj)
 (princ)
 )

 

It works with the attached dxf... (2000 Format) 250KB Limit? Serious?:shock:

BOLT.zip

Link to comment
Share on other sites

Lee Mac & AlanJT: Thanks for posting your code.... Fun stuff! :)

 

To the OP:How about something like this?

It works with the attached dxf... (2000 Format) 250KB Limit? Serious?:shock:

 

You're welcome and cool.

Link to comment
Share on other sites

Your welcome & Thanks!

 

(I just noticed that I am now a full member! Yahoo!) :D

Only 5 million more posts and I'll be a Luminous Being! (just poking fun at you Lee)

Link to comment
Share on other sites

Only 5 million more posts and I'll be a Luminous Being! (just poking fun at you Lee)

 

Go look at ReMark's 'level'.

Link to comment
Share on other sites

Hippe, THANKS!! thats exackly what I was try'n to do, just got'a figure out how to make it work with my pipe fix dwg Thanks again....................

Link to comment
Share on other sites

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