跳至正文
OpenAgentSkill
浏览已开放 · 目录记录日期 2026-11-21 · 自动更新和账户服务暂时关闭。
设计与 UI

revit-api-option-handlers

Supply small Autodesk Revit API callback interfaces with Nice3point.Revit.Toolkit ready-made handlers, not hand-rolled classes. USE FOR: passing IFamilyLoadOptions, IDuplicateTypeNamesHandler, or ISaveSharedCoordinatesCallback to a Revit API call. DO NOT USE FOR: constraining what a user can pick in an interactive selection, or building a dockable pane's UI element.

Nice3point · 已有静态检查记录

安装与使用

运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。

npx skills add Nice3point/revit-skills --skill revit-api-option-handlers

技能说明


name: revit-api-option-handlers description: > Supply small Autodesk Revit API callback interfaces with Nice3point.Revit.Toolkit ready-made handlers, not hand-rolled classes. USE FOR: passing IFamilyLoadOptions, IDuplicateTypeNamesHandler, or ISaveSharedCoordinatesCallback to a Revit API call. DO NOT USE FOR: constraining what a user can pick in an interactive selection, or building a dockable pane's UI element. license: MIT

Revit API Option Handlers

Several Revit API calls demand a small callback interface. Nice3point.Revit.Toolkit provides ready implementations with a default behavior and lambda or enum customization. A hand-rolled implementation of the interface is unnecessary.

When to use

  • A Revit API call requires IFamilyLoadOptions, IDuplicateTypeNamesHandler, or ISaveSharedCoordinatesCallback.

Workflow

Step 1: Family load options

document.LoadFamily(fileName, new FamilyLoadOptions(), out var family); //overwrite existing types, load from the family
document.LoadFamily(fileName, new FamilyLoadOptions(false, FamilySource.Project), out var family); // preserve values, load from the project
document.LoadFamily(fileName, UIDocument.GetRevitUIFamilyLoadOptions(), out var family); //reuse Revit's interactive prompt

The default constructor overwrites the parameter values of existing types. The (overwrite, FamilySource) constructor sets both options explicitly, and UIDocument.GetRevitUIFamilyLoadOptions() shows Revit's own dialog.

Step 2: Duplicate type names handler

var options = new CopyPasteOptions();
options.SetDuplicateTypeNamesHandler(new DuplicateTypeNamesHandler()); //default: UseDestinationTypes
options.SetDuplicateTypeNamesHandler(new DuplicateTypeNamesHandler(DuplicateTypeAction.Abort)); //fixed action
options.SetDuplicateTypeNamesHandler(new DuplicateTypeNamesHandler(args => DuplicateTypeAction.Abort)); // select the action per call

The default constructor uses the destination types. Pass a DuplicateTypeAction for a fixed action, or a lambda that returns the action per call from the args.

Step 3: Save shared coordinates callback

linkType.Unload(new SaveSharedCoordinatesCallback()); //default: SaveLinks
linkType.Unload(new SaveSharedCoordinatesCallback(SaveModifiedLinksOptions.DoNotSaveLinks)); //fixed option
linkType.Unload(new SaveSharedCoordinatesCallback(link => //select the option per link
{
    if (link.AttachmentType == AttachmentType.Overlay) return SaveModifiedLinksOptions.SaveLinks;
    return SaveModifiedLinksOptions.DoNotSaveLinks;
}));

The default constructor saves the links. Pass a SaveModifiedLinksOptions value for a fixed option, or a lambda that returns the option per link.

Step 4: Verify

Call the API with the handler and confirm the intended behavior applies — the family loads with the chosen source, the duplicate resolves as selected, or the link unloads with the chosen coordinate option.

Validation

  • The callback uses the Toolkit handler, not a hand-rolled interface implementation.
  • Customization is expressed with the lambda or enum overload, not a new class.
  • The selected default behavior matches the operation's requirement.

Common Pitfalls

PitfallCorrect approach
Writing a class that implements IDuplicateTypeNamesHandlerUse DuplicateTypeNamesHandler with a lambda returning the action.
FamilyLoadOptions not foundThe Nice3point.Revit.Toolkit package is not referenced.