Welcome
Collapse Getting StartedGetting Started
Overview
Expand Types of SOLIDWORKS API ApplicationsTypes of SOLIDWORKS API Applications
Expand SOLIDWORKS API Object Model and Class HierarchySOLIDWORKS API Object Model and Class Hierarchy
Collapse Programming with the SOLIDWORKS APIProgramming with the SOLIDWORKS API
Expand Add-insAdd-ins
API Dependent on SOLIDWORKS Being Visible
Arrays
Attributes Imported from ACIS SAT Files
Bitmasks
Block Definitions and Block Instances
Bodies in Body Folders
BOOL and VARIANT_BOOL
Bounding Box and Note Text
COM vs. Dispatch
CommandManager and CommandGroups
Components, Configurations, and Suppression States
Compound Note
ComVisibleAttribute in in VB.NET and C# Macros and Add-ins
Controls, Visual Basic 6.0, and Windows XP
Drawing Views and Model Entities
Early and Late Binding
Expand EventsEvents
Features of Components
Helper Functions
Hole Wizard Features and Objects
IDispatch Object Arrays as Input in .NET
Implementation Guidelines
Import and Export File Options
In-process Methods
Instantiate ActiveX Controls as Tabs
Interface Pointers
ISafeArrayUtility Interface Overview
Keystrokes and Accelerator Keys
Library Features and Objects
Lightweight Components
Line Attributes for View::GetPolyLinesAndCurves
Line Weights
Long vs. Integer
Collapse Macro FeaturesMacro Features
Manipulators
Mass Properties
Expand Multibody PartsMultibody Parts
Option Explicit Statement
Expand Packing and Unpacking Double Arrays and Integer PairsPacking and Unpacking Double Arrays and Integer Pairs
Partition Rollback and API Handles
Persistent Reference IDs
Presentation Transforms
Expand PropertyManager PagesPropertyManager Pages
.NET Interop Assemblies
Quick Tips and Bubble ToolTips
Return Values
Expand SafeArraysSafeArrays
Selection Criteria
Selection Lists
Selections that Define Features
Setup Project to Distribute SOLIDWORKS Add-in
Smart Pointers
SOLIDWORKS Objects
Sorting Tables
Splines
SQLite
STL Container Classes and Smart Pointers
Suspend Automatic Rebuilds
System Options and Document Properties
Tessellation and Edges
Third-party Data in SOLIDWORKS Files
Tracking IDs
Expand Type LibrariesType Libraries
Units
Unmanaged C++ and C++/CLI Code
VBA and SOLIDWORKS x64
Examples and Projects
Expand SOLIDWORKS API HelpSOLIDWORKS API Help
Expand SOLIDWORKS PDM Professional API HelpSOLIDWORKS PDM Professional API Help
Expand FeatureWorks API HelpFeatureWorks API Help
Expand SOLIDWORKS Costing API HelpSOLIDWORKS Costing API Help
Expand SOLIDWORKS Document Manager API HelpSOLIDWORKS Document Manager API Help
Expand SOLIDWORKS Routing API HelpSOLIDWORKS Routing API Help
Expand SOLIDWORKS Simulation API HelpSOLIDWORKS Simulation API Help
Expand SOLIDWORKS Sustainability API HelpSOLIDWORKS Sustainability API Help
Expand SOLIDWORKS Toolbox API HelpSOLIDWORKS Toolbox API Help
Expand SOLIDWORKS Utilities API HelpSOLIDWORKS Utilities API Help
Expand SOLIDWORKS Workgroup PDM API HelpSOLIDWORKS Workgroup PDM API Help
Expand eDrawings API HelpeDrawings API Help
Hide Table of Contents

Rebuild Function

The rebuild function for a macro feature performs the real work. No new features can be introduced and no user interaction can occur during a rebuild of a model containing a macro feature.

There are three types of rebuild functions:

Type

Definition

Actions

Independent

Interacts with the model, but does not modify existing geometry or create new geometry

  • Obtains the IMacroFeatureData object from the input IFeature object

  • Obtains the selections and parameters from the IMacroFeatureData object

  • Processes the inputs according to the design of the feature

  • Validates data based on the model

  • Updates external databases

Return values can be:

  • True, which indicates success

  • False, which indicates failure with no additional information

  • String, which is displayed in an error message to the user; for example:

  • VBA

  • swmRebuild = "Macro feature output error message"
  • C++ COM

  • CComBSTR bMsg = _T("Macro feature output error message");
    _variant_t vBSTRRet = bMsg;
    *retval = vBSTRRet;

  • C#

  • functionReturnValue = "Macro feature output error message";
    return functionReturnValue;

  • VB.NET

  • Regenerate = "Macro feature output error message"
     

Modify

Modifies one or more input bodies

NOTE: The numbering scheme should be consistent and reproducible.

Return values can be:

  • True, which indicates success

  • False, which indicates failure and no additional information is provided

  • String, which is displayed in an error message to the user; for example:

  • VBA

  • swmRebuild = "Macro feature output error message"
  • C++ COM

  • CComBSTR bMsg = _T("Macro feature output error message");
    _variant_t vBSTRRet = bMsg;
    *retval = vBSTRRet;

  • C#

  • functionReturnValue = "Macro feature output error message";
    return functionReturnValue;

  • VB.NET

  • Regenerate = "Macro feature output error message"

NOTE: A macro feature rebuild function can output more than one body, in a VARIANT SafeArray containing multiple IBody2 objects, by either modifying one or more edit bodies or by creating one or more new bodies. For multibody macro features only, call IMacroFeatureData::EnableMultiBodyConsume from within the rebuild function to specify whether the original edit body is appended (default) or replaced with multiple bodies in the FeatureManager design tree's Solid Bodies folder.

Create

Creates one or more output bodies

NOTE: The numbering scheme should be consistent and reproducible.

Return values can be:

  • IBody2, the newly created body, or a VARIANT SafeArray containign multiple IBody2 objects

  • False, which indicates failure and provides no additional information

  • String, which is displayed in an error message to the user; for example:

  • VBA

  • swmRebuild = "Macro feature output error message"
  • C++ COM

  • CComBSTR bMsg = _T("Macro feature output error message");
    _variant_t vBSTRRet = bMsg;
    *retval = vBSTRRet;

  • C#

  • functionReturnValue = "Macro feature output error message";
    return functionReturnValue;

  • VB.NET

  • Regenerate = "Macro feature output error message"

NOTE: A macro feature rebuild function can output more than one body, in a VARIANT SafeArray containing multiple IBody2 objects, by either modifying one or more edit bodies or by creating one or more new bodies. For multibody macro features only, call IMacroFeatureData::EnableMultiBodyConsume from within the rebuild function to specify whether the original edit body is appended (default) or replaced with multiple bodies in the FeatureManager design tree's Solid Bodies folder.

The rebuild function is called by SOLIDWORKS whenever the macro feature is regenerated. The parametric information needed to regenerate the feature should be stored in the feature’s parameter and selection lists. These lists are created when the feature is inserted into the model and are available for reading and editing from the feature’s IMacroFeatureData interface. For example, the data stored in the parameters and selection lists can be used to perform low-level Boolean body operations to affect geometric features.

Because IBody2 objects created using the API do not always automatically assign IDs to their faces and edges, you should always check that there are no entity IDs that need to be assigned. Otherwise, any Boolean body operations involving that Body2 object will cause regeneration to fail. Use IMacroFeatureData::GetEntitiesNeedUserId to check for the IDs. If the faces and edges arrays returned are both empty, then no user IDs are required. Otherwise, use IMacroFeatureData::SetFaceUserId and IMacroFeatureData::SetEdgeUserId to set the IDs of those entities.

The macro feature’s rebuild function is responsible for ensuring that the same IDs are always placed on the same entities each time the regeneration function is called. The order in which the entities are returned cannot be used. Instead, there should be some algorithm used that relies on the geometry of the body to determine entity IDs. Of course, features with no impact on the geometry of the model can also be created.

The following example illustrates a VBA-based rebuild function. When called, it returns true to indicate to SOLIDWORKS that it was successful.

Function swmRegen(app As Variant, part As Variant, feature As Variant) As Variant

msgbox "Regeneration function called."   

.

.

.

swmRegen = True

End Function

NOTES:

  • When regenerating a macro feature, IDimension::ReferencePoints gets and sets the reference points of a display dimension (IDisplayDimension object). In all other cases, this property gets and sets the reference points of a dimension (IDimension object).
  • If your macro feature is crashing while regenerating, then force garbage collection and wait for all finalizers to complete before continuing. For example, include the following code at the end of your rebuild function in a VB.NET application:

    ‘Wait for all finalizers to complete before continuing

    GC.Collect()
    GC.WaitforPendingfinalizers()
    GC.Collect()
    GC.WaitforPendingFinalizers()

     



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Rebuild Function
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:

x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2016 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.