开发顾问
DevTech中国区经理
Autodesk开发技术支持部(DevTech)
左右方向键切换PPT,有些页面上下方向键切换子页面
注:广告都是浮云
基于云,从概念设计到成品的三维CAD/CAM协作设计平台
{
"autodeskProduct": "Fusion360",
"type": "addin",
"id": "ea34afff-f444-4ac7-95e5-d9ac5c574b6e",
"author": "Autodesk Inc.",
"description": {
"": "This is sample addin."
},
"version": "0.0.1",
"runOnStartup": false,
"supportedOS": "windows|mac",
"autodeskLibraries": ["application", "dashboard", "geometry", "materials", "userInterface", "utilities", "bRep", "components", "construction", "features", "fusion", "meshBody", "meshData", "sketch", "tSpline"]
}
{
"autodeskProduct": "Fusion360",
"type": "script",
"author": "",
"description": {
"": ""
},
"supportedOS": "windows|mac"
}
{
"autodeskProduct": "Fusion360",
"type": "script",
"author": "",
"description": {
"": ""
},
"supportedOS": "windows|mac",
"sourcewindows": "MyTestCPP.vcxproj",
"sourcemac": "MyTestCPP.xcodeproj"
}
//Fusion调用入口函数
function run(context) {
//是否支持调试
"use strict";
if (adsk.debug === true) {
/*jslint debug: true*/
debugger;
/*jslint debug: false*/
}
//用户界面相关的对象
var ui;
try {
//获取Application对象
var app = adsk.core.Application.get();
ui = app.userInterface;
ui.messageBox('Hello script');
}
catch (e) {
if (ui) {
ui.messageBox('Failed : ' + (e.description ? e.description : e));
}
}
adsk.terminate();
}
#引入必要的基本库
import adsk.core, adsk.fusion, traceback
#Fusion调用入口函数
def run(context):
#用户界面相关的对象
ui = None
try:
#获取Application对象
app = adsk.core.Application.get()
ui = app.userInterface
ui.messageBox('Hello script')
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 app;
Ptr ui;
//外部函数,Fusion调用的入口
extern "C" XI_EXPORT bool run(const char* context)
{
//获取Application对象
app = Application::get();
if (!app)
return false;
//用户界面相关的对象
ui = app->userInterface();
if (!ui)
return false;
ui->messageBox("in run");
return true;
}
//外部函数,程序退出时
extern "C" XI_EXPORT bool stop(const char* context)
{
if (ui)
{
ui->messageBox("in stop");
ui = nullptr;
}
return true;
}
#ifdef XI_WIN
#include
//C++程序的执行入口
BOOL APIENTRY DllMain(HMODULE hmodule, DWORD reason, LPVOID reserved)
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
#endif // XI_WIN
Ptr< SketchLine > line1;
bool doAnimation(Ptr< SketchCurve > pathCurve, Ptr< Vector3D > upDirection)
if (comp->name() == "Test")
bool isOK = comp->name("New Test");
var prof = sketch.profiles.item(0);
var extrudes = rootComp.features.extrudeFeatures;
var extInput = extrudes.createInput(prof, adsk.fusion.FeatureOperations.NewBodyFeatureOperation);
var distance = adsk.core.ValueInput.createByReal(5);
extInput.setDistanceExtent(false, distance);
var ext = extrudes.add(extInput)
//获取application
var app = adsk.core.Application.get();
ui = app.userInterface;
//当前设计
var product = app.activeProduct;
var design = adsk.fusion.Design(product);
// 获取当前设计的模型根对象rootComponent.
var rootComp = design.rootComponent;
//基于XZ平面创建草图
var sketches = rootComp.sketches;
var sketch = sketches.add(rootComp.xZConstructionPlane);
//绘制一个草图圆.
var sketchCircles = sketch.sketchCurves.sketchCircles;
var centerPoint = adsk.core.Point3D.create(0, 0, 0);
var circle = sketchCircles.addByCenterRadius(centerPoint, 5.0);
// 获取缺省的第一个轮廓(即这个草图圆区域)
var prof = sketch.profiles.item(0);
// 创建模型特征的Input对象
var extrudes = rootComp.features.extrudeFeatures;
var extInput = extrudes.createInput(prof, adsk.fusion.FeatureOperations.NewBodyFeatureOperation);
// 定义特征的拉伸距离
var distance = adsk.core.ValueInput.createByReal(5);
extInput.setDistanceExtent(true, distance);
// 利用该Input对象创建拉伸特征
var ext = extrudes.add(extInput);
app = adsk.core.Application.get()
design = app.activeProduct
# 获取当前设计的模型根对象rootComponent.
rootComp = design.rootComponent
# 基于XY平面创建草图.
sketch = rootComp.sketches.add(rootComp.xYConstructionPlane)
# 绘制一个草图圆.
circles = sketch.sketchCurves.sketchCircles
circle1 = circles.addByCenterRadius(adsk.core.Point3D.create(0, 0, 0), 2)
# 获取缺省的第一个轮廓(即这个草图圆区域)
prof = sketch.profiles.item(0)
#创建模型特征的Input对象
extrudes = rootComp.features.extrudeFeatures
extInput = extrudes.createInput(prof, adsk.fusion.FeatureOperations.NewComponentFeatureOperation)
# 定义特征的拉伸距离
extInput.setDistanceExtent(False, adsk.core.ValueInput.createByReal(5))
# 利用该Input对象创建拉伸特征
ext = extrudes.add(extInput)
extern "C" XI_EXPORT bool run(const char* context)
{
app = Application::get();
if (!app)
return false;
ui = app->userInterface();
if (!ui)
return false;
//获取当前设计
Ptr product = app->activeProduct();
Ptr design = product;
//获取当前设计的模型根对象rootComponent.
PtrrootComp = design->rootComponent();
//基于XZ平面创建草图
Ptr sketches = rootComp->sketches();
Ptr sketch = sketches->add(rootComp->xZConstructionPlane());
//绘制一个草图圆.
Ptr sketchCircles = sketch->sketchCurves()->sketchCircles();
Ptr centerPoint = Point3D::create(0, 0, 0);
Ptr circle = sketchCircles->addByCenterRadius(centerPoint, 5.0);
// 获取缺省的第一个轮廓(即这个草图圆区域)
Ptr prof = sketch->profiles()->item(0);
// 创建模型特征的Input对象
Ptr extrudes= rootComp->features()->extrudeFeatures();
Ptr extInput = extrudes->createInput(prof, FeatureOperations::NewBodyFeatureOperation);
// 定义特征的拉伸距离
Ptr distance =ValueInput::createByReal(5);
extInput->setDistanceExtent(true, distance);
// 利用该Input对象创建拉伸特征
Ptrext = extrudes->add(extInput);
return true;
}
var app = adsk.core.Application.get();
ui = app.userInterface;
var thisobj = ui.activeSelections.item(0).entity ;
var objName = thisobj.objectType;
ui.messageBox(objName);
if(thisobj instanceof adsk.fusion.BRepFace)
{
ui.messageBox("这是Face!");
}
else
{
ui.messageBox("这不是Face!");
}
if(ui.activeSelections.count>1)
{
var thisobj1 = ui.activeSelections.item(0).entity;
var thisobj2 = ui.activeSelections.item(1).entity;
if(thisobj.equals(thisobj1)){
ui.messageBox("两对象相等!");
}
else{
ui.messageBox("两对象不相等!");
}
}
app = adsk.core.Application.get()
ui = app.userInterface
thisobj= ui.activeSelections.item(0).entity
objName = type(thisobj).__name__
if type(thisobj) is adsk.fusion.BRepFace:
ui.messageBox('这是Face!')
else:
ui.messageBox('这不是Face!')
if ui.activeSelections.count > 1:
thisobj1= ui.activeSelections.item(0).entity
thisobj2= ui.activeSelections.item(1).entity
if thisobj == thisobj1:
ui.messageBox('两对象相等')
else:
ui.messageBox('两对象不相等')
Ptr selectedEnt = selection->entity();
if (selectedEnt->objectType() == adsk::fusion::SketchLine::classType())
If (face1 == face2)
ui.messageBox(“Faces are the same.”);
function run(context) {
"use strict";
if (adsk.debug === true) {
/*jslint debug: true*/
debugger;
/*jslint debug: false*/
}
var ui;
try {
var app = adsk.core.Application.get();
ui = app.userInterface;
ui.messageBox('Hello addin');
}
catch (e) {
if (ui) {
ui.messageBox('Failed : ' + (e.description ? e.description : e));
}
}
}
function stop(context) {
var ui;
try {
var app = adsk.core.Application.get();
ui = app.userInterface;
ui.messageBox('Stop addin');
}
catch (e) {
if (ui) {
ui.messageBox('Failed : ' + (e.description ? e.description : e));
}
}
}
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
ui.messageBox('Hello addin')
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def stop(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
ui.messageBox('Stop addin')
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 app;
Ptr ui;
extern "C" XI_EXPORT bool run(const char* context)
{
app = Application::get();
if (!app)
return false;
ui = app->userInterface();
if (!ui)
return false;
ui->messageBox("in run");
return true;
}
extern "C" XI_EXPORT bool stop(const char* context)
{
if (ui)
{
ui->messageBox("in stop");
ui = nullptr;
}
return true;
}
#ifdef XI_WIN
#include
BOOL APIENTRY DllMain(HMODULE hmodule, DWORD reason, LPVOID reserved)
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
#endif // XI_WIN
import adsk.core, adsk.fusion, traceback
#全局事件句柄集合
handlers = []
#定义事件类
class MyWorkspaceActivatedHandler(adsk.core.WorkspaceEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
#通知函数为事件触发
ws = args.workspace
app = adsk.core.Application.get()
ui = app.userInterface
#显示当前激活的工作空间
ui.messageBox(ws.name + ' 激活的工作空间 (Python).')
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
#添加函数指针到对应事件
onWorkspaceActivated = MyWorkspaceActivatedHandler()
ui.workspaceActivated.add(onWorkspaceActivated)
handlers.append(onWorkspaceActivated)
#如果是脚本,为了让事件继续有效,需要调用autoTerminate
#如果是插件,由于已经调入整个Fusion进程,不需这句
adsk.autoTerminate(False)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
//定义事件函数
var MyWorkspaceActivatedHandler = function(args) {
var ws = args.workspace;
var app = adsk.core.Application.get();
var ui = app.userInterface;
ui.messageBox(ws.name + ' 激活的工作空间 (JavaScript).');
};
function run(context) {
var app = adsk.core.Application.get();
var ui = app.userInterface;
//添加函数指针到对应事件
ui.workspaceActivated.add(MyWorkspaceActivatedHandler);
//注意。即使是脚本形式,Javascript委托的事件仍旧在后台执行,
//所以不需要Python或C++中的
}
}
#include < Core/CoreAll.h>
#include < Fusion/FusionAll.h>
#include < Core/UserInterface/UserInterface.h>
#include < Core/UserInterface/WorkspaceEvent.h>
#include < Core/UserInterface/WorkspaceEventHandler.h>
#include < Core/UserInterface/WorkspaceEventArgs.h>
using namespace adsk::core;
using namespace adsk::fusion;
Ptr app;
Ptr ui;
//定义事件类
class MyWorkspaceActivatedEventHandler : public adsk::core::WorkspaceEventHandler
{
public:
void notify(const Ptr& eventArgs) override
{
//通知函数为事件触发
//显示当前激活的工作空间
Ptr ws = eventArgs->workspace();
std::string wsName = "当前激活的工作空间是 (C++):" + ws->name();
ui->messageBox(wsName);
}
} _workspaceActivated;
extern "C" XI_EXPORT bool run(const char* context)
{
app = Application::get();
if (!app)
return false;
ui = app->userInterface();
if (!ui)
return false;
// 添加函数指针到对应事件
Ptr workspaceActivatedEvent = ui->workspaceActivated();
if (!workspaceActivatedEvent)
return false;
bool isOk = workspaceActivatedEvent->add(&_workspaceActivated);
if (!isOk)
return false;
//如果是脚本,为了让事件继续有效,需要调用autoTerminate
//如果是插件,由于已经调入整个Fusion进程,不需这句
adsk::autoTerminate(false);
return true;
}
extern "C" XI_EXPORT bool stop(const char* context)
{
if (ui)
{
//ui->messageBox("in stop");
ui = nullptr;
}
return true;
}
#ifdef XI_WIN
#include
BOOL APIENTRY DllMain(HMODULE hmodule, DWORD reason, LPVOID reserved)
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
#endif // XI_WIN
import adsk.core, adsk.fusion, traceback
app = None
ui = None
handlers_dialog = []
commandDefId = 'ADNTestCommandDef'
commandName = 'My Test'
commandDescription = 'test'
workspaceToUse = "FusionSolidEnvironment"
panelToUse = "SolidCreatePanel"
#执行按钮的事件
class CommandCreatedHandler(adsk.core.CommandCreatedEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
global ui
ui.messageBox('我的按钮执行了!')
#插件启动时自动调用的入口
#初始化自定义界面,增加自定义按钮
def run(context):
try:
global app
app = adsk.core.Application.get()
global ui
ui = app.userInterface
#添加命令的definition
cmdDef = ui.commandDefinitions.itemById(commandDefId)
if not cmdDef:
cmdDef = ui.commandDefinitions.addButtonDefinition(commandDefId, commandName, commandDescription, '/')
#委托按钮的执行事件
onCommandCreated = CommandCreatedHandler()
cmdDef.commandCreated.add(onCommandCreated)
#获得【模型】工作空间
workspaces_ = ui.workspaces
modelingWorkspace_ = workspaces_.itemById(workspaceToUse)
# 获得【创建】的面板
toolbarPanels_ = modelingWorkspace_.toolbarPanels
toolbarPanel_ = toolbarPanels_.itemById(panelToUse)
#添加新按钮到面板按钮集合
toolbarControlsPanel_ = toolbarPanel_.controls
toolbarControlPanel_ = toolbarControlsPanel_.itemById(commandDefId)
if not toolbarControlPanel_:
toolbarControlPanel_ = toolbarControlsPanel_.addCommand(cmdDef, commandDefId)
#附加到全局句柄
handlers_dialog.append(onCommandCreated)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
#插件卸载时自动调用
#销毁自定义界面,释放其它对象
def stop(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
#删除按钮
workspaces_ = ui.workspaces
modelingWorkspace_ = workspaces_.itemById(workspaceToUse)
toolbarPanels_ = modelingWorkspace_.toolbarPanels
toolbarPanel_ = toolbarPanels_.itemById(panelToUse)
toolbarControls_ = toolbarPanel_.controls
toolbarControl_ = toolbarControls_.itemById(commandDefId)
if toolbarControl_.isValid:
toolbarControl_.deleteMe()
commandDefinitions_ = ui.commandDefinitions
commandDefinition_ = commandDefinitions_.itemById(commandDefId)
if commandDefinition_.isValid:
commandDefinition_.deleteMe()
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
//Author-
//Description-
var commandId = 'ADNTestJSCommandDef';
var commandName = 'My Javascript Test';
var commandDescription = 'test';
var workspaceToUse = 'FusionSolidEnvironment';
var panelToUse = 'SolidCreatePanel';
var commandResources = './';
//插件启动时自动调用的入口
//初始化自定义界面,增加自定义按钮
function run(context) {
//是否支持调试
"use strict";
if (adsk.debug === true) {
/*jslint debug: true*/
debugger;
/*jslint debug: false*/
}
var ui;
try {
var app = adsk.core.Application.get();
ui = app.userInterface;
//创建按钮命令
var onCommandCreated = function(args) {
try {
// 委托按钮执行事件.
var command = args.command;
command.execute.add(onCommandExecuted);
}
catch (e) {
ui.messageBox('创建命令失败 : ' + errorDescription(e));
}
};
// 按钮执行事件
var onCommandExecuted = function(args) {
try {
ui.messageBox("Javascript创建的按钮被执行!");
}
catch (e) {
ui.messageBox('执行按钮失败! : ' + errorDescription(e));
}
};
// 添加按钮
var workspaces_ = ui.workspaces;
//【模型】工作空间
var modelingWorkspace_ = workspaces_.itemById('FusionSolidEnvironment');
var toolbarPanels_ = modelingWorkspace_.toolbarPanels;
//工作空间某面板
var toolbarPanel_ = toolbarPanels_.itemById(panelToUse)
var toolbarControls_ = toolbarPanel_.controls;
var toolbarControl_ = toolbarControls_.itemById(commandId);
if (toolbarControl_) {
//若已经创建
adsk.terminate();
return;
} else {
//命令定义
var commandDefinition_ = ui.commandDefinitions.itemById(commandId);
if (!commandDefinition_) {
commandDefinition_ = ui.commandDefinitions.addButtonDefinition(commandId, commandName, commandDescription, commandResources);
}
//委托命令创建事件
commandDefinition_.commandCreated.add(onCommandCreated);
//添加定义到面板
toolbarControl_ = toolbarControls_.addCommand(commandDefinition_);
toolbarControl_.isVisible = true;
}
}
catch (e) {
if (ui) {
ui.messageBox('Failed : ' + (e.description ? e.description : e));
}
}
}
//插件卸载时自动调用
//销毁自定义界面,释放其它对象
function stop(context) {
var ui;
try {
var app = adsk.core.Application.get();
ui = app.userInterface;
//删除按钮
var workspaces_ = ui.workspaces;
var modelingWorkspace_ = workspaces_.itemById('FusionSolidEnvironment');
var toolbarPanels_ = modelingWorkspace_.toolbarPanels;
var toolbarPanel_ = toolbarPanels_.itemById(panelToUse)
var toolbarControls_ = toolbarPanel_.controls;
var toolbarControl_ = toolbarControls_.itemById(commandId);
if (toolbarControl_.isValid) {
toolbarControl_.deleteMe();
}
//删除命令定义
var commandDefinitions_ = ui.commandDefinitions;
var commandDefinition_ = commandDefinitions_.itemById(commandId);
if (commandDefinition_.isValid) {
commandDefinition_.deleteMe();
}
}
catch (e) {
if (ui) {
ui.messageBox('Failed : ' + (e.description ? e.description : e));
}
}
}