Edit
Attach
Printable
topic end
<!-- * Set TOPICTITLE = #define private public - Expanding Drawlists (14 Nov 2017) --> <style type="text/css"> pre {background-color:#ffeecc;} </style> %STARTINCLUDE% <a name="14"></a> ---+++ [[DefinePrivatePublic20171114ExpandingDrawlists][Expanding drawlists]] (14 Nov 2017) <summary> Last week, someone <a href="https://ww3.cad.de/foren/ubb/Forum92/HTML/000883.shtml">posted a question to a customer forum</a> for <nop>CoCreate Modeling (aka PTC Creo Elements/Direct Modeling), providing the perfect excuse for me to dabble with LISP again. </summary> The question centered on how to expand the results of the API call =sd-inq-vp-drawlist-objects= which returns a list of all currently visible objects. <div style="float:right;"> <img src="%ATTACHURLPATH%/drawlist.png" alt="drawlist.png" width="200" height="234" /> </div> In the example to the right, the following objects are checked, and are therefore visible: * Assembly "a1" * Part "cone" in assembly "a1" * Part "cube" in assembly "a1" * Part "backplate" in assembly "act_assy" * Part "housing" in assembly "act_assy" * Part "pistonhead" in assembly "act_assy/pst_subassy" * Part "shaft" in assembly "act_assy/pst_subassy" To reduce the amount of data it has to return, =sd-inq-vp-drawlist-objects= "compresses" its result as follows: * If all objects below an assembly are checked (=visible), only the assembly is returned * In partially visible assemblies, visible objects are returned individually So in our example, =sd-inq-vp-drawlist-objects= would return a list containing: * /a1 * /act_assy/backplate * /act_assy/housing * /act_assy/pst_subassy This representation is perfectly fine for many purposes, but in the specific circumstances of the forum post, the user needed a way to "uncompress" the result, and wasn't interested in the assemblies, only in parts. So in the given example, the desired output would have been: * /a1/cone * /a1/cube * /act_assy/backplate * /act_assy/housing * /act_assy/pst_subassy/piston-head * /act_assy/pst_subassy/shaft Assembly structures can be highly nested, of course, and so a recursive solution is needed. My first solution revisited an approach I used in a [[http://www.clausbrod.de/cgi-bin/view.pl/Blog/DefinePrivatePublic20150404FlacheHierarchien][previous blog post]] which discussed how to recurse over a hierarchy of objects and build a flat list from it. <style type="text/css"> <!-- pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color:#ffeecc; } body { font-family: monospace; color: #000000; background-color: #ffffff; } * { font-size: 1em; } .String { color: #4a708b; } .Statement { color: #b03060; font-weight: bold; } .Type { color: #008b00; font-weight: bold; } .Special { color: #8a2be2; } --> </style> <div> <pre id='vimCodeElement'> <span class="Special">(</span><span class="Statement">in-package</span> :de.clausbrod.expanddrawlist<span class="Special">)</span> <span class="Special">(</span><span class="Statement">use-package</span> :oli<span class="Special">)</span> <span class="Special">(</span><span class="Statement">defun</span> flatten-assembly-mapcan<span class="Special">(</span>node<span class="Special">)</span> <span class="Special">(</span><span class="Statement">cons</span> node <span class="Special">(</span><span class="Statement">mapcan</span> <span class="Type">#'flatten-assembly-mapcan</span> <span class="Special">(</span>sd-inq-obj-children node<span class="Special">))))</span> <span class="Special">(</span><span class="Statement">defun</span> expand-objects<span class="Special">(</span>objects<span class="Special">)</span> <span class="Special">(</span><span class="Statement">loop</span> for obj in objects <span class="Statement">nconc</span> <span class="Special">(</span><span class="Statement">remove-if-not</span> <span class="Type">#'sd-inq-part-p</span> <span class="Special">(</span>flatten-assembly-mapcan obj<span class="Special">))))</span> <span class="Special">(</span><span class="Statement">defun</span> show-part<span class="Special">(</span>p<span class="Special">)</span> <span class="Special">(</span>display <span class="Special">(</span>sd-inq-obj-pathname p<span class="Special">)))</span> <span class="Special">(</span><span class="Statement">let</span> <span class="Special">((</span>displayed-objects <span class="Special">(</span>sd-inq-vp-drawlist-objects <span class="Special">(</span>sd-inq-current-vp<span class="Special">))))</span> <span class="Special">(</span><span class="Statement">mapc</span> <span class="Type">#'show-part</span> <span class="Special">(</span>expand-objects displayed-objects<span class="Special">)))</span> </div> This worked and returns lists as described above. However, if you're actually not really interested in those intermediate lists, but instead simply want to visit all visible parts in the assembly tree and execute some action for each of those parts, then the problem can be solved more succinctly: <div> <pre id='vimCodeElement'> <span class="Special">(</span><span class="Statement">in-package</span> :de.clausbrod.expanddrawlist<span class="Special">)</span> <span class="Special">(</span><span class="Statement">use-package</span> :oli<span class="Special">)</span> <span class="Special">(</span><span class="Statement">defun</span> show-part<span class="Special">(</span>p<span class="Special">)</span> <span class="Special">(</span>display <span class="Special">(</span>sd-inq-obj-pathname p<span class="Special">)))</span> <span class="Special">(</span><span class="Statement">defun</span> visit-parts<span class="Special">(</span>obj<span class="Special">)</span> <span class="Special">(</span><span class="Statement">if</span> <span class="Special">(</span>sd-inq-part-p obj<span class="Special">)</span> <span class="Special">(</span>show-part obj<span class="Special">)</span> <span class="Special">(</span><span class="Statement">mapc</span> <span class="Type">#'visit-parts</span> <span class="Special">(</span>sd-inq-obj-children obj<span class="Special">))))</span> <span class="Special">(</span><span class="Statement">let</span> <span class="Special">((</span>displayed-objects <span class="Special">(</span>sd-inq-vp-drawlist-objects <span class="Special">(</span>sd-inq-current-vp<span class="Special">))))</span> <span class="Special">(</span><span class="Statement">mapc</span> <span class="Type">#'visit-parts</span> displayed-objects<span class="Special">)))</span> </div> --- %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.1
|
Total page history
|
Backlinks
You are here:
Blog
>
DefinePrivatePublic20171114ExpandingDrawlists
r1.1 - 14 Nov 2017 - 20:39 -
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