Hi Abhishek,
What you need to do is to let the server code generate the script and response to Fusion. Then in the Fusion API, you can call eval to run the script.
For example, if your web service wants to generate some code to create a circle in Fusion with specified radius value, in the server side, you need some code like this:
public string GetCircleScript(double radius){
return "varapp=adsk.core.Application.get();"
+ "ui=app.userInterface;"
+ "var doc=app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType);"
+ "var product=app.activeProduct;"
+ "var design=adsk.fusion.Design(product);"
+ "var rootComp=design.rootComponent;"
+ "var sketches=rootComp.sketches;"
+ "var xyPlane=rootComp.xYConstructionPlane;"
+ "var sketch=sketches.add(xyPlane);"
+ "var circles=sketch.sketchCurves.sketchCircles;"
+ "var circle=circles.addByCenterRadius(adsk.core.Point3D.create(0,0,0)," + radius.toString() + ");";
}
In Fusion side, you will get the respsonse string as follows if you send the request with radius=2:
var responseText="var app = adsk.core.Application.get();ui = app.userInterface;var doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType);var product = app.activeProduct;var design = adsk.fusion.Design(product);var rootComp = design.rootComponent;var sketches = rootComp.sketches;var xyPlane = rootComp.xYConstructionPlane;var sketch = sketches.add(xyPlane);var circles = sketch.sketchCurves.sketchCircles;var circle = circles.addByCenterRadius(adsk.core.Point3D.create(0, 0, 0), 2); ";
Then you can simply call the following code to run the script to create the circle in Fusion:
eval(responseText);
Shirley
Developer for Fusion Electronics
Autodesk, Inc.