Accurately Insert a Block in Simulink Model based on Mouse Position.

2 ビュー (過去 30 日間)
ES
ES 2013 年 10 月 16 日
コメント済み: Guillaume 2023 年 9 月 14 日
Hi, I want to insert a Block into a Simullink Model from Right Click Menu. The block should be inserted into the exact 'position' of the mouse right click. To calculate the 'position' i use
locationBase = get_param(modelName,'Location');%To account for floating windows etc
scrollOffset = get_param(modelName,'ScrollbarOffset');%To account for ScrollBar Position
I calculate the 'position' by
p_X = mousePositionX - locationBase(1) + scrollOffset(1);
p_Y = screenSizeY - mousePositionY - locationBase(2) + scrollOffset(2) ;
I add the block dimensions to find the 'position' to insert the blocks like this.
location = [p_X p_Y p_X+BlockWidth+BlockHeight];
This works well if the Model Browser is not open. If Model Browser is open, It adds additional offset to the position and the Blocks are inserted at the wrong place. How can I include offsets created by the Model Browser?
  1 件のコメント
Abhishek Vaidya
Abhishek Vaidya 2020 年 3 月 1 日
How are you finding out the mousePositionX and mousePositionY

サインインしてコメントする。

採用された回答

Zack Peters
Zack Peters 2013 年 10 月 25 日
編集済み: Zack Peters 2013 年 10 月 25 日
The system has parameters named 'ModelBrowserVisibility' and 'ModelBrowserWidth'. I would suggest checking if the visibility is on and if so then add the 'ModelBrowserWidth' as an offset to the Y position of the 'location' variable.
~Zack
  1 件のコメント
Guillaume
Guillaume 2023 年 9 月 14 日
Hello,
This topic is quite old but I have the same issue. 'ModelBrowserWidth' seems to be no more available (R2022b), is there any other way to get this width information ? Thank you.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgrammatic Model Editing についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by