Expand description
Read and write SolidWorks .sldprt part documents, and read the
component structure of .sldasm assembly documents.
SldprtCodec decodes B-rep topology, analytic and NURBS geometry,
tessellation, appearances, selected document attributes, feature history,
and feature-input records into cadmpeg_ir::CadIr. It preserves source
blocks and records provenance so supported edits can retain native data.
Support: L3 (ladder).
§Decode
use std::io::Cursor;
use cadmpeg_codec_sldprt::SldprtCodec;
use cadmpeg_ir::{Codec, DecodeOptions};
let decoded = SldprtCodec.decode(
&mut Cursor::new(bytes),
&DecodeOptions::default(),
)?;
println!("{} faces", decoded.ir().model.faces.len());
for loss in &decoded.report().losses {
eprintln!("{:?}: {}", loss.severity, loss.message);
}Decode reports can accompany a usable model. Untyped support carriers become
opaque geometry linked to retained bytes, while their resolvable topology
remains in the IR. No usable geometry yields metadata with diagnostics.
Set DecodeOptions::depth to DecodeDepth::Container to omit geometry
decoding explicitly.
Semantic Parasolid graph errors propagate as decode errors.
Codec::inspect inventories the outer blocks, section directory, cache
cells, payload families, and Parasolid schemas. It does not build model
geometry.
§Format and units
The outer container uses an 8-byte header, CRC-validated raw-DEFLATE blocks,
a fixed-cell section index, and a tail directory. Embedded Parasolid
partition and deltas streams supply the B-rep record graph. The decoder
groups related body streams by site and selects the resolved active site.
Without a resolved active site, the first site is a deterministic merge
accumulator. Alternate sites become configuration-specific bodies. Parasolid
lengths are metres; decoded CadIr coordinates are millimetres. Directions,
normals, and ratios remain dimensionless.
§Encode
use std::fs::File;
use cadmpeg_codec_sldprt::SldprtCodec;
use cadmpeg_ir::codec::write::target::TargetRequest;
use cadmpeg_ir::codec::write::Encoder;
use cadmpeg_ir::{Codec, DecodeOptions};
let mut input = File::open("part.sldprt")?;
let decoded = SldprtCodec.decode(&mut input, &DecodeOptions::default())?;
let (ir, _report, fidelity) = decoded.into_parts();
let mut output = File::create("part-edited.sldprt")?;
SldprtCodec
.plan(
cadmpeg_ir::codec::write::EncodeInput::new(&ir, Some(&fidelity)),
TargetRequest::Inherit,
)?
.write_to(&mut output)?;SldprtCodec implements cadmpeg_ir::codec::write::Encoder through
plan → write_to. Encoding
with the retained source_fidelity sidecar replays or patches the source
image. Omitting fidelity regenerates the supported source-less profile.
Supported geometry edits can patch the native partition when the entity
graph and provenance remain stable. Retained writing synchronizes supported
feature, sketch, parameter, configuration, and PMI edits. Semantic writing
returns CodecError::NotImplemented when the requested IR shape cannot be
represented.
The semantic writer supports solid bodies with at most five regions and at most six shells per solid region, sheet bodies with one shell per region, analytic and non-periodic NURBS carriers, selected metadata and feature records, base colors, and sequential triangle-strip tessellation. It bakes right-handed rigid body transforms into geometry.
Modules§
- exact_
ledger - Opt-in exact-read ledger for
.sldprtParasolid stream bodies.
Structs§
- Sldprt
Codec - Codec for
SolidWorks.sldprtpart documents.