Message 1 of 6
Copy a sketch from one component into another without changing its position in world space?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello, is it possible to copy a sketch, or at least recreate it, from its source component into another component with a different transform? In the image below I would like to copy the sketch in component 2 into component 1,without moving the global position of the sketch using the API.
I am not sure where I am going wrong here. Ay help is greatly appreciated. I have attached the test project above to make things easier.
import adsk.core, adsk.fusion, traceback
def run(context):
try:
app = adsk.core.Application.get()
ui = app.userInterface
design:adsk.fusion.Design = app.activeDocument.products.itemByProductType("DesignProductType")
# design.designType = adsk.fusion.DesignTypes.ParametricDesignType
root = design.rootComponent
occ1 = root.occurrences.item(0)
occ2 = root.occurrences.item(1)
comp1 = occ1.component
comp2 = occ2.component
#get the sketch to be copied
sketch = comp2.sketches.item(0)
#create the target sketch to copy the sketch into
newSketch = comp1.sketches.add(comp1.xYConstructionPlane)
sketchLines = adsk.core.ObjectCollection.createWithArray([line for line in sketch.sketchCurves.sketchLines])
transform = adsk.core.Matrix3D.create()
fO,fX,fY,fZ = occ1.transform2.getAsCoordinateSystem()
tO,tX,tY,tZ = occ2.transform2.getAsCoordinateSystem()
transform.setToAlignCoordinateSystems(fO,fX,fY,fZ,tO,tX,tY,tZ)
sketch.copy(sketchLines,transform,newSketch)
except:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))