Solved
Geting Model Position
- November 21, 2023
- 1 reply
- 1829 views
Dear Community
I've found some code to get the position of an assembly part here:
But it doesn't seem to work for me
$scope.centerof = function() {
// Get the Structure information for model-1
PTC.Structure.fromId('model-1').then ( (structure) => {
// Get the properties of the 'model-1' widget
var widgetProps = $scope.view.wdg['model-1'];
// Get the bounding box information for part '/0/0/2'
var bbox = structure.getBounds('/0/0/2');
// Transform the bounding box to account for the 'model-1' widget's location
var xform_bbox = bbox.transform(
[widgetProps.x, widgetProps.y, widgetProps.z],
[widgetProps.rx, widgetProps.ry, widgetProps.rz],
widgetProps.scale);
// Move '3DImage-1' to the center of the bounding box
$scope.view.wdg['3DImage-1'].x = xform_bbox.center.x;
$scope.view.wdg['3DImage-1'].y = xform_bbox.center.y;
$scope.view.wdg['3DImage-1'].z = xform_bbox.center.z;
// Get the location information for part '/0/2/8'
var loc = structure.getLocation('/0/0/2');
// Transform the location to account for the 'model-1' widget's location
var xform_loc = loc.transform(
[widgetProps.x, widgetProps.y, widgetProps.z],
[widgetProps.rx, widgetProps.ry, widgetProps.rz],
widgetProps.scale);
// Get the rotational component as euler angles
var rot = xform_loc.rotation.asEuler();
// Rotate '3DImage-2' to match the rotation
$scope.view.wdg['3DImage-1'].rx = rot.x;
$scope.view.wdg['3DImage-1'].ry = rot.y;
$scope.view.wdg['3DImage-1'].rz = rot.z;
});
}
I've added a demo experience to troubleshoot the issue.
Does anyone know what's wrong?
Best wishes
Alex


