@@ -346,5 +346,155 @@ GS::ObjectState ReloadLibrariesCommand::Execute (const GS::ObjectState& /*parame
346346 return CreateErrorResponse (APIERR_COMMANDFAILED, " Reloading Libraries failed. Check internet connection if you have active libraries from BIMcloud!" );
347347 }
348348
349+ return {};
350+ }
351+
352+
353+ // --- MoveElementsCommand ----------------------------------------------------------------------------------
354+
355+ GS::String MoveElementsCommand::GetName () const
356+ {
357+ return " MoveElements" ;
358+ }
359+
360+
361+ constexpr const char * ElementsWithMoveVectorsParameterField = " elementsWithMoveVectors" ;
362+ constexpr const char * ElementIdField = " elementId" ;
363+ constexpr const char * GuidField = " guid" ;
364+ constexpr const char * MoveVectorField = " moveVector" ;
365+ constexpr const char * CopyField = " copy" ;
366+
367+
368+ GS::Optional<GS::UniString> MoveElementsCommand::GetInputParametersSchema () const
369+ {
370+ return GS::UniString::Printf (R"( {
371+ "type": "object",
372+ "properties": {
373+ "%s": {
374+ "type": "array",
375+ "description": "The elements with move vector pairs.",
376+ "items": {
377+ "type": "object",
378+ "properties": {
379+ "%s": {
380+ "$ref": "APITypes.json#/definitions/ElementId"
381+ },
382+ "%s": {
383+ "type": "object",
384+ "description" : "Move vector of a 3D point.",
385+ "properties" : {
386+ "x": {
387+ "type": "number",
388+ "description" : "X value of the vector."
389+ },
390+ "y" : {
391+ "type": "number",
392+ "description" : "Y value of the vector."
393+ },
394+ "z" : {
395+ "type": "number",
396+ "description" : "Z value of the vector."
397+ }
398+ },
399+ "additionalProperties": false,
400+ "required" : [
401+ "x",
402+ "y",
403+ "z"
404+ ]
405+ },
406+ "%s": {
407+ "type": "boolean",
408+ "description" : "Optional parameter. If true, then a copy of the element will be moved. By default it's false."
409+ }
410+ },
411+ "additionalProperties": false,
412+ "required": [
413+ "%s",
414+ "%s"
415+ ]
416+ }
417+ }
418+ },
419+ "additionalProperties": false,
420+ "required": [
421+ "%s"
422+ ]
423+ })" ,
424+ ElementsWithMoveVectorsParameterField,
425+ ElementIdField,
426+ MoveVectorField,
427+ CopyField,
428+ ElementIdField, MoveVectorField,
429+ ElementsWithMoveVectorsParameterField);
430+ }
431+
432+
433+ static API_Guid GetGuidFromElementIdField (const GS::ObjectState& os)
434+ {
435+ GS::String guid;
436+ os.Get (GuidField, guid);
437+ return APIGuidFromString (guid.ToCStr ());
438+ }
439+
440+
441+ static API_Vector3D GetVector3DFromMoveVectorField (const GS::ObjectState& os)
442+ {
443+ API_Vector3D v;
444+ os.Get (" x" , v.x );
445+ os.Get (" y" , v.y );
446+ os.Get (" z" , v.z );
447+ return v;
448+ }
449+
450+
451+ static GSErrCode MoveElement (const API_Guid& elemGuid, const API_Vector3D& moveVector, bool withCopy)
452+ {
453+ GS::Array<API_Neig> elementsToEdit = { API_Neig (elemGuid) };
454+
455+ API_EditPars editPars = {};
456+ editPars.typeID = APIEdit_Drag;
457+ editPars.endC = moveVector;
458+ editPars.withDelete = !withCopy;
459+
460+ return ACAPI_Element_Edit (&elementsToEdit, editPars);
461+ }
462+
463+
464+ GS::ObjectState MoveElementsCommand::Execute (const GS::ObjectState& parameters, GS::ProcessControl& /* processControl*/ ) const
465+ {
466+ GS::Array<GS::ObjectState> elementsWithMoveVectors;
467+ parameters.Get (ElementsWithMoveVectorsParameterField, elementsWithMoveVectors);
468+
469+ API_Guid elemGuid;
470+ const APIErrCodes err = (APIErrCodes) ACAPI_CallUndoableCommand (" Move Elements" , [&] () -> GSErrCode {
471+ for (const GS::ObjectState& elementWithMoveVector : elementsWithMoveVectors) {
472+ const GS::ObjectState* elementId = elementWithMoveVector.Get (ElementIdField);
473+ const GS::ObjectState* moveVector = elementWithMoveVector.Get (MoveVectorField);
474+ if (elementId == nullptr || moveVector == nullptr ) {
475+ continue ;
476+ }
477+
478+ elemGuid = GetGuidFromElementIdField (*elementId);
479+
480+ bool copy = false ;
481+ elementWithMoveVector.Get (CopyField, copy);
482+
483+ const GSErrCode err = MoveElement (elemGuid,
484+ GetVector3DFromMoveVectorField (*moveVector),
485+ copy);
486+ if (err != NoError) {
487+ return err;
488+ }
489+ }
490+
491+ return NoError;
492+ });
493+
494+ if (err != NoError) {
495+ const GS::UniString errorMsg = GS::UniString::Printf (" Failed to move element with guid %T!" , APIGuidToString (elemGuid).ToPrintf ());
496+ return CreateErrorResponse (err, errorMsg.ToCStr ().Get ());
497+ }
498+
349499 return {};
350500}
0 commit comments