Every now and then, a CoCreate Modeling user needs some functionality which isn't in the product
yet, or at least not precisely in the shape and form she needs it. For example, in a recent
forum discussion, someone
asked for a way to batch-convert CoCreate Modeling package files into STEP format.
The
CoCreate Task Agent provides
such functionality, but since it is an add-on module
at extra cost, only some customers have it available to them. But that's no reason for despair,
as it's pretty simple to add new functionality to the product.
Here's my take on the problem. My solution doesn't have any kind of glitzy UI,
it doesn't handle errors, it's not optimized for performance - but it shows how the
approach works, and that's all I wanted to accomplish.
;; (C) 2009 Claus Brod
;;
;; Demonstrates how to convert models into STEP format
;; in batch mode. Assumes that STEP module has been activated.
(in-package :clausbrod.de)
(use-package :oli)
(export 'pkg-to-step)
(defun convert-one-file(from to)
(delete_3d :all_at_top)
(load_package from)
(step_export :select :all_at_top :filename to :overwrite)
(undo))
(defun pkg-to-step(dir)
"Exports all package files in a directory into STEP format"
(dolist (file (directory (format nil "~A/*.pkg" dir)))
(let ((filename (namestring file)))
(convert-one-file filename (format nil "~A.stp" filename)))))
To use this code:
- Run CoCreate Modeling
- Activate the STEP module
- Load the Lisp file
- In the user input line, enter something like
(clausbrod.de:pkg-to-step "c:/allmypackagefiles")
For each package (
*.pkg
) file in the specified directory, a STEP file will be generated in the
same directory. The name of the STEP file is the original filename with
.stp
appended to it.
In
pkg-to-step
, the code iterates over the list of filenames returned from
(directory)
. For each package file,
convert-one-file
is called, which performs
the actual conversion:
- Delete all objects in memory (so that they don't interfere with the rest of the process)
- Load the package file
- Save the model in memory out to a STEP file
- Undo to the state of affairs before loading the package file
For each of those steps, we use one of the built-in commands, i.e.
delete_3d
,
load_package
,
step_export
and
undo
. These are the kind of commands which are captured in a recorder
file when you run CoCreate Modeling's recorder utility. Around those commands, we use
some trivial Common Lisp glue code - essentially,
dolist over
the results of
directory. And that's all, folks
Astute readers will wonder why I use
undo
after the load operation rather than
delete_3d
the model.
undo
is in fact more efficient in this kind of scenario, which is
an interesting story in and of itself - and shall be told some other day.