import adsk.core, adsk.fusion, traceback
def getArcGeometryInfo(arcGeom):
result = arcGeom.getData()
if (result[0]):
(retVal, center, axis, refVector, radius, startAngle, endAngle) = result
arcInfo = "Center: %.6f, %.6f, %.6f\n" % (center.x, center.y, center.z)
arcInfo += "Axis: %.6f, %.6f, %.6f\n" % (axis.x, axis.y, axis.z)
arcInfo += "Reference vector: %.6f, %.6f, %.6f\n" % (refVector.x, refVector.y, refVector.z)
arcInfo += "Radius: %.6f\n" % radius
arcInfo += "Start angle: %.6f\n" % startAngle
arcInfo += "End angle: %.6f" % endAngle
return arcInfo
def getCircleGeometryInfo(circGeom):
result = circGeom.getData()
if (result[0]):
(retVal, center, axis, radius) = result
circleInfo = "Center: %.6f, %.6f, %.6f\n" % (center.x, center.y, center.z)
circleInfo += "Axis: %.6f, %.6f, %.6f\n" % (axis.x, axis.y, axis.z)
circleInfo += "Radius: %.6f" % radius
return circleInfo
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
ent = ui.selectEntity("Select a circular edge", "CircularEdges")
if (isinstance(ent.entity.geometry, adsk.core.Arc3D)):
arcGeom = ent.entity.geometry
arcInfo = getArcGeometryInfo(arcGeom)
ui.messageBox(arcInfo, "Arc Info")
else:
if (isinstance(ent.entity.geometry, adsk.core.Circle3D)):
circGeom = ent.entity.geometry
circleInfo = getCircleGeometryInfo(circGeom)
ui.messageBox( circleInfo, "Circle Info")
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
#include <Core/Application/Application.h>
#include <Core/Geometry/Arc3D.h>
#include <Core/Geometry/Circle3D.h>
#include <Core/Geometry/Point3D.h>
#include <Core/Geometry/Vector3D.h>
#include <Core/UserInterface/Selection.h>
#include <Core/UserInterface/UserInterface.h>
#include <Fusion/BRep/BRepEdge.h>
using namespace adsk::core;
using namespace adsk::fusion;
Ptr<UserInterface> ui;
namespace
{
std::string getArcGeometryInfo(Ptr<Arc3D> arcGeom)
{
std::string arcInfo;
if (!arcGeom)
return arcInfo;
Ptr<Point3D> center;
Ptr<Vector3D> axis;
Ptr<Vector3D> refVector;
double radius = 0.0;
double startAngle = 0.0;
double endAngle = 0.0;
bool result = arcGeom->getData(center, axis, refVector, radius, startAngle, endAngle);
if (!result)
return arcInfo;
std::stringstream ss;
ss.precision(6);
ss << std::fixed;
ss << "Center: " << center->x() << ", " << center->y() << ", " << center->z() << "\n";
ss << "Axis: " << axis->x() << ", " << axis->y() << ", " << axis->z() << "\n";
ss << "Reference vector: " << refVector->x() << ", " << refVector->y() << ", " << refVector->z() << "\n";
ss << "Radius: " << radius << "\n";
ss << "Start angle: " << startAngle << "\n";
ss << "End angle: " << endAngle << "\n";
arcInfo += ss.str();
return arcInfo;
}
std::string getCircleGeometryInfo(Ptr<Circle3D> circGeom)
{
std::string circleInfo;
if (!circGeom)
return circleInfo;
Ptr<Point3D> center;
Ptr<Vector3D> axis;
double radius = 0.0;
bool result = circGeom->getData(center, axis, radius);
if (!result)
return circleInfo;
std::stringstream ss;
ss.precision(6);
ss << std::fixed;
ss << "Center: " << center->x() << ", " << center->y() << ", " << center->z() << "\n";
ss << "Axis: " << axis->x() << ", " << axis->y() << ", " << axis->z() << "\n";
ss << "Radius: " << radius << "\n";
circleInfo += ss.str();
return circleInfo;
}
} // namespace
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<Selection> selection = ui->selectEntity("Select a circular edge", "CircularEdges");
if (!selection)
return false;
Ptr<BRepEdge> edge = selection->entity();
if (!edge)
return false;
if (Ptr<Arc3D> arcGeom = edge->geometry()) {
std::string arcInfo = getArcGeometryInfo(arcGeom);
ui->messageBox(arcInfo, "Arc Info");
}
else if (Ptr<Circle3D> circGeom = edge->geometry()) {
std::string circleInfo = getCircleGeometryInfo(circGeom);
ui->messageBox(circleInfo, "Circle Info");
}
return true;
}
/**
* Get Circle and Arc Data from Edge API Sample
* Display the arc and circle geometric information from a selected circular edge.
*/
import { adsk } from '@adsk/fusion';
function getArcGeometryInfo(arcGeom) {
const result = arcGeom.getData()
if (result[0]) {
const [center, axis, refVector, radius, startAngle, endAngle] = result
let arcInfo = ""
arcInfo += `Center: ${center.x.toFixed(6)}, ${center.y.toFixed(6)}, ${center.z.toFixed(6)}\n`;
arcInfo += `Axis: ${axis.x.toFixed(6)}, ${axis.y.toFixed(6)}, ${axis.z.toFixed(6)}\n`;
arcInfo += `Reference vector: ${refVector.x.toFixed(6)}, ${refVector.y.toFixed(6)}, ${refVector.z.toFixed(6)}\n`;
arcInfo += `Radius: ${radius.toFixed(6)}\n`;
arcInfo += `Start angle: ${startAngle.toFixed(6)}\n`;
arcInfo += `End angle: ${endAngle.toFixed(6)}`;
return arcInfo
}
}
function getCircleGeometryInfo(circGeom) {
const result = circGeom.getData()
if (result[0]) {
const [center, axis, radius] = result
let circleInfo = "";
circleInfo += `Center: ${center.x.toFixed(6)}, ${center.y.toFixed(6)}, ${center.z.toFixed(6)}\n`;
circleInfo += `Axis: ${axis.x.toFixed(6)}, ${axis.y.toFixed(6)}, ${axis.z.toFixed(6)}\n`;
circleInfo += `Radius: ${radius.toFixed(6)}`;
return circleInfo
}
}
function createCylinder(component: adsk.fusion.Component) {
// Create sketch
const sketches = component.sketches
const sketch = sketches.add(component.xZConstructionPlane)
const sketchCircles = sketch.sketchCurves.sketchCircles
const centerPoint = adsk.core.Point3D.create(0, 0, 0)
const circle = sketchCircles.addByCenterRadius(centerPoint, 3.0)
// Get the profile defined by the circle.
const prof = sketch.profiles.item(0)
// Create an extrusion input
const extrudes = component.features.extrudeFeatures
const extInput = extrudes.createInput(prof, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
// Define that the extent is a distance extent of 5 cm.
const distance = adsk.core.ValueInput.createByReal(5)
const distanceExtentDef = adsk.fusion.DistanceExtentDefinition.create(distance)
extInput.setOneSideExtent(distanceExtentDef, adsk.fusion.ExtentDirections.PositiveExtentDirection)
// Create the extrusion.
const ext = extrudes.add(extInput)
return ext.bodies.item(0)
}
function run() {
// Get the Fusion API's application object
const app = adsk.core.Application.get();
if (!app) throw Error("No adsk.core.Application.");
// Create a document.
const doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
// Create a document.
const design = app.activeProduct as adsk.fusion.Design
if (!design) throw Error("No active Fusion design");
const rootComp = design.rootComponent
const cylinder = createCylinder(rootComp)
// Selecting circular edge
const edge = cylinder.edges.item(1)
adsk.log("TypeScript")
adsk.log("Edge object type: " + edge.geometry.objectType)
adsk.log("Arc object type: " + adsk.core.Arc3D.classType())
adsk.log("Circle object type: " + adsk.core.Circle3D.classType())
if (edge.geometry.objectType == adsk.core.Arc3D.classType()) {
const arcGeom = edge.geometry
const arcInfo = getArcGeometryInfo(arcGeom)
adsk.log("Arc Info: " + arcInfo)
}
else if (edge.geometry.objectType == adsk.core.Circle3D.classType()) {
const circGeom = edge.geometry
const circleInfo = getCircleGeometryInfo(circGeom)
adsk.log("Circle Info: " + circleInfo)
}
}
run();