• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How do I center a selected element to the stage using code in camera mode?

New Here ,
Apr 15, 2024 Apr 15, 2024

Copy link to clipboard

Copied

I encountered a little difficulty, as follows, when I used the camera, the elements that were originally centered on the stage were moved to the outside of the stage.
I hope that after using the command to select the element, it can be automatically centered without being affected by the camera.
I checked the relevant API. When the camera is not turned on, the command works fine. However, after it is turned on, it cannot be centered. The xy position information of the element is different when the camera is turned on and off.
Can you provide some implementation ideas? Or give the relevant code directly, thank you very much!

01.png02.png03.png

Views

101

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 16, 2024 Apr 16, 2024

Hi.

 

The camera will offset and scale everything on stage according to its settings. Centering won't happen on selection. 

 

You need to adjust camera's x, y, and zoom properties accordingly to get the results that you want.

 

Regards,

JC

Votes

Translate

Translate
Community Expert ,
Apr 16, 2024 Apr 16, 2024

Copy link to clipboard

Copied

Hi.

 

The camera will offset and scale everything on stage according to its settings. Centering won't happen on selection. 

 

You need to adjust camera's x, y, and zoom properties accordingly to get the results that you want.

 

Regards,

JC

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 17, 2024 Apr 17, 2024

Copy link to clipboard

Copied

LATEST

111.png

When I paste elements copied from other documents into the current document, because the camera is offset, the elements will be very far away and very difficult to find.
The following is one of my ideas. First get the xy coordinates of the camera and apply them to the selected element (while exchanging the xy position), but you can only move the element near the stage.

//Get the current camera coordinates
var tl = an.getDocumentDOM().getTimeline();
var currentFrame = tl.currentFrame;
var cameraPos = tl.camera.getPosition(currentFrame);
an.trace("Camera position: x = " + cameraPos.x + ", y = " + cameraPos.y);
var selection = an.getDocumentDOM().selection[0]; 
// Set the position of the selected element to the position of the camera
selection.x = cameraPos.y;
selection.y = cameraPos.x;
an.getDocumentDOM().selectNone();

I may have missed something, but there is no reason why it can't be implemented. This camera should also have its own range box. The manual contains too little content. I can't figure out what other feasible methods are available.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines