- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I've pasted a code example below that creates a Rectangular Pattern Feature and adds it to a new document. I want to re-configure this so it adds the pattern feature to a new component within an active file instead of creating a new file and adding it to that one. Can someone help me re-configure this example to do this?
I've tried to change by passing in a new component and using it as my root component and get the following error:
Traceback (most recent call last): File "C:/Users/ebunn/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/Scripts/Nesting_True_Type_By_Points_Comp/Nesting_True_Type_By_Points_Comp.py", line 736, in <module> PatternBodies(preN[1],newComp,numX,moveX,numY,moveY) File "C:/Users/ebunn/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/Scripts/Nesting_True_Type_By_Points_Comp/Nesting_True_Type_By_Points_Comp.py", line 683, in PatternBodies rectangularFeature = rectangularPatterns.add(rectangularPatternInput) File "C:\Users/ebunn/AppData/Local/Autodesk/webdeploy/production/8814bf1cdd9624465cbdf7f023becc629a5ffbe5/...", line 28366, in add return _fusion.RectangularPatternFeatures_add(self, input) RuntimeError: 2 : InternalValidationError : Utils::getObjectPath(obj.get(),objPath, nullptr,path)
Here is an example of the attempted change. The new component I am trying to add it to is called newComp. I am pulling the bodies from another component passed in as comp:
import adsk.core, adsk.fusion, traceback
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
# Create a document.
doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
# Get the root component of the active design.
rootComp = design.rootComponent
# Create sketch
sketches = rootComp.sketches
sketch = sketches.add(rootComp.xZConstructionPlane)
sketchCircles = sketch.sketchCurves.sketchCircles
centerPoint = adsk.core.Point3D.create(0, 0, 0)
sketchCircles.addByCenterRadius(centerPoint, 3.0)
# Get the profile defined by the circle.
prof = sketch.profiles.item(0)
# Create an extrusion input
extrudes = rootComp.features.extrudeFeatures
extInput = extrudes.createInput(prof, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
# Define that the extent is a distance extent of 5 cm.
distance = adsk.core.ValueInput.createByReal(5)
extInput.setDistanceExtent(False, distance)
# Create the extrusion.
ext = extrudes.add(extInput)
# Get the body created by extrusion
body = ext.bodies.item(0)
# Create input entities for rectangular pattern
inputEntites = adsk.core.ObjectCollection.create()
inputEntites.add(body)
# Get x and y axes for rectangular pattern
xAxis = rootComp.xConstructionAxis
yAxis = rootComp.yConstructionAxis
# Quantity and distance
quantityOne = adsk.core.ValueInput.createByString('3')
distanceOne = adsk.core.ValueInput.createByString('8 cm')
quantityTwo = adsk.core.ValueInput.createByString('3')
distanceTwo = adsk.core.ValueInput.createByString('8 cm')
# Create the input for rectangular pattern
rectangularPatterns = rootComp.features.rectangularPatternFeatures
rectangularPatternInput = rectangularPatterns.createInput(inputEntites, xAxis, quantityOne, distanceOne, adsk.fusion.PatternDistanceType.SpacingPatternDistanceType)
# Set the data for second direction
rectangularPatternInput.setDirectionTwo(yAxis, quantityTwo, distanceTwo)
# Create the rectangular pattern
rectangularFeature = rectangularPatterns.add(rectangularPatternInput)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Appreciate the help.
Eric
Solved! Go to Solution.