Hi…
I still have a problem. I’ve temporarily abandoned the MoveExtended extension to concentrate on moving.
On loading, I set up a list containing TreeNodes, a Vecto3 to store the current position after each move and a list of your batchObjects.
type TypeRevitSpeckle = {
node: TreeNode;
currentCenter: Vector3;
batchObjects: BatchObject[]; // Liste des objets batch associés
};
The first time the person moves from 0,0,0, I translate to 1,1,0. It works.
Next, I store my object’s new coordinates in my typeRevitSpeckles list.
The console.log shows me 1,1,0.
The next move is to 1,-2,0, but there’s a problem: the person moves to 0,1,0.
Now I don’t get it!
First translation
Second translation
Voici mon code…
//Function to Move current TreeNode
function MoveTreeNode() {
if (!_treeNodeSelected) return;
const currentElementId = _treeNodeSelected.model.raw.elementId;
if (!currentElementId) return;
if (!typeRevitSpeckles) return;
// Affichage des centres de chaque boîte englobante avec window.alert
// Vérifier si SpecialityEquipmentNodes est vide ou null
if (typeRevitSpeckles) {
// Trouver le TypeRevitSpeckle correspondant à l'élément sélectionné
const foundTypeRevitSpeckle = findTypeRevitSpeckleByElementId(
typeRevitSpeckles,
currentElementId
);
// Affichage des TreeNodes trouvés
//console.log(`Number of filteredNode with elementId ${elementIdToSearch} is ${filteredNodes.length}`);
if (foundTypeRevitSpeckle) {
/*
node: TreeNode;
currentCenter: Vector3;
*/
const tn: TreeNode = foundTypeRevitSpeckle.node;
const currentCenter = foundTypeRevitSpeckle.currentCenter;
/*calcul du vecteur de déplacement par rapport à la position speckle
de l'objet sélectionné
*/
const newPosition = new Vector3(
REVIT_COORDINATES.x,
REVIT_COORDINATES.y,
REVIT_COORDINATES.z
);
const translation = new Vector3(
REVIT_COORDINATES.x - currentCenter.x,
REVIT_COORDINATES.y - currentCenter.y,
REVIT_COORDINATES.z - currentCenter.z
);
if (isNaN(translation.x)) {
translation.x = 0;
}
if (isNaN(translation.y)) {
translation.y = 0;
}
if (isNaN(translation.z)) {
translation.z = 0;
}
console.log("Translation:", translation);
console.log("NewPosition:", newPosition);
/*
node est le TreeNode Speckle correspondant
currentCenter: Vector3; position actuelle du TreeNode
batchObjects: BatchObject[]; // Liste des objets batch associés
*/
foundTypeRevitSpeckle.batchObjects.forEach(
(batchObject: BatchObject) => {
batchObject.transformTRS(
translation,
undefined,
undefined,
undefined
);
}
);
/*
moveExtension.MoveTreeNode(
_treeNodeSelected,
translation,
currentCenter
);
*/
viewer.requestRender();
/*
type TypeRevitSpeckle = {
node: TreeNode;
currentCenter: Vector3;
};
*/
const foundIndex = typeRevitSpeckles.findIndex(
(item) => item.node.model.raw.elementId === currentElementId
);
if (foundIndex !== -1) {
//MAJ du foundTypeRevitSpeckle
typeRevitSpeckles[foundIndex].currentCenter = newPosition;
}
typeRevitSpeckles.forEach((item, index) => {
if (item.node.model.raw.elementId != currentElementId) return;
console.group("After moving :");
console.log("Node elementid :", item.node.model.raw.elementId);
console.log(
"Current Center after translation is :",
item.currentCenter
);
console.groupEnd();
});
/*
https://codesandbox.io/p/sandbox/categorize-forked-s6p6z6?file=%2Fsrc%2FBoxSelection.ts%3A122%2C60
*/
} else {
console.log(
`No TypeRevitSpeckle found with elementId ${currentElementId}`
);
}
}
}
my sandbox.io