MoI discussion forum
MoI discussion forum

Full Version: View Manager Script

Show messages:  1-20  21-40  41-45

From: Teddy Lindsey (TEDDYLINDSEY)
9 Nov 2020   [#1]
This script allows you to save specific camera views of your model that can be easily restored.



I've found this to be very useful when I'm working on a model that needs to be exported as PDF or Adobe Illustrator and I need a precise camera orientation to be restored after making repeated edits on a model. The line art on the box for one of my models was generated using MOI's CopyToClipboardPDF() function and then pasted into Affinity Designer for layout of the print design.



Usage
Activate the View Manager script (I have it bound to my "V" key) and it will bring up a panel with a list of saved views which will initially be empty. Clicking the Create button will create an item called "View 1" in the list which will store the camera view for the 3D viewport. You can reorient the camera and click Create again, which will save additional views, each named sequentially.



Selecting a view from the list will reorient the camera to that saved view.

Clicking on the Rename View button will bring up an input field so you can rename the currently selected view.

Clicking the Delete button will remove the currently selected view.

Saved View Data File
Since there currently isn't a way to embed the saved view data directly into a 3DM file, the View Manager creates a "views.json" file located alongside the currently open file. The file is named after the base filename, excluding numeric version suffixes.

This allows you to share views across multiple versions of a model you are working on, e.g., you can open up "My Model.3dm" or "My Model 07.3dm" and have access to the same saved views using the file named "My Model.views.json".

Please note that this script will create a file in the same directory as your model with the same filename and the extension ".views.json" immediately after the script is activated.

Installation
Extract the attached ViewManager_v0.1.zip archive and move the ViewManager.htm and ViewManager.js files into your MOI Commands folder.

On Mac the folder is located at /Users/[your user name]/Library/Application Support/Moi/commands

On Windows the folder is located C:\Documents and Settings\[your user name]\Application Data\Moi\commands

If you use CustomUI, it should appear in your Scripts menu. You can also bind a hotkey to the command "ViewManager" to activate it.

Thanks to Michael for tips on scripting with MOI so that I could create this script!

Attachments:
View Manager 0.2.3.zip

Image Attachments:
scout_and_box.JPG  view_manager_create_view.jpg  view_manager_scout.jpg 


From: bemfarmer
9 Nov 2020   [#2] In reply to [#1]
Hi Teddy,

This looks to be a very useful script.
>>>>>

As I have been having a lot of trouble (in general) in manipulating the 3DView of some object with the mouse, (why I do not know, maybe it is the hi-def monitor?),
I would also like to have a 3DViewMgr script which would switch the 3DView to various camera positions. An example would be to view the object in 3DView, with the orientation comparable to the Top View, etc.. This would give the mouse manipulation in 3DView a fresh start to deviate from a TopView orientation a bit.

There may be some existing scripts? Not sure.
>>>

I've also recently noticed that a bunch of my old shortcuts reference add-on scripts without the _ prefix, so they do not work from the shortcut. This must
have been faulty for a long time...(but is my fault.)


- Brian
From: Teddy Lindsey (TEDDYLINDSEY)
9 Nov 2020   [#3] In reply to [#2]
Brian (bemfarmer), I hope you do find the script useful! Seems like we both had the same need for a view manager of some kind.

With regards to what you originally posted about having a view that's oriented exactly like one of the orthographic views, you can edit the .views.json file manually and put in specific values to get a precise camera and target view. In the example below, the target is located at the XYZ origin but the camera is located 250 units above the XY plane, yielding a camera view like the Top orthographic view.

Example:
code:
{
    "version": "0.1",
    "views": [
        {
            "name": "Top",
            "camera": "0,0,250",
            "target": "0,0,0"
        }
    ]
}

From: bemfarmer
9 Nov 2020   [#4] In reply to [#3]
Thank you Teddy,.

- B
From: Larry Fahnoe (FAHNOE)
9 Nov 2020   [#5]
Hi Teddy,

Very handy script, thanks! This certainly beats my keeping notes on the settings in Options > View > 3D view angles.

--Larry
From: bemfarmer
10 Nov 2020   [#6] In reply to [#2]
So my problem with 3D view manipulation was the Option View Rotate/Pan/Zoom was set to World Z Axis.
I prefer Free Rotation, most of the time.
- Brian

I think a script for some 3D View camera position presets might be useful.
Did some searches back as far as 2016, re camera and target.
See Michael's script "SetNearestOrthoView".
From: TOM (SIRTOM)
19 Nov 2020   [#7]
Fantastic ! Thank you !
From: Teddy Lindsey (TEDDYLINDSEY)
21 Nov 2020   [#8]
I'm glad that folks are finding it useful! Please let me know if you run into any bugs or have improvements to suggest.

- Teddy
From: pixelhouse
22 Mar 2022   [#9]
hmm, it seems that the position of the saved view is inverted and I see my model from the bottom side.
I have tested out different angles and positions in Moi V4 but every saved position are totaly wrong.

I hit "v" (my shortcut for this script) to save the position of the view, its open the window to manage the saved positions. This works fine!
To hide the window I click "Cancel" so I can select and hide objects and hit v again to save the next view.
When I will go back to an defined position I hit v to open the window, I select my saved view and the camera is changing to the new position. But the position isn`t correct.



Best regards
Jörg

edit:

Here screensots of the position that I saved and the saved position from the View Manager.

Image Attachments:
screenshot viewmanager01.JPG  screenshot viewmanager02.JPG 


From: Michael Gibson
22 Mar 2022   [#10] In reply to [#9]
Hi Jörg, I tested over here and it was working fine for me.

I think the issue is that you're probably using Options > View > Rotate/Pan/Zoom options > Rotation style = "Free rotation" instead of "Rotate around world z axis" mode.

Currently this ViewManager script only saves and restores a camera and a target point, it does not save or restore the "up" direction that defines the view's rotation around that line.

This isn't an issue when using Rotation style = "Rotate around world z axis" view rotation mode because that mode always keeps the "up" direction along the world z axis. But when using Rotation style = "Free rotation" you can have some other "up direction" which will be lost.

I think it should only take a minor adjustment to the script to make it additionally save and restore the "up" direction, I'll give that a try.

- Michael
From: Michael Gibson
22 Mar 2022   [#11] In reply to [#9]
Hi Jörg, please give this updated version a try, it should save and restore the "up" direction too now.

- Michael

EDIT: Updated to work with locales that have comma as decimal point separator, new version a few messages down.
From: pixelhouse
22 Mar 2022   [#12] In reply to [#11]
Hi Michael,

I use the correct settings (world) for the rotation. I'm using another laguage, but this sould be not the problem.
I have made a screenshot of the Rotate/Pan/Zoom settings.

With the new script the model is rotating vertically.

I have nbo idea what the problem is.


Thanks for your support, guys!
Jörg




Image Attachments:
screenshot settings.JPG 


From: coi (MARCO)
23 Mar 2022   [#13] In reply to [#12]
nah..doesn't work here either.
From: Michael Gibson
23 Mar 2022   [#14] In reply to [#12]
Hi Jörg, what version do you have under Help > About MoI ?

- Michael
From: Michael Gibson
23 Mar 2022   [#15] In reply to [#12]
Hi Jörg, can you also please post an example .3dm file and the .views.json file that ViewManager saved?

Maybe it's an issue with the ViewManager script only saving out 2 decimal places when it writes out coordinate information to the .view.json file.

Or it could be a localization problem when commas are used for the decimal places. If I can see the output that it generated on your system maybe that will help me to figure out the problem.

- Michael
From: Teddy Lindsey (TEDDYLINDSEY)
23 Mar 2022   [#16] In reply to [#15]
Michael: thanks for jumping in and fixing the issue with the View Manager Script not handling the "up direction"!

It sounds like it might be helpful to separate out the X, Y and Z values for the camera, target and up Idirection into separate fields in the JSON to avoid localization issues with how commas are handled. I'd be happy to refactor script to handle this as well as a bug I've found that can cause duplication of views when renaming them.

Since it's been a while since I wrote this, I wanted to consult some documentation on scripting for Moi, but it looks like the sites I've used in the past are no longer around, e.g., http://moi.maxsm.net/api/

Can you point me to another site where I might be able to reacquaint myself with the API?
From: Michael Gibson
23 Mar 2022   [#17] In reply to [#16]
Hi Teddy, I think the Internet Archive snapshot of Max's API page might work:
https://web.archive.org/web/20200218200812/http://moi.maxsm.net:80/api/

re: Localization issue - I'm not really sure yet if that's why it's not working for some people. Maybe that can be confirmed or ruled out by checking out an example saved view file.

- Michael
From: Michael Gibson
23 Mar 2022   [#18] In reply to [#16]
Ok, I think it is a comma as decimal separator locale problem. The problem is the MoI point's toString() method uses a locale dependent method for making UI presentable text and the View Manager script is using that.

Here's a quick fix putting in a ptToString() function using built in toFixed() Javascript number to string conversion which shouldn't be locale dependent.

- Michael

EDIT: removed this version, there is a newer one right below.
From: Teddy Lindsey (TEDDYLINDSEY)
23 Mar 2022   [#19]
I've attached an update (View Manager v.0.2.1) that incorporates the latest fixes from Michael for the locale-specific comma problem in addition to the following improvements:
- Fixed a bug where renaming a view might cause duplicate views.
- Improved logic for creating new View names to avoid duplicating an existing View name.

- Teddy

Attachments:
View Manager 0.2.1.zip


From: Michael Gibson
23 Mar 2022   [#20] In reply to [#19]
Thanks Teddy!

- Michael

Show messages:  1-20  21-40  41-45