Scheme Extensions

 

 

Technical Article


Scheme is a public domain programming language, based on the LISP language, that uses an interpreter to run commands. ACIS provides extensions (written in C++) to the native Scheme language that can be used by an application to interact with ACIS through its Scheme Interpreter. The C++ source files for ACIS Scheme extensions are provided with the product. Spatial's Scheme based demonstration application, Scheme ACIS Interface Driver Extension (Scheme AIDE), also uses these Scheme extensions and the Scheme Interpreter.

face:offset-loops

Action
Offsets the loops in a face by the specified amount.

Filename
scm/scmext/swp/swp_scm.cpp

APIs
api_offset_planar_face_loops

Syntax
(face:offset-loops input-ent offset
    [gap-type [use-transform] [acis-opts]])

Arg Types
input-ent face
offset real
gap-type integer
use-transform transform
acis-opts acis-options

Returns
entity

Description
Offsets the loops in a face, input-ent, by the specified amount given in offset. The default gap-type at the corners is natural (2), but gap-type can be changed to corner (0) or arc (1). The use-transform is also optional and specifies where the output entity is to be transformed to.

Arguments
input-ent is the face that needs to be offset.
 
offset specifies the amount to be removed.
 
gap-type specifies the type of gap that can be corner(0) or arc(1).
 
use-transform is an optional argument that specifies where the output entity is to be transformed .
 
acis-opts contains versioning and journaling information.
; face:offset-loops
; Create a face to offset.
(define f1 (face:plane (position 0 0 0) 10 15))
;; f1
(define f2 (face:offset-loops f1 15))
;; f2
(define f3 (face:offset-loops f1 25 1))
;; f3
; OUTPUT Example

Figure. face:offset-loops

[Top]


project:wire

Action
Projects a wire body onto a manifold or nonimanifold sheet body.

Filename
scm/scmext/swp/swp_scm.cpp

APIs
api_check_wire_self_inters, api_project_wire

Syntax
(project:wire wire body vector distance [acis-opts])

Arg Types
wire wire-body
body entity
vector gvector
distance real
acis-opts acis-options

Returns
entity

Description
The projection is imprinted onto the body. This means, for example, a circle could be projected onto the face of a block and then the resulting circular face swept to make a post on the block.
The project:wire extension is implemented using a rigid sweep and imprint. First the wire is swept by the distance in the direction specified by vector, then the swept body and the given body are imprinted. It is not necessary that the wire being projected be planar.

Arguments
wire gives the wire body in the Scheme Component.
 
body is one of the entities in a Scheme Component.
 
vector specifies the direction vector.
 
distance gives the value that needs to be swept by the wire.
 
acis-opts  gives the versioning and journaling information.
; project:wire
; Create a cylinder
(define cylinder1
    (solid:cylinder (position -50 0 50)
    (position 50 0 50) 25))
;; cylinder1
; cylinder1 => #[entity 2 1]
; Create an ellipse
(define ellipse1
    (edge:elliptical (position 0 0 0)
    (position 20 0 0) 1 0 360))
;; ellipse1
; create a wire body of the ellipse1
(define wire1 (wire-body (list ellipse1)))
;; wire1
(zoom-all)
;; #[view 5375160]
; OUTPUT Original

; Project wire1 onto one side of cylinder1
(define project (project:wire wire1 cylinder1
    (gvector 0 0 1) 50))
;; project
; OUTPUT Result

Figure. project:wire

[Top]


sweep:get-path

Action
Returns the path used to create a swept surface.

Filename
scm/scmext/swp/swp_scm.cpp

APIs
api_make_ewire

Syntax
(sweep:get-path in-obj)

Arg Types
in-obj face

Returns
entity

Description
The entity that is returned is a path equivalent to what was used to create the original sweep.

Arguments
in-obj is of the type face.
; sweep:get-path
; Create some geometry.
(define e1 (edge:spline (list (position 0 0 0)
    (position 2 5 10)) (gvector 0 0 1)
    (gvector 0 0 1)))
;; e1
(define e2 (edge:linear (position 0 0 -10)
    (position 0 0 0)))
;; e2
(define path (wire-body (list e1 e2)))
;; path
(define reverse (wire:reverse path))
;; reverse
(define prof (wire-body (edge:ellipse
    (position 0 0 -4.5) (gvector 0 0 1) 0.9)))
;; prof
(zoom-all)
;; #[view 1077017040]
(render:rebuild)
;; ()
(define start (position -1.5 -1.5 6.5))
;; start
(define start-mark (solid:sphere start 0.15))
;; start-mark
(entity:set-color start-mark 2)
;; ()
(define end (position -1.5 -1.5 -6.5))
;; end
(define end-mark (solid:sphere end 0.15))
;; end-mark
(entity:set-color end-mark 1)
;; ()
(define opts (sweep:options "portion"
    "between_points" start end))
;; opts
(define sw (sweep:law prof path opts))
;; sw
(define sw-path (sweep:get-path
    (car (entity:faces sw))))
;; sw-path
(env:set-highlight-color 1)
;; ()
(define highlight (entity:set-highlight sw-path #t))
;; highlight
; OUTPUT Example

Figure. sweep:get-path

[Top]


sweep:get-profile

Action
Returns the profile used in a sweeping operation.

Filename
scm/scmext/swp/swp_scm.cpp

APIs
api_make_ewire

Syntax
(sweep:get-profile in-obj)

Arg Types
in-obj face

Returns
entity
Arguments
in-obj  is of the type face.
; sweep:get-profile
; Create some geometry
(define e1 (edge:spline (list (position 0 0 0)
    (position 2 5 10)) (gvector 0 0 1)
    (gvector 0 0 1)))
;; e1
(define e2 (edge:linear (position 0 0 -10)
    (position 0 0 0)))
;; e2
(define path (wire-body (list e1 e2)))
;; path
(define reverse (wire:reverse path))
;; reverse
(define prof (wire-body (edge:ellipse
    (position 0 0 -4.5) (gvector 0 0 1) 0.9)))
;; prof
(zoom-all)
;; #[view 1077017040]
(render:rebuild)
;; ()
(define start (position -1.5 -1.5 6.5))
;; start
(define start-mark (solid:sphere start 0.15))
;; start-mark
(entity:set-color start-mark 2)
;; ()
(define end (position -1.5 -1.5 -6.5))
;; end
(define end-mark (solid:sphere end 0.15))
;; end-mark
(entity:set-color end-mark 1)
;; ()
(define opts (sweep:options "portion"
    "between_points" start end))
;; opts
(define sw (sweep:law prof path opts))
;; sw
(define sw-profile (sweep:get-profile
    (car (entity:faces sw))))
;; sw-profile
(define highlight (entity:set-highlight
    sw-profile #t))
;; highlight

[Top]


sweep:law

Action
Creates a surface or solid by sweeping a profile along a path.

Filename
scm/scmext/swp/swp_scm.cpp

APIs
api_check_wire_self_inters, api_sweep_with_options

Syntax
(sweep:law profile {path | distance | vector | axis}
    [sweep-options])

Arg Types
profile wire-body | face | edge
path wire-body | edge
distance real
vector gvector
axis position . vector
sweep-options Sweep_Options

Returns
entity

Errors
An error is reported if the result of the sweep operation is incomplete lateral faces or invalid topology.

Description
The sweep:law extension creates a sheet body or solid body from a profile and a path. The path can be defined as a path, a distance, a vector, or an axis (position and vector).

The sweep:law extension is complicated, but not difficult. We have presented, explained, and provided examples for a variety of scenarios and option combinations to get you started, but can not provide every one. There are also some that will simply fail (causes self-intersections). It is up to you to experiment and explore whatever remaining scenarios and option combinations you can design.

Numerous additional sweep:law Scheme examples are provided in the Technical Articles section.

Arguments
The argument profile is a pointer to a wire-body, a face, or an edge, which in turn, defines the sweep geometry and becomes the base of the solid or the edge of the surface.
 
The argument path is a wire-body or an edge along which the profile is swept. path can be defined as a distance if profile is a planar face. path can be defined as a vector if "rail_law" is used (no twist). path can be defined as a axis (defined as position and vector) if "rail_law" is used (no twist).
 
The distance argument defines the distance to sweep along the face normal.
 
The vector argument defines the direction and distance to sweep.
 
The axis argument is a position and vector that defines the axis to revolve around. The amount to revolve is controlled by the "sweep:angle" option.
 
sweep-options is an optional argument that contains the Sweep_Options data structure. This data structure is created by sweep:options. If sweep-options is not specified, default sweep option values are used. The defaults are as follows:
-        Create a solid.
-        Draft angle is 0.
-        Gap type is 2 (natural).
-        Twist angle is 0.
-        Rail law is minimum rotation.
If you set the option "sweep_selfint" to TRUE, the code checks to see if the sweep path intersects itself. If it does, the sweep errors out. But, it allows the sweep path to intersect with the original body and that causes self intersections.
; sweep:law - Example 1
; Sweeping an edge along a vector
(define edge1 (edge:linear (position 10 0 0)
    (position 10 10 0)))
;; edge1
; OUTPUT Original


(define sweep1 (sweep:law edge1 (gvector 0 0 10)))
;; sweep1
; Convert the single-sided entity into double-sided.
(define 2dconvert (sheet:2d sweep1))
;; 2dconvert
; OUTPUT Result

Figure. sweep:law - Example 1 - Sweep an edge along a Vector
; sweep:law - Example 2
; Sweeping a face a distance
(part:clear)
;; #t
(define face2 (face:plane (position 0 20 0)
    10 10 (gvector 0 0 1)))
;; face2
; OUTPUT Original

(define sweep3 (sweep:law face2 5))
;; sweep3
; OUTPUT Result

Figure. sweep:law - Example 2 - Sweep a Face

; sweep:law - Example 3
; Revolving a face.
(part:clear)
;; #t
; Create a solid block.
(define block1 (solid:block (position -10 -10 0)
    (position 25 25 25)))
;; block1
; Separate faces from block1.
(define entities (entity:faces block1))
;; entities
; Extract a single planar face.
(define face1 (car (cdr (cdr entities))))
;; face1
; Verify transform applied.
(define fix (entity:fix-transform block1))
;; fix
; OUTPUT Original

; Define extent of sweep.
(define opts (sweep:options "sweep_angle" 60))
;; opts
; Revolve the planar face by a gvector around a
; position.
(define sweep1 (sweep:law face1
    (position -10 -10 -10)
    (gvector 1 0 0) opts))
;; sweep1
; OUTPUT Result

Figure. sweep:law - Example 3 - Revolving a Face

; sweep:law - Example 4
; Revolving a wire.
(part:clear)
;; #t
; Create 4 linear edges.
(define edge1 (edge:linear (position 0 0 0)
    (position 20 0 0)))
;; edge1
(define edge2 (edge:linear (position 20 0 0)
    (position 20 20 0)))
;; edge2
(define edge3 (edge:linear (position 20 20 0)
    (position 0 20 0)))
;; edge3
(define edge4 (edge:linear (position 0 20 0)
    (position 0 0 0)))
;; edge4
; Create a wirebody from the 4 edges.
(define wirebody (wire-body
    (list edge1 edge2 edge3 edge4)))
;; wirebody
; OUTPUT Original

; Create a solid by revolving the wire body.
(define sweep1 (sweep:law wirebody
    (position 0 0 0) (gvector 0 1 0)
    (sweep:options "sweep_angle" 60)))
;; sweep1
; OUTPUT Result

Figure. sweep:law - Example 4 - Revolving a Wire

; sweep:law - Example 5
; Sweeping a Planar Face.
(part:clear)
;; #t
; Create a solid block.
(define block1 (solid:block (position -10 -10 -10)
    (position 30 30 30)))
;; block1
; Get a list of the solid block's faces.
(define faces (entity:faces block1))
;; faces
; Select a single face to sweep
(define face (car (cdr (cdr faces))))
;; face
; OUTPUT Original


; Create a new solid by sweeping the face along a
; gvector.
(define sweep1 (sweep:law face 7.5
    (sweep:options "draft_angle" -45)))
;; sweep1
; OUTPUT Result

 

Figure. sweep:law - Example 5 - Sweeping a Planar Face

[Top]


sweep:options

Action
Sets the options in the data structure to be used by sweep:law.

Filename
scm/scmext/swp/swp_scm.cpp

APIs
None

Syntax
(sweep:options "name-of-option"
    {value | location direction})

Arg Types
"name-of-option" string
value string | law | real | gvector | entity | boolean | integer | body | face
location position
direction gvector

Returns
Sweep_Options

Description
The sweep:options scheme extension defines elements in the Sweep_Options data structure that are later used for the sweep:law operation.

Arguments
name-of-option is a string placed within quotation marks.

If value is a real, it does not require delimiters. If value is a string representing a law, it should be enclosed in quotation marks. If value is a law, only the variable name for the law is required. Multiple pairs of name-of-option and value can be specified simultaneously.
(sweep:options "draft_angle" 5 "solid" #f)

The options are explained in detail in the discussion topic Sweeping with Options and include:

bool_type (string): Specifies the boolean operation to be used along with the option sweep_to_body. Valid values are "limit", "unite", "intersect", "subtract" and "keep_both". Default is "limit".
 
close_to_axis (boolean): If a revolve operation is required, and the profile is open and far away from the rotation axis, it will close the gap that could be produced between the profile and the axis. Default is #f.
 
cut_end_off (boolean): Cuts the end of the swept body squarely, with a perpendicular plane to the end of the profile. Default value is #f.
 
draft_angle (real): Defines the draft angle in degrees. Default is 0.0.
 
draft_hole (string): Specifies the orientation of the draft angle in interior holes in faces being swept with draft: "no_draft", "with_periphery", "against_periphery" and "by_angle". If "by_angle" is specified, a draft_hole_angle must be supplied, in degrees. Default is "against_periphery".
 
draft_law (law): The draft angle can be defined in the form of a law. Default is none.
 
draft_repair (string): Specifies the type of repairs done internally to complete a draft operation: "no_repair", "first_self_intersection", "first_degeneracy", "self_intersection", "degeneracy", "error_on_repair". The default value is "degeneracy".
 
end_draft_dist (real): Alternative way to set up a draft operation, by specifying the final offset distance. Default is zero.
 
gap_type (string): Specifies the type of face that will fill up the gaps made by draft operations. It is of type "EXTENDED", "ROUNDED" or "NATURAL". Default value is "NATURAL".
 
keep_branches (boolean): Option to keep extra branches produced in sweep_to_body or to_face operations. Default value is #f.
 
keep_law (law): The resulting graph of the sweep_to_body or to_face operations can be defined using a customized law. Default is none.
 
keep_start_face (boolean): Specify if in a closed path operation or a full revolution revolve operation the original profile face should remain topologically in the same place, instead of getting absorbed by the new closed body. Default value is #f.
 
miter_type (string): The type of mitering operation to be used: "old", "crimp", "bend" or "new". If "bend" is specified, a real value for the miter_amount should be provided also. Default is "new".
 
portion (string): Specifies the portions of the path to be used: "as_is", "to_profile", "from_profile", "between_points", "sweep_to", "entire_path". If "between_points" is specified, the portion_start and portion_end positions must be supplied. If "sweep_to" is specified, a position should be supplied. Default is "entire_path".
 
rail_laws (law || (list law1 law2 ...)): Laws that define the rails (for orientation) for the operation. If a list is provided, it will define the rail_law_num. Default is none.
 
rigid (boolean): Orientation of the profile at miter planes or end of path. Default value is #f.
 
self_int_test (integer): Specify if a self intersecting surface check should be performed and if the body is allowed to complete even when a self-intersecting situation has been found. If 1 is specified, check and error occur, if 0 is specified, no check is performed, is 2 is specified, check is performed but only warns about self intersecting surfaces. Default value is 1.
 
simplify (boolean): Simplify when possible surfaces into lighter forms. Default is #t.
 
solid (boolean): The result body should be a closed solid body when possible. Default value is #t.
 
start_draft_dist (real): Start offset distance used in draft operations. Default is 0.0.
 
steps (integer): Number of linear divisions in revolve operations. Default value is 0.
 
sweep_angle (real): Revolve angle, in degrees. Default is 360.
 
to_body (body): Defines a body that will limit the sweep operation. Default is none.
 
to_face (face): Defines a surface from an input face that will limit the sweep operation. Default is none.
 
twist_angle (real): Defines an angle that the profile will twist by the end of the sweep operation in degrees. Default is 0.0.
 
twist_law (law): The twist angle can be defined with a law. Default is NULL.
 
two_sided or 2d (boolean): Specifies if a sheet body is created, if it should be one or double sided. Default is #t.
 
See also sweep:test for a demonstration of all sweep options.
 
The sweep option draft_angle is a real number that represents the angle with which the swept profile is to draft while sweeping. Drafting has two mutually exclusive options which are draft_angle and draft_law. The default for draft_angle is 0. One application of drafting is for molded items. As the profile is swept, the ending profile has been offset by an equal distance, which helps with the removal of the item from a mold. Extreme draft angles or draft laws can result in errors due to self-intersecting bodies, incomplete lateral faces (likely at corners), and/or unsupported topologies.
 
The sweep option end_draft_dist defines where to stop the end of the draft.
 
Twisting has two mutually exclusive options: twist_angle and twist_law. Only one can be set by the sweep:options extension. When one is set, the other is cleared out. The default is twist_angle set to 0. Moreover, if the rail_law array was set up using law:make-rails and it included a twist law, then rail_law would be mutually exclusive with the twist_law option (i.e., do not use the twist law more than once).

Limitations
The two twist options are mutually exclusive. When the rail law array includes a twist law, do not apply another twist law as part of a sweep option. Some options only appear if they are explicitly specified out or are non-selected and mutually exclusive.
; sweep:options
; Define the sweep options to use.
; These are the default options.
(define sweep1 (sweep:options))
;; sweep1
; Define new sweep options where all values are
; default except the draft_law.
(define s1 (sweep:options
    "draft_law" "sin(x)"))
;; s1
; Define another set of sweep options that is almost
; the same as s1 except for a minor change
; to the gap-type
(define s2 (sweep:options
    "gap_type" "n" "draft_law" "sin(x)"))
;; s2

; Create a sweep path from points
(define plist1 (list (position 0 0 0)
    (position 20 0 0) (position 20 20 0)
    (position 20 20 20)))
;; plist1
(define start1 (gvector 1 0 0))
;; start1
(define end1 (gvector 0 0 10))
;; end1
(define path1 (edge:spline plist1
    start1 end1))
;; path1
(define law1 (law "cur (edge1)" path1))
;; law1
(define rail1 (law "minrot (law1,vec (0,-1,0))"
    law1))
;; rail1
(define edgelist1 (list (edge:linear (position 0 3 3)
    (position 0 3 -3)) (edge:linear (position 0 3 -3)
    (position 0 -3 -3)) (edge:linear
    (position 0 -3 -3) (position 0 -3 3))
    (edge:linear (position 0 -3 3)
    (position 0 3 3))))
;; edgelist1
(define profile1 (wire-body edgelist1))
;; profile1
(define sweep1 (sweep:law profile1 path1
    (sweep:options "rail_law" rail1)))
;; sweep1

[Top]