Use API to Mirror Sketch

Use API to Mirror Sketch

Anonymous
Not applicable
1,868 Views
5 Replies
Message 1 of 6

Use API to Mirror Sketch

Anonymous
Not applicable

There are many examples to Sketch Features.

 

I can't find one for Mirroring lines.

 

Any help appreciated. Thanks

0 Likes
Accepted solutions (1)
1,869 Views
5 Replies
Replies (5)
Message 2 of 6

BrianEkins
Mentor
Mentor
Accepted solution

The equivalent of the Mirror command is not available in the API.  However, it is possible to still end up with the same results.  You can create the geometry that is the mirror image and then add the symmetry constraint between it and the original geometry so that it continues to behave correctly.  The GeometricConstraints collection supports the AddSymmetry method.  You'll mostly apply this to the points because the geometry is dependent on them.  The exception to this is arcs and circles to be able to control the radius.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 6

Anonymous
Not applicable

Thanks. 


Took a few hours to get from that to something that actually worked

  • First got it to work in GUI
  • Don't forget to make points that are on the mirror line symetric!

Then some code

        app = adsk.core.Application.get()
        ui  = app.userInterface
        product = app.activeProduct
        rootComp = product.rootComponent
        sketch = rootComp.sketches.add(rootComp.xYConstructionPlane,)
        
        #draw line
        p1    = adsk.core.Point3D.create(1,1,0)     
        p2    = adsk.core.Point3D.create(2,2,0)     
        line1 = sketch.sketchCurves.sketchLines.addByTwoPoints(p1, p2)
        
        #create a mirror (constructin) line 
        x1    = adsk.core.Point3D.create(0,0,0)     
        x2    = adsk.core.Point3D.create(0,2,0)     
        lineX = sketch.sketchCurves.sketchLines.addByTwoPoints(x1, x2)
        lineX.isConstruction = True 
        
        #mirrorline(s) - Draw on top of lines, mirror will move them 
        m1      = adsk.core.Point3D.create(1,1,0) 
        m2      = adsk.core.Point3D.create(2,2,0) 
        mirror1 = sketch.sketchCurves.sketchLines.addByTwoPoints(m1, m2)
            
        #Add Symatry (Don't forget to add points on the mirror line )
        sketch.geometricConstraints.addSymmetry(line1.startSketchPoint, mirror1.startSketchPoint, lineX)
        sketch.geometricConstraints.addSymmetry(line1.endSketchPoint,   mirror1.endSketchPoint, lineX)
0 Likes
Message 4 of 6

MichaelT_123
Advisor
Advisor

Hi Mr. Ekins

 

Mirroring in geometry and even topology has been known for a long time. Even Aphrodite has been using it quite often.

From a mathematical standpoint is done by reversing axis sign (not a secret at all), so simple addition of this functionality (on sketch or model level will do the trick ... no matter what). It is sad to see that people desperate for such operation, resort to spending hours.... writing their own scripts!

As I pointed out in my previous post, they deserve a Nobel prize for the excessive determination.

To switch to a better mood... Just imagine the committee Smiley LOL.

 

With Regards

MichaelT

 

Mr. Ekins, although this is a replay to your post, it is actually addressed to the whole TF360.

 

MichaelT
0 Likes
Message 5 of 6

Anonymous
Not applicable

True it is simple to just draw the other side, reversing the axis. 

 

I needed actual mirroring. Where the if I latter grabbed a point and moved it, the other side would move as well.

 

Thanks

0 Likes
Message 6 of 6

ben
Observer
Observer

Just another pathetic example of self-absorbed developers who ignore the "if it's not broke don't fix it" axiom.

 

They have taken a simple and useful feature and replaced it with something obtuse and complicated....

0 Likes