Author Topic: Cant get c:repref to work in rendering code  (Read 3422 times)

0 Members and 1 Guest are viewing this topic.

bemiller1

  • Guest
Cant get c:repref to work in rendering code
« on: August 16, 2008, 04:45:20 PM »
If anyone is able to figure out why c:rpref doesn't work in the following example of code, I sure would appreciate it"
Code: [Select]
Command:
(vl-load-com)

(defun rtod (a)
  (/ (* a 180) pi)
)
;sets render 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 path here
(setq
  fname (strcat
  "D:\X\Y\Z\TestImage"
  (itoa cntr)
  ".bmp"
)
)
(c:rpref "TOGGLE" "SKIPRDLG" "OFF")
(c:rpref "ROPT" "ASCAN" 2 NIL NIL 0 1 3)
(c:rfileopt "BMP" 640 480 1.0 "C8")

; ***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)
)
Thx

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Cant get c:repref to work in rendering code
« Reply #1 on: August 16, 2008, 07:15:44 PM »
Doesn't appear that there is a command line version of rpref.
therefore
Code: [Select]
(c:rpref "TOGGLE" "SKIPRDLG" "OFF")or
Code: [Select]
(command "rpref" "TOGGLE" "SKIPRDLG" "OFF")will not work.

Perhaps someone who uses render can lend a hand but it's a little slow on the week ends.
So be patient.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

bemiller1

  • Guest
Re: Cant get c:repref to work in rendering code
« Reply #2 on: August 17, 2008, 11:40:53 AM »
Thanks for quick response, CAB
What makes this a weird problem for me is that when I enter rpref on the command line of AutoCad the render preference dialog box appears yet when inserted in AutoLisp code, with recommended handling for externally defined commands i.e. "C:"prefix it returns "no function definition: C:RPREF"

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Cant get c:repref to work in rendering code
« Reply #3 on: August 17, 2008, 01:22:08 PM »
Yes, when you try this you get nil
Code: [Select]
_$ (atoms-family 1 (list "c:rpref"))
(nil)
But after executing from the command line it returns
Code: [Select]
_$ (atoms-family 1 (list "c:rpref"))
("C:RPREF")


I think RPREF is a VBA routine and not LISP.
See this is loaded "acrender.arx"

but these don't work eather
Code: [Select]
Command: (vl-vbarun  "rpref")
_.-VBARUN Initializing VBA System...
Macro name: rpref Execution error
Command: "rpref"

Command: (vl-vbarun  "c:rpref")
_.-VBARUN
Macro name: c:rpref
Macro not found.
Command: "c:rpref"
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Cant get c:repref to work in rendering code
« Reply #4 on: August 17, 2008, 01:31:01 PM »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: Cant get c:repref to work in rendering code
« Reply #5 on: August 17, 2008, 02:34:08 PM »
(vla-SendCommand(vla-get-ActiveDocument(vlax-get-acad-object))"rpref ")
James Buzbee
Windows 8

bemiller1

  • Guest
Re: Cant get c:repref to work in rendering code
« Reply #6 on: August 18, 2008, 04:23:38 PM »
(vla-SendCommand(vla-get-ActiveDocument(vlax-get-acad-object))"rpref ")
jbuzbee,
Looks like it might work for externally defined commands. Being unfamiliar with the vla-type code I'm not totally sure how to integrate it with AutoLisp. I'll take a crack at it. Here is an attempt.
(Would appreciate any comments)
Code: [Select]
(defun C:setrender
   ()
  (vl-load-com)
  (setq pref (vla-SendCommand
       (vla-get-ActiveDocument
(vlax-get-acad-object)
       )
       "rpref"
     )
(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)
)
(defun rtod (a)
  (/ (* a 180) pi)
)
(setq deg
       (rtod (getangle rotpnt "\nEnter degrees of movement:<3> "))
)
(if (= deg nil)
  (setq deg 3)
)
(setq cntr 1)
(repeat num
; Add path here
  (setq
    fname (strcat
    "D:\X\Y\Z\TestImage"
    (itoa cntr)
    ".bmp"
  )
  )
  (c:rpref "TOGGLE" "SKIPRDLG" "OFF")
  (c:rpref "ROPT" "ASCAN" 2 NIL NIL 0 1 3)
  (c:rfileopt "BMP" 640 480 1.0 "C8")

; ***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)
  )
)
CAB I had discovered that last bit of code you found, in fact, that was what prompted me to get around problems with "command: render" and attempts to open and set a render dialog box. But now I'm stuck with this "rpref" thing.

bemiller1

  • Guest
Re: Cant get c:repref to work in rendering code
« Reply #7 on: August 18, 2008, 04:27:08 PM »
OK I found this
Render settings in LISP
CAB I had discovered that last bit of code you found, in fact, that was what prompted me to get around problems with "command: render" and attempts to open and set a render dialog box. But now I'm stuck with this "rpref" thing.

bemiller1

  • Guest
Re: Cant get c:repref to work in rendering code
« Reply #8 on: August 18, 2008, 04:35:47 PM »
Yes, when you try this you get nil
Code: [Select]
_$ (atoms-family 1 (list "c:rpref"))
(nil)
But after executing from the command line it returns
Code: [Select]
_$ (atoms-family 1 (list "c:rpref"))
("C:RPREF")


I think RPREF is a VBA routine and not LISP.
See this is loaded "acrender.arx"

but these don't work eather

Code: [Select]
Command: (vl-vbarun  "rpref")
_.-VBARUN Initializing VBA System...
Macro name: rpref Execution error
Command: "rpref"

Command: (vl-vbarun  "c:rpref")
_.-VBARUN
Macro name: c:rpref
Macro not found.
Command: "c:rpref"

Yes there is acrender.arx in my ACAD folder. There must be some way to call it up in AutoLisp. But the how-to is just a bit beyond my reach. (or my grasp)
BTW my ACAD version-2K2 in case that is a factor.

mjguzik

  • Newt
  • Posts: 30
Re: Cant get c:repref to work in rendering code
« Reply #9 on: August 18, 2008, 06:04:47 PM »
Typically, you would load an arx file by first checking if it was already loaded in the current application.  You cannot load an arx that has already been loaded in the current application session without first unloading it as arx files are application driven not per document.  See arxload and arxunload.

Code: [Select]
(if (not (member "lfafunctions.arx" (arx)))(arxload "lfafunctions.arx"))

Then within lisp you would use either use the arx command with prompts or as an arx function depending on how coded in the arx file.  An arx file is just a dll loaded within AutoCad.

Code: [Select]
;; Command method
(command "_toponotes" "ALL" "")

for arx functions with arguments
Code: [Select]
;; function method
(setq varlst (lfa_savevarlist "cmdecho" "blipmode" "PLINEWID" "osmode"))

in your case it appears that acrender.arx has "rpref" that doesn't take arguments anymore (2008) or contain the older ads "c:rpref" command.  For the few times tried it complains and keeps bringing up the dialog box.  Doesn't seem to have much support for lisp.

Have you tried importing material presets tied to layers from another drawing file?

MJG

Didge

  • Bull Frog
  • Posts: 211
Re: Cant get c:repref to work in rendering code
« Reply #10 on: August 19, 2008, 11:23:11 AM »
I've had a very quick play with your coding and got this working on my Acad 2006 - Hope it helps.

I've added the (INLIST) function to ensure that AutoCAD's rendering extension is loaded in advance.
The  usual (member (arx)...   approach can prove problematic as Autodesk have occassionally changed the name of their rendering extension.

Code: [Select]
(defun c:ani (/ INLIST rtod cmdold entgrp rotpnt num ang deg cntr)
  (defun INLIST (lst str / cnt ret)
    (setq cnt -1 ret nil)
    (repeat (length lst) (if (wcmatch (strcase (nth (setq cnt (1+ cnt)) lst)) (strcat "*" (strcase str) "*"))(setq ret 1)))
    ret
  )
  (defun rtod (a)(/ (* a 180) pi))
  (setq cmdold (getvar "cmdecho"))
  (setvar "cmdecho" 0)
  (if (not (INLIST (arx) "RENDER"))
    (if (not (arxload "acrender" nil))(progn (princ "\nError: unable to locate rendering extension")(exit)))
  )
  (if (setq entgrp (ssget))
    (progn
      (command ".undo" "Mark")
      (if (not (setq rotpnt (getpoint "\nPick rotation point:<0,0,0> "))) (setq rotpnt (list 0 0 0)))
      (if (not (setq num (getint "\nEnter number of images:<15> ")))      (setq num 15))
      (if (setq ang (getangle rotpnt "\nEnter degrees of movement:<3> ")) (setq deg (rtod ang)) (setq deg 3))
      (setq cntr 0)
      (c:rpref "DEST" "FILE")
      (c:rpref "TOGGLE" "CACHE" "OFF")
      (c:rpref "TOGGLE" "SKIPRDLG" "ON")
      (c:rpref "ROPT" "ASCAN" 2 NIL NIL 0 1 3)
      (c:rfileopt "BMP" 640 480 1.0 "C8")
      (repeat num
(c:render (strcat "C:\\TEMP\\TestImage-" (itoa (setq cntr (1+ cntr))) ".bmp"))
(command ".rotate" entgrp "" rotpnt deg)
      )
      (c:rpref "TOGGLE" "SKIPRDLG" "OFF")
      (command ".undo" "Back")
    )
  )
  (setvar "cmdecho" cmdold)
  (princ)
)
« Last Edit: August 19, 2008, 12:12:21 PM by Didge »
Think Slow......

bemiller1

  • Guest
Re: Cant get c:repref to work in rendering code
« Reply #11 on: August 19, 2008, 01:21:54 PM »
I've had a very quick play with your coding and got this working on my Acad 2006 - Hope it helps.

I've added the (INLIST) function to ensure that AutoCAD's rendering extension is loaded in advance.
The  usual (member (arx)...   approach can prove problematic as Autodesk have occassionally changed the name of their rendering extension.

Code: [Select]
(defun c:ani (/ INLIST rtod cmdold entgrp rotpnt num ang deg cntr)
  (defun INLIST (lst str / cnt ret)
    (setq cnt -1 ret nil)
    (repeat (length lst) (if (wcmatch (strcase (nth (setq cnt (1+ cnt)) lst)) (strcat "*" (strcase str) "*"))(setq ret 1)))
    ret
  )
  (defun rtod (a)(/ (* a 180) pi))
  (setq cmdold (getvar "cmdecho"))
  (setvar "cmdecho" 0)
  (if (not (INLIST (arx) "RENDER"))
    (if (not (arxload "acrender" nil))(progn (princ "\nError: unable to locate rendering extension")(exit)))
  )
  (if (setq entgrp (ssget))
    (progn
      (command ".undo" "Mark")
      (if (not (setq rotpnt (getpoint "\nPick rotation point:<0,0,0> "))) (setq rotpnt (list 0 0 0)))
      (if (not (setq num (getint "\nEnter number of images:<15> ")))      (setq num 15))
      (if (setq ang (getangle rotpnt "\nEnter degrees of movement:<3> ")) (setq deg (rtod ang)) (setq deg 3))
      (setq cntr 0)
      (c:rpref "DEST" "FILE")
      (c:rpref "TOGGLE" "CACHE" "OFF")
      (c:rpref "TOGGLE" "SKIPRDLG" "ON")
      (c:rpref "ROPT" "ASCAN" 2 NIL NIL 0 1 3)
      (c:rfileopt "BMP" 640 480 1.0 "C8")
      (repeat num
(c:render (strcat "C:\\TEMP\\TestImage-" (itoa (setq cntr (1+ cntr))) ".bmp"))
(command ".rotate" entgrp "" rotpnt deg)
      )
      (c:rpref "TOGGLE" "SKIPRDLG" "OFF")
      (command ".undo" "Back")
    )
  )
  (setvar "cmdecho" cmdold)
  (princ)
)
Fantastic! I ran it, BINGO! Now I will read carefully through your code changes and learn from a Master.
Very, Very grateful. Thanks so much,
bemiller

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Cant get c:repref to work in rendering code
« Reply #12 on: August 19, 2008, 02:15:17 PM »
Nice work Didge.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Didge

  • Bull Frog
  • Posts: 211
Re: Cant get c:repref to work in rendering code
« Reply #13 on: August 20, 2008, 05:08:12 AM »
Its a pleasure guys, I should've stressed that this coding should only operate in releases upto and including 2006.
I've yet to fathom the wonders of the new rendering engine.

Here's a few more lines worth experimenting with.

Code: [Select]
(c:rpref "STYPE" "ARENDER") - basic renderer
(c:rpref "STYPE" "ASCAN") - photoreal renderer
(c:rpref "STYPE" "ARAY") - photo raytracing renderer

(c:rpref "TOGGLE" "SHADOW" "ON")
(c:rpref "TOGGLE" "SHADOW" "OFF")

(c:rpref "TOGGLE" "SMOOTH" "ON")   - smooth shading
(c:rpref "TOGGLE" "SMOOTH" "OFF")

(c:rpref "TOGGLE" "FINISH" "ON") - render using materials
(c:rpref "TOGGLE" "FINISH" "OFF") - render without materials

(c:rpref "DEST" "FRAMEBUFFER")  - render to viewport
(c:rpref "DEST" "FILE") - render to file

(c:rfileopt "TIFF" XDIM YDIM 1 COLORS "COMP")  - file output options depend upon acad version.
(c:rfileopt "TGA" XDIM YDIM 1 COLORS 1 "COMP" "UP")
(c:rfileopt "BMP" XDIM YDIM 1 COLORS)
(c:rfileopt "PCX" XDIM YDIM 1 COLORS)
(c:rfileopt "PS" XDIM YDIM 1 COLORS)

*valid values for COLORS are   "MONO" "G8" "C8" "C16" or "C24"
« Last Edit: August 20, 2008, 05:18:35 AM by Didge »
Think Slow......

bemiller1

  • Guest
Re: Cant get c:repref to work in rendering code
« Reply #14 on: August 21, 2008, 01:47:45 PM »
Its a pleasure guys, I should've stressed that this coding should only operate in releases upto and including 2006.
I've yet to fathom the wonders of the new rendering engine.

Here's a few more lines worth experimenting with.

Code: [Select]
(c:rpref "STYPE" "ARENDER") - basic renderer
(c:rpref "STYPE" "ASCAN") - photoreal renderer
(c:rpref "STYPE" "ARAY") - photo raytracing renderer

(c:rpref "TOGGLE" "SHADOW" "ON")
(c:rpref "TOGGLE" "SHADOW" "OFF")

(c:rpref "TOGGLE" "SMOOTH" "ON")   - smooth shading
(c:rpref "TOGGLE" "SMOOTH" "OFF")

(c:rpref "TOGGLE" "FINISH" "ON") - render using materials
(c:rpref "TOGGLE" "FINISH" "OFF") - render without materials

(c:rpref "DEST" "FRAMEBUFFER")  - render to viewport
(c:rpref "DEST" "FILE") - render to file

(c:rfileopt "TIFF" XDIM YDIM 1 COLORS "COMP")  - file output options depend upon acad version.
(c:rfileopt "TGA" XDIM YDIM 1 COLORS 1 "COMP" "UP")
(c:rfileopt "BMP" XDIM YDIM 1 COLORS)
(c:rfileopt "PCX" XDIM YDIM 1 COLORS)
(c:rfileopt "PS" XDIM YDIM 1 COLORS)

*valid values for COLORS are   "MONO" "G8" "C8" "C16" or "C24"
Plenty of experimenting ahead, Thanks again! Very impressive. I'm sure it won't be much longer 'til you've fathomed the depths and wonders of the latest rendering engine.
bemiller