Author Topic: Need to combine 2 routines  (Read 1586 times)

0 Members and 1 Guest are viewing this topic.

bemiller1

  • Guest
Need to combine 2 routines
« on: July 28, 2008, 12:19:53 PM »
Here's a problem: I have two snippets of code each of which test OK when run separately but when I combine them I am unable to get the desired result. (a number of sequential renderings written to a particular file)
I'll post both then post my attempt at combining them. Hopefully some brilliant Autolisp specialist can spot a neophyte's oversight.
First bit:
Code: [Select]
(defun C:setrender
()
  (c:rpref "TOGGLE" "SKIPRDLG" "OFF")
  (c:rpref "ROPT" "ASCAN" 2 NIL NIL 0 1 3)
  (c:rfileopt "BMP" 640 480 1.0 "C8")
  (c:render "D:/Bernie/Shadows/Shadow_System_Rotate2/Test2"
  )
)
Second bit:
Code: [Select]
(defun rtod (a)
  (/ (* a 180) pi)
)
(defun c:ani (/ cntr deg entgrp fname num rotpnt)
; Turn command echoing off
  (setq cmdold (getvar "cmdecho"))
  (setvar "cmdecho" 0)
; Select the objects
  (setq entgrp (ssget))
; Check to make sure you selected something
  (if entgrp
    (progn
; Set undo point
      (command ".undo" "Mark")
; Pick rotation point
      (setq rotpnt (getpoint "\nPick rotation point:<0,0,0> "))
      (if (= rotpnt nil)
(setq rotpnt (list 0 0 0))
      )
      (setq num (getint "\nEnter number of images:<15> "))
      (if (= num nil)
(setq num 15)
      )
      (setq deg
     (rtod (getangle rotpnt "\nEnter degrees of movement:<3> "))
      )
      (if (= deg nil)
(setq deg 3)
      )
      (setq cntr 1)
      (repeat num
; Add your path here
(setq
  fname (strcat
  "D:\Bernie\Shadows\Shadow_System_Rotate2\TestImage"
  (itoa cntr)
  ".jpg"
)
)

; ***renders an image to the specified filename***
(c:render (vl-princ-to-string fname))
; Rotate the object
(command ".rotate" entgrp "" rotpnt deg)
(setq cntr (1+ cntr))
      ) ; repeat
      (command ".undo" "Back")
    ) ; progn
  ) ; if

; Return echo
  (setvar "cmdecho" cmdold)
  (princ)
)
My attempt at a combination:
Code: [Select]
(defun rtod (a)
  (/ (* a 180) pi)
)
;sets reder preferences and file options
(defun C:setrender
   ()
  (c:rpref "TOGGLE" "SKIPRDLG" "OFF")
  (c:rpref "ROPT" "ASCAN" 2 NIL NIL 0 1 3)
  (c:rfileopt "BMP" 640 480 1.0 "C8")
)

(defun c:ani (/ cntr deg entgrp fname num rotpnt)
; Turn command echoing off
  (setq cmdold (getvar "cmdecho"))
  (setvar "cmdecho" 0)
; Select the objects
  (setq entgrp (ssget))
; Check to make sure you selected something
  (if entgrp
    (progn
; Set undo point
      (command ".undo" "Mark")
; Pick rotation point
      (setq rotpnt (getpoint "\nPick rotation point:<0,0,0> "))
      (if (= rotpnt nil)
(setq rotpnt (list 0 0 0))
      )
      (setq num (getint "\nEnter number of images:<15> "))
      (if (= num nil)
(setq num 15)
      )
      (setq deg
     (rtod (getangle rotpnt "\nEnter degrees of movement:<3> "))
      )
      (if (= deg nil)
(setq deg 3)
      )
      (setq cntr 1)
      (repeat num
; Add you path here
(setq
  fname (strcat
  "D:\Bernie\Shadows\Shadow_System_Rotate2\TestImage"
  (itoa cntr)
  ".jpg"
)
)
;sets render preferences and file options
(c:setrender)
; ***renders an image to the specified filename***
(c:render (vl-princ-to-string fname))
; Rotate the object
(command ".rotate" entgrp "" rotpnt deg)
(setq cntr (1+ cntr))
      ) ; repeat
      (command ".undo" "Back")
    ) ; progn
  ) ; if

; Return echo
  (setvar "cmdecho" cmdold)
  (princ)
)

Hope someone has a go at this
bemiller

lispman21

  • Guest
Re: Need to combine 2 routines
« Reply #1 on: July 28, 2008, 04:22:17 PM »
You can give this a try.  The only thing i changed is highlighted in red.  Where if you didn't enter a number of degreest to rotate it would error out because it would try to run rtod without a number, bu ti fixed that.  Other than what i changed that is all i can test cause i don't have you other programs it try's to call, but looks like it will work because it tried to call the other programs.

Code: [Select]
(defun rtod (a)
  (/ (* a 180) pi)
)
;sets reder preferences and file options
(defun C:setrender ()
  (c:rpref "TOGGLE" "SKIPRDLG" "OFF")
  (c:rpref "ROPT" "ASCAN" 2 NIL NIL 0 1 3)
  (c:rfileopt "BMP" 640 480 1.0 "C8")
)

(defun c:ani (/ cntr deg entgrp fname num rotpnt)
; Turn command echoing off
  (setq cmdold (getvar "cmdecho"))
  (setvar "cmdecho" 0)
; Select the objects
  (setq entgrp (ssget))
; Check to make sure you selected something
  (if entgrp
    (progn
; Set undo point
      (command ".undo" "Mark")
; Pick rotation point
      (setq rotpnt (getpoint "\nPick rotation point:<0,0,0> "))
      (if (= rotpnt nil)
(setq rotpnt (list 0 0 0))
      )
      (setq num (getint "\nEnter number of images:<15> "))
      (if (= num nil)
(setq num 15)
      )
      [color=red](setq deg(getangle rotpnt "\nEnter degrees of movement:<3> "))
     
      (if (= deg nil)
(setq deg (rtod 3))
(setq deg (rtod deg))
      )[/color]
      (setq cntr 1)
      (repeat num
; Add you path here
(setq
  fname (strcat
  "D:\Bernie\Shadows\Shadow_System_Rotate2\TestImage"
  (itoa cntr)
  ".jpg"
)
)
;sets render preferences and file options
  (c:setrender)
; ***renders an image to the specified filename***
(c:render (vl-princ-to-string fname))
; Rotate the object
(command ".rotate" entgrp "" rotpnt deg)
(setq cntr (1+ cntr))
      ) ; repeat
      (command ".undo" "Back")
    ) ; progn
  ) ; if

; Return echo
  (setvar "cmdecho" cmdold)
  (princ)
)


Adesu

  • Guest
Re: Need to combine 2 routines
« Reply #2 on: July 28, 2008, 08:04:00 PM »
I'm not sure this code would help you.
Code: [Select]
(defun C:setrender ()
(if
  (not (member "geom3d.arx" (arx)))
  (arxload "geom3d")
  ) ; if
  (c:rpref "TOGGLE" "SKIPRDLG" "OFF")
  (c:rpref "ROPT" "ASCAN" 2 NIL NIL 0 1 3)
  (c:rfileopt "BMP" 640 480 1.0 "C8")
  (c:render "D:/Bernie/Shadows/Shadow_System_Rotate2/Test2"
  )
)

Here's a problem: I have two snippets of code each of which test OK when run separately but when I combine them I am unable to get the desired result. (a number of sequential renderings written to a particular file)
I'll post both then post my attempt at combining them. Hopefully some brilliant Autolisp specialist can spot a neophyte's oversight.
First bit:
Code: [Select]
(defun C:setrender
()
  (c:rpref "TOGGLE" "SKIPRDLG" "OFF")
  (c:rpref "ROPT" "ASCAN" 2 NIL NIL 0 1 3)
  (c:rfileopt "BMP" 640 480 1.0 "C8")
  (c:render "D:/Bernie/Shadows/Shadow_System_Rotate2/Test2"
  )
)
Second bit:
Code: [Select]
(defun rtod (a)
  (/ (* a 180) pi)
)
(defun c:ani (/ cntr deg entgrp fname num rotpnt)
; Turn command echoing off
  (setq cmdold (getvar "cmdecho"))
  (setvar "cmdecho" 0)
; Select the objects
  (setq entgrp (ssget))
; Check to make sure you selected something
  (if entgrp
    (progn
; Set undo point
      (command ".undo" "Mark")
; Pick rotation point
      (setq rotpnt (getpoint "\nPick rotation point:<0,0,0> "))
      (if (= rotpnt nil)
(setq rotpnt (list 0 0 0))
      )
      (setq num (getint "\nEnter number of images:<15> "))
      (if (= num nil)
(setq num 15)
      )
      (setq deg
     (rtod (getangle rotpnt "\nEnter degrees of movement:<3> "))
      )
      (if (= deg nil)
(setq deg 3)
      )
      (setq cntr 1)
      (repeat num
; Add your path here
(setq
  fname (strcat
  "D:\Bernie\Shadows\Shadow_System_Rotate2\TestImage"
  (itoa cntr)
  ".jpg"
)
)

; ***renders an image to the specified filename***
(c:render (vl-princ-to-string fname))
; Rotate the object
(command ".rotate" entgrp "" rotpnt deg)
(setq cntr (1+ cntr))
      ) ; repeat
      (command ".undo" "Back")
    ) ; progn
  ) ; if

; Return echo
  (setvar "cmdecho" cmdold)
  (princ)
)
My attempt at a combination:
Code: [Select]
(defun rtod (a)
  (/ (* a 180) pi)
)
;sets reder preferences and file options
(defun C:setrender
   ()
  (c:rpref "TOGGLE" "SKIPRDLG" "OFF")
  (c:rpref "ROPT" "ASCAN" 2 NIL NIL 0 1 3)
  (c:rfileopt "BMP" 640 480 1.0 "C8")
)

(defun c:ani (/ cntr deg entgrp fname num rotpnt)
; Turn command echoing off
  (setq cmdold (getvar "cmdecho"))
  (setvar "cmdecho" 0)
; Select the objects
  (setq entgrp (ssget))
; Check to make sure you selected something
  (if entgrp
    (progn
; Set undo point
      (command ".undo" "Mark")
; Pick rotation point
      (setq rotpnt (getpoint "\nPick rotation point:<0,0,0> "))
      (if (= rotpnt nil)
(setq rotpnt (list 0 0 0))
      )
      (setq num (getint "\nEnter number of images:<15> "))
      (if (= num nil)
(setq num 15)
      )
      (setq deg
     (rtod (getangle rotpnt "\nEnter degrees of movement:<3> "))
      )
      (if (= deg nil)
(setq deg 3)
      )
      (setq cntr 1)
      (repeat num
; Add you path here
(setq
  fname (strcat
  "D:\Bernie\Shadows\Shadow_System_Rotate2\TestImage"
  (itoa cntr)
  ".jpg"
)
)
;sets render preferences and file options
(c:setrender)
; ***renders an image to the specified filename***
(c:render (vl-princ-to-string fname))
; Rotate the object
(command ".rotate" entgrp "" rotpnt deg)
(setq cntr (1+ cntr))
      ) ; repeat
      (command ".undo" "Back")
    ) ; progn
  ) ; if

; Return echo
  (setvar "cmdecho" cmdold)
  (princ)
)

Hope someone has a go at this
bemiller