Edit
Attach
Printable
topic end
<!-- * Set TOPICTITLE = #define private public - STEP files for the masses (29 Jul 2009) --> <style type="text/css"> pre {background-color:#ffeecc;} </style> %STARTINCLUDE% <a name="29"></a> ---+++ [[DefinePrivatePublic20090729StepConversion][STEP files for the masses]] (29 Jul 2009) <summary> Every now and then, a <nop>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 <a href="http://cocreateusers.org/forum/showthread.php?p=22199">forum discussion</a>, someone asked for a way to batch-convert <nop>CoCreate Modeling package files into STEP format.</summary> The [[http://www.ptc.com/products/cocreate/task-agent][<nop>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. <pre> <font color="#0000ff">;; (C) 2009 Claus Brod</font> <font color="#0000ff">;;</font> <font color="#0000ff">;; Demonstrates how to convert models into STEP format</font> <font color="#0000ff">;; in batch mode. Assumes that STEP module has been activated.</font> <font color="#6a5acd">(</font><font color="#804040"><b>in-package</b></font> :clausbrod.de<font color="#6a5acd">)</font> <font color="#6a5acd">(</font><font color="#804040"><b>use-package</b></font> :oli<font color="#6a5acd">)</font> <font color="#6a5acd">(</font><font color="#804040"><b>export</b></font> <font color="#6a5acd">'</font><font color="#008080">pkg-to-step</font><font color="#6a5acd">)</font> <font color="#6a5acd">(</font><font color="#804040"><b>defun</b></font> convert-one-file<font color="#6a5acd">(</font>from to<font color="#6a5acd">)</font> <font color="#6a5acd">(</font>delete_3d :all_at_top<font color="#6a5acd">)</font> <font color="#6a5acd">(</font>load_package from<font color="#6a5acd">)</font> <font color="#6a5acd">(</font>step_export :select :all_at_top :filename to <font color="#2e8b57"><b>:overwrite</b></font><font color="#6a5acd">)</font> <font color="#6a5acd">(</font>undo<font color="#6a5acd">))</font> <font color="#6a5acd">(</font><font color="#804040"><b>defun</b></font> pkg-to-step<font color="#6a5acd">(</font>dir<font color="#6a5acd">)</font> <font color="#ff00ff">"Exports all package files in a directory into STEP format"</font> <font color="#6a5acd">(</font><font color="#804040"><b>dolist</b></font> <font color="#6a5acd">(</font>file <font color="#6a5acd">(</font><font color="#804040"><b>directory</b></font> <font color="#6a5acd">(</font><font color="#804040"><b>format</b></font> <font color="#804040"><b>nil</b></font> <font color="#ff00ff">"~A/*.pkg"</font> dir<font color="#6a5acd">)))</font> <font color="#6a5acd">(</font><font color="#804040"><b>let</b></font> <font color="#6a5acd">((</font>filename <font color="#6a5acd">(</font><font color="#804040"><b>namestring</b></font> file<font color="#6a5acd">)))</font> <font color="#6a5acd">(</font>convert-one-file filename <font color="#6a5acd">(</font><font color="#804040"><b>format</b></font> <font color="#804040"><b>nil</b></font> <font color="#ff00ff">"~A.stp"</font> filename<font color="#6a5acd">)))))</font></font> </pre> To use this code: * Run <nop>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: <table border="1"> <tr> <th>Step</th> <th>Command</th> </tr> <tr> <td>Delete all objects in memory (so that they don't interfere with the rest of the process)</td> <td><tt>delete_3d</tt></td> </tr> <tr> <td>Load the package file</td> <td><tt>load_package</tt></td> </tr> <tr> <td>Save the model in memory out to a STEP file</td> <td><tt>step_export</tt></td> </tr> <td>Revert to the state of affairs as _before_ loading the package file</td> <td><tt>undo</tt></td> </tr> </table> 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 <nop>CoCreate Modeling's recorder utility.) Around those commands, we use some trivial Common Lisp glue code - essentially, [[http://l1sp.org/cl/dolist][dolist]] over the results of [[http://l1sp.org/cl/directory][directory]]. And that's all, folks :D 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. --- %STOPINCLUDE% %COMMENT{type="below" nonotify="on"}% ---
to top
End of topic
Skip to action links
|
Back to top
Edit
|
Attach image or document
|
Printable version
|
Raw text
|
Refresh
|
More topic actions
Revisions: | r1.2 |
>
|
r1.1
|
Total page history
|
Backlinks
You are here:
Blog
>
DefinePrivatePublic20090729StepConversion
r1.2 - 29 Jul 2009 - 17:14 -
ClausBrod
to top
Blog
This site
2017
:
12
-
11
-
10
2016
:
10
-
7
-
3
2015
:
11
-
10
-
9
-
4
-
1
2014
:
5
2013
:
9
-
8
-
7
-
6
-
5
2012
:
2
-
10
2011
:
1
-
8
-
9
-
10
-
12
2010
:
11
-
10
-
9
-
4
2009
:
11
-
9
-
8
-
7
-
6
-
5
-
4
-
3
2008
:
5
-
4
-
3
-
1
2007:
12
-
8
-
7
-
6
-
5
-
4
-
3
-
1
2006:
4
-
3
-
2
-
1
2005:
12
-
6
-
5
-
4
2004:
12
-
11
-
10
C++
CoCreate Modeling
COM & .NET
Java
Mac
Lisp
OpenSource
Scripting
Windows
Stuff
Changes
Index
Search
Maintenance
Impressum
Datenschutzerklärung
Home
Webs
Atari
Blog
Claus
CoCreateModeling
Klassentreffen
Main
Sandbox
Sommelier
TWiki
Xplm
Jump:
Copyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback