Scheme Examples of Part Management


These Scheme examples show how you can use part.scm and attribut.scm for part management.

Creating, Modifying, Saving, and Loading Parts

The following example from the part.scm file clears the existing default part, adds entities, deletes other entities, inquires the entities within the part, and then saves and restores the part.

; - part.scm -------------------------------------------------
; Modify the default part, then save, clear, restore the part.
; ------------------------------------------------------------
(part:clear)

;; Create some entities in the empty part
(define blk (solid:block (position 0 0 0) (position 20 30 40)))
(define sph (solid:sphere (position 0 0 0) 10))
(define cyl (solid:cylinder (position 10 15 40)
    (position 10 15 50) 5))

;; List the entities in the part
(display (part:entities))
(newline)

;; Delete one of the entities and display the results
(entity:delete sph)
(display (part:entities))
(newline)

;; Save and clear the part
(part:save "part.sat")
(part:clear)
(display (part:entities))
(newline)

;; Restore the part
(part:load "part.sat")
(display (part:entities))
(newline)

Example. Basic Part Management

Assigning Name-Value Attribute Pairs

The following example from the attribut.scm file creates a block, and then attaches an attribute that specifies its volume, and a second attribute that specifies its composition.

; - attribut.scm ----------------------------------------------
; Assign two name/value attribute pairs to an entity, then
; modify them.
; Demonstrate non-volatility by saving, restoring, and
; displaying the entity.
; -------------------------------------------------------------

;; Create a new part so we know what's there when we reload
(part:set-active (part:new))

;; Create a block and add some attributes
(define blk (solid:block (position 0 0 0) (position 20 30 40)))
(attrib:add blk "name" "cornerstone")
(attrib:add blk "volume" 24000)

;; Display the attributes
(display (attrib:get blk))

;; Add and modify attributes
(attrib:replace blk "volume" 12000)
(attrib:add blk "name" "granite")
(display (attrib:get blk))

;; Remove all name attributes
(attrib:remove blk "name")
(display (attrib:get blk))

;; Save and restore part
(part:save "attrib.sat")
(part:clear)
(part:load "attrib.sat")

;; Display attributes for first restored entity
(display (attrib:get (car (part:entities))))

Example. Name-Value Attribute Pairs

[Top]