import adsk.core, adsk.fusion, traceback
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
rootComp = design.rootComponent
features = rootComp.features
# Access the unfold and refold feature collections
unfoldFeatures = features.unfoldFeatures
refoldFeatures = features.refoldFeatures
if unfoldFeatures.count == 0:
ui.messageBox('No unfold features found in this design.')
unfold = unfoldFeatures.item(0)
# Get the associated refold feature from the unfold
refold = unfold.refoldFeature
if refold:
ui.messageBox(
f'Unfold "{unfold.name}" is associated with refold "{refold.name}".'
)
else:
ui.messageBox(
f'Unfold "{unfold.name}" has no associated refold feature.'
)
# Get the associated unfold feature from the refold (reverse direction)
if refoldFeatures.count > 0:
refold = refoldFeatures.item(0)
unfold = refold.unfoldFeature
if unfold:
ui.messageBox(
f'Refold "{refold.name}" is associated with unfold "{unfold.name}".'
)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
#include <Core/CoreAll.h>
#include <Fusion/FusionAll.h>
using namespace adsk::core;
using namespace adsk::fusion;
Ptr<UserInterface> ui;
extern "C" XI_EXPORT bool run(const char* context)
{
Ptr<Application> app = Application::get();
if (!app)
return false;
ui = app->userInterface();
if (!ui)
return false;
Ptr<Product> product = app->activeProduct();
if (!product)
return false;
Ptr<Design> design = product;
if (!design)
return false;
Ptr<Component> rootComp = design->rootComponent();
if (!rootComp)
return false;
Ptr<Features> features = rootComp->features();
if (!features)
return false;
// Access unfold and refold feature collections
Ptr<UnfoldFeatures> unfoldFeatures = features->unfoldFeatures();
Ptr<RefoldFeatures> refoldFeatures = features->refoldFeatures();
if (unfoldFeatures->count() == 0)
return false;
Ptr<UnfoldFeature> unfoldFeature = unfoldFeatures->item(0);
// Get the refold feature associated with this unfold.
// Returns null if the unfold has no associated refold (e.g. user hasn't refolded yet).
Ptr<RefoldFeature> associatedRefold = unfoldFeature->refoldFeature();
if (associatedRefold)
{
std::string msg = "Unfold \"" + unfoldFeature->name() + "\" is paired with refold \"" +
// Get the unfold feature from the refold (reverse direction).
// A refold always has an associated unfold.
Ptr<UnfoldFeature> associatedUnfold = associatedRefold->unfoldFeature();
}
// Iterate all refold features and get their associated unfold
for (size_t i = 0; i < refoldFeatures->count(); ++i)
{
Ptr<RefoldFeature> refold = refoldFeatures->item(i);
Ptr<UnfoldFeature> unfold = refold->unfoldFeature();
}
return true;
}