Community
3ds Max Programming
Welcome to Autodesk’s 3ds Max Forums. Share your knowledge, ask questions, and explore popular 3ds Max SDK, Maxscript and Python topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Link Two Viewports' View

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
rartidiello
436 Views, 9 Replies

Link Two Viewports' View

Hi,

I need to link 2 viewports view. Let's say Active Viewport and Floating Viewport - 1.  Because I add a Viewport Filter in which I only show Editable Poly objects in the Active Viewport and Editable Mesh objects in the Floating Viewport, and need to see them both at the same time from the same angle.

 

So far I use a camera and show it in both viewports but I don't like it since moving, modeling and checking a scene through a camera view is quite a mess in my opinion.

 

I was thinking maybe saving a perspective/orthographic view from Active Viewport and pasting it to Floating Viewport - 1 every a short period of time and viceversa in case Floating Viewport - 1 becomes the Active Viewport.

 

Thanks!

9 REPLIES 9
Message 2 of 10

Are you interested in learning how to do it, or are you looking for a working solution? 😉

Message 3 of 10

Right now more into a working solution 😁

Message 4 of 10

You are only working with one of the two linked viewports. The other one is needed for reference. If so, there is a safe way to link them - one would be a “free” viewport (static) and the other would be a camera view (floating).

Do you think this makes sense?

Message 5 of 10
rartidiello
in reply to: rartidiello

.

Message 6 of 10

Ideally it would be great to work with both viewports as if one was an instance of the other. But a first approach could be that. Can you explain your method?

Message 7 of 10

denisTMaxDoctor_0-1721695689910.gif

 

 

 

try(destroydialog ViewBinderRol) catch ()
rollout ViewBinderRol "Bind Views by denisT" width:191
(
	local g = (dotnetclass "autodesk.max.globalinterface").instance
	local x = g.COREInterface14

	local vp0 = 3
	local vp1 = 7
	
	fn canbind = 
	(
		local g = (dotnetclass "autodesk.max.globalinterface").instance
		local x  = g.COREInterface14
		
		if x != undefined then
		(
			x.GetViewExpByID vp0 != undefined and x.GetViewExpByID vp1 != undefined
		)
		else false	
	)
	
	local binding = off
	local working_color = (color 51 128 204)
	local picking_color = orange
	
	checkbutton bind_callback_cb "Bind Viewports" width:172 align:#left offset:[-4,0] enabled:(canbind())
		tooltip:"Use Bound Viewports\n   RC\t- Pick A Pair to Active" highlightcolor:working_color


	fn bindViewports = if not binding do
	(
		id = x.ActiveViewExp.ViewID
		
		if id == vp0 or id == vp1 do
		(
			binding = on
			
			if id == vp1 do swap vp0 vp1
		
			v0 = x.GetViewExpByID vp0
			v1 = x.GetViewExpByID vp1

			v1.SetAffineTM v0.AffineTM
			v1.SetFOV v0.FOV
			v1.SetFocalDistance v0.FocalDist

			v1.Invalidate true
			
			binding = off
		)
	)
	
	fn disableViewportBinder ui:off = 
	(
		callbacks.removeScripts id:#viewport_binder
		unregisterRedrawViewsCallback bindViewports
		if ui do 
		(
			bind_callback_cb.state = off
			bind_callback_cb.highlightcolor = working_color
		)
	)

	fn enableViewportBinder ui:off = 
	(
		disableViewportBinder()
		binding = off

		callbacks.addscript #viewportChange "(getproperty ::ViewBinderRol #bindViewports)()" id:#viewport_binder
	
		bind_callback_cb.highlightcolor = working_color
		bindViewports()
	)
	
	fn pickBoundingPair = 
	(
		vp1 = x.ActiveViewExp.ViewID
		if (vp1 != vp0) do
		(
			--xformat_ #active vp1 
			enableViewportBinder ui:off
		)
	)
	
	on bind_callback_cb rightclick do 
	(
		if bind_callback_cb.state then 
		(
			disableViewportBinder ui:on
		)
		else
		(
			vp0 = x.ActiveViewExp.ViewID
			disableViewportBinder ui:off
			
			bind_callback_cb.state = on
			bind_callback_cb.highlightcolor = picking_color
			callbacks.addscript #activeViewportChanged "(getproperty ::ViewBinderRol #pickBoundingPair)()" id:#viewport_binder	
		)
	)
	
	on bind_callback_cb changed state do
	(
		if state then if canbind() do
		(
			if canbind() then enableViewportBinder() else bind_callback_cb.state = off	
		)
		else disableViewportBinder ui:on
	)
	
	
	on ViewBinderRol close do
	(
		disableViewportBinder ui:on
	)
	on ViewBinderRol open do
	(
		disableViewportBinder ui:on
	)
)
createdialog ViewBinderRol

 

 

 

 

The idea works... and the script almost works. But I purposely left the tools unfinished and left a couple bugs out to give you a chance to learn something. 😉

 

  

 

Message 8 of 10
rartidiello
in reply to: rartidiello

.

Message 9 of 10

Thanks!

Yes, the script is working. As you mentioned it still has some bugs as when changing views inside the viewport it seems to lose the connection.

Also when I use this script to rapid switch to the viewport closest to viewpoint angle in perspective/orthogonal view , the "slave" viewport seems to lose its focal point of view or something like that.

-- -------------------------------------------------------------------------------------
-- Created: 20-07-2017
-- Updated: 23-09-2017
-- Version: 1.10
--
-- Author : Roman Nazarov / rnazarov@gmail.com /
--
-- Description: Switch active viewport to the view closely aligned to the screen axis.
-- The analog of behavior of constrain angle snap in ZBrush.
--
-- Usage: SET SHORTCUT KEY ON THIS SCRIPT
--
-- Special thanks to Rustam Arazov (aka rustm) for providing an idea.
-- --------------------------------------------------------------------------------------

macroScript RotationAxisSnap
category: "jaspar scripts"
tooltip: "Switch active viewport to the view closely aligned to the screen axis"
(
global sType;

vpType = viewport.getType()

if (vpType==#view_left or vpType==#view_right or vpType==#view_front or vpType==#view_back or vpType==#view_bottom or vpType==#view_top)
then(
try(
viewport.setType sType
actionMan.executeAction 0 "40228" -- Views: Restore Active View
)catch()
)
else (
temp = viewport.getTM() as EulerAngles

sType = viewport.getType()
actionMan.executeAction 0 "40227" -- Views: Save Active View

case of
(
(45<=temp.y and temp.y<=135): viewport.setType #view_left
(-45>=temp.y and temp.y>=-135): viewport.setType #view_right
((-45>=temp.x and temp.x>=-135) and (-45<=temp.y and temp.y<=45)): viewport.setType #view_front
((45<=temp.x and temp.x<=135) and (-45<=temp.y and temp.y<=45)): viewport.setType #view_back
((135<=temp.x and temp.x<=180) or (-135>=temp.x and temp.x>=-180)): viewport.setType #view_bottom
default: viewport.setType #view_top
)
max zoomext sel
)
completeredraw()
)

 

But it works so

Thanks a lot!

Message 10 of 10


@rartidiello wrote:

Thanks!

Yes, the script is working. As you mentioned it still has some bugs as when changing views inside the viewport it seems to lose the connection.

 


The main thing is not to give fish, but to teach how to catch them! 😉

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report