In C++, DirectDesignType, Moving Does Not Work

In C++, DirectDesignType, Moving Does Not Work

tperam
Advocate Advocate
715 Views
2 Replies
Message 1 of 3

In C++, DirectDesignType, Moving Does Not Work

tperam
Advocate
Advocate
In C++, DirectDesignType, Moving SketchLines, Arc, Circle in my following code Does Not Work.
 
It goes upto:
Ptr<MoveFeatureInput> moveFeatureInput = moveFeats->createInput(ObjectColl, transform);
 
But Skips the following line:
Ptr<MoveFeature> moveFeature = moveFeats->add(moveFeatureInput);
 
The my code is as below:
 
Regards,
Thurai.

extern "C" XI_EXPORT bool run(const char* context)
{
 app = Application::get();
 if (!app)
  return false;
        ui = app->userInterface();
 if (!ui)
  return false;
 
 Ptr<Documents> documents = app->documents();
 if (!documents)
  return false;
 
 Ptr<Document> doc = documents->add(DocumentTypes::FusionDesignDocumentType);
 if (!doc)
  return false;
 //des = adsk.fusion.Design.cast(app.activeProduct),
 Ptr<Product> product = app->activeProduct();
 if (!product)
  return false;

       Ptr<Design> design = product;
 if (!design)
  return false;
 // In C++ Specifying Design Type: Set the value of the property, where value_var is a DesignTypes.
        bool ReturnValue = design->designType(DirectDesignType);
 if(!ReturnValue)
 return false;
 // Get the root component of the active design.
 Ptr<Component> rootComp = design->rootComponent();
 if(!rootComp)
  return false;
 
 // Create a new sketch on the xy plane.
 Ptr<Sketches> sketches = rootComp->sketches();
 if (!sketches)
  return false;
 
 Ptr<ConstructionPlane> xyPlane = rootComp->xYConstructionPlane();
 if (!xyPlane)
  return false;
 Ptr<Sketch> sketch = sketches->add(xyPlane);
 if (!sketch)
  return false;
        Ptr<SketchCurves> sketchCurves = sketch->sketchCurves();
 if(!sketchCurves)
  return false;
 Ptr<SketchLines> sketchLines = sketchCurves->sketchLines();
  if(!sketchLines)
  return false;
        Ptr<SketchCircles> sketchcCircles = sketchCurves->sketchCircles();
        if (!sketchcCircles)
         return false;

 Ptr<SketchArcs> sketchArcs = sketchCurves->sketchArcs();
 if (!sketchArcs)
  return false;

    ui->messageBox("Before bulkhead.sketchPoints");
 // Get sketch texts
 Ptr<SketchPoints> sketchPoints = sketch->sketchPoints();
 if (!sketchPoints)
  return false;
 ui->messageBox(" After bulkhead.sketchPoints");
 Ptr<Point3D> Pts[4];
        Pts[0] = Point3D::create(0.0,0.0,0.0);
        Pts[1] = Point3D::create(-10.0,0.0,0.0);
        Pts[2] = Point3D::create(-10.0,-5,0.0);
 
  //sketchPoints
 Ptr<SketchPoint> sketchPoint[4];
 
       unsigned int I;
 for (I = 0; I <= 2 ; I++)
       {//I
        sketchPoint[I] = sketchPoints->add(Pts[I]);
        if(!sketchPoint[I])
         return false;
       }//I
        string msg;
 ui->messageBox(" After bulkhead.sketchPoints[I] 0 to 2 ");
 
        Ptr<SketchLine> MyLines[2];
   MyLines[0] = sketchLines->addByTwoPoints( Pts[0], Pts[1]);
 if(!MyLines[0])
 return false;
 MyLines[1] = sketchLines->addByTwoPoints( Pts[1], Pts[2]);
 if(!MyLines[1])
    return false;

       Ptr<SketchArc> arc0 = sketchArcs->addFillet(MyLines[0], MyLines[0]->endSketchPoint()->geometry(), MyLines[1], MyLines[1]->startSketchPoint()->geometry(), 0.5);
        if (!arc0)
         return false;
           
 Pts[3] = Point3D::create(-10.0,-5,0.0);
        Ptr<SketchCircle> circle0 = sketchcCircles->addByCenterRadius(Pts[3], 1.0);
         if (!circle0)
         return false;
        sketchPoint[3] = sketchPoints->add(Pts[3]);
        Ptr<ObjectCollection> ObjectColl = adsk::core::ObjectCollection::create();
         if(!ObjectColl)
          return false;
        ObjectColl->add(MyLines[0]);
        ObjectColl->add(MyLines[1]);
        ObjectColl->add(arc0);
        ObjectColl->add(circle0);
    msg = " After  ObjectColl->add(); ";
 ui->messageBox(msg);
      // Create a transform to do move
 Ptr<Vector3D> vector = adsk::core::Vector3D::create(2.0, 3.0, 0.0);
 if(!vector)
 return false;
 Ptr<Matrix3D> transform = adsk::core::Matrix3D::create();
 if(!transform)
 return false;
 transform->translation(vector);

 Ptr<Features> features = rootComp->features();
 if(!features)
  return false;

 // Create a move feature
 Ptr<MoveFeatures> moveFeats = features->moveFeatures();
 if(!moveFeats)
  return false;
 Ptr<MoveFeatureInput> moveFeatureInput = moveFeats->createInput(ObjectColl, transform);
 if(!moveFeatureInput)
  return false;
 msg = " After   moveFeatureInput ";
 ui->messageBox(msg);
 Ptr<MoveFeature> moveFeature = moveFeats->add(moveFeatureInput);
 if(!moveFeature)
  return false;
 msg = " After   moveFeature ";
 ui->messageBox(msg);

 return true;
}
 
 
 
 
 
 
0 Likes
Accepted solutions (1)
716 Views
2 Replies
Replies (2)
Message 2 of 3

BrianEkins
Mentor
Mentor
Accepted solution

The move command behaves in different ways depending on the context.  If you move a Body, then the move command results in the creation of move feature so that modification is tracked in the timeline and is recomputed when any of the previous geometry is modified.  However, when working with sketch geometry, a move feature is not created but the geometry is transformed and the fact that they were moved is forgotten.  To perform a move operation with sketch geometry, use the move method on the Sketch object.  In your program, you can remove the last section of your code where you're dealing with a move feature and replace it with this single line.

 

	sketch->move(ObjectColl, transform);
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 3 of 3

tperam
Advocate
Advocate

Thanks Brian.

 

It works.

 

Regards,

Thurai

0 Likes