Message 1 of 3
addExistingComponent weirdness
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have some code that should create three rectangular solids (A, B, and C) , at (0, 0), (2, 1), and (2, -1), respectively. That's not what happens. The problem appears to be caused by the fact that B and C are copies of A that aren't at the same level of component hierarchy as A; if I create them as siblings the problem goes away.
Here's the code:
from traceback import format_exc
from adsk.core import Application, DialogResults, Matrix3D, Matrix2D, Vector3D, Point3D, Point2D, ValueInput, ObjectCollection
from adsk.fusion import Design, FeatureOperations
def run(context):
ui = None
try:
app = Application.get()
ui = app.userInterface
design = Design.cast(app.activeProduct)
if not design:
ui.messageBox('No active Fusion design', 'No Design')
return
# Create component #1
modelBoard = design.activeComponent.occurrences.addNewComponent(Matrix3D.create()).component
modelBoard.name = "Board"
# Create component #2
packageComponent = design.activeComponent.occurrences.addNewComponent(Matrix3D.create()).component
# Create a sketch in component #2
outline = packageComponent.sketches.add(packageComponent.xYConstructionPlane)
lines = outline.sketchCurves.sketchLines
for line in [(-2, -1, 2, -1), (2, -1, 2, 1), (2, 1, -2, 1), (-2, 1, -2, -1)]:
(x1, y1, x2, y2) = line
start = Point3D.create(float(x1), float(y1), 0)
end = Point3D.create(float(x2), float(y2), 0)
lines.addByTwoPoints(start, end)
# Extrude sketch in component #2
extrudes = packageComponent.features.extrudeFeatures
extrudeParams = extrudes.createInput(outline.profiles.item(0), FeatureOperations.NewBodyFeatureOperation)
extrudeParams.setDistanceExtent(False, ValueInput.createByReal(.25))
extrudeParams.isSolid = True
extrudes.add(extrudeParams)
# Copy component #2 into component #1 twice
for x, y in [(2, 1), (-2, 1)]:
transform = Matrix3D.create()
transform.translation = Vector3D.create(x, y, 0)
packageOccurrence = modelBoard.occurrences.addExistingComponent(packageComponent, transform)
except:
if ui:
print(format_exc())
ui.messageBox('Failed:\n{}'.format(format_exc(4)))Here's what happens:
Help / suggestions?
