Macro to move a viewport

Macro to move a viewport

ArthurADas
Advocate Advocate
798 Views
2 Replies
Message 1 of 3

Macro to move a viewport

ArthurADas
Advocate
Advocate

Hi,

Im looking for a code in C# or VB.NET that moves my viewport to a specific position in my sheet view.

Ive never programmed something in my life, so i started looking through the Autodesk materials. Well, that's a lot that i need to learn in order to understand what is what and finally start to write some codes. Since i'm kinda desperate right now and running out of time, i was hoping to get some help around here. 

What i have is: A sheet with only one viewport and a few spreadsheets. Since im working with scales, my viewport tends to move to a different position everytime i change the scale. With this Macro i could, somehow, move it always to the same place that it was before changing the scale. 

0 Likes
799 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

@ArthurADas 

I am having a nightmare situation with sheets and views myself, thanks to differing view sizes.

 

However, assuming you are using the same title block, something like this:

 

newSheetViewPort.SetBoxCenter(templateSheetViewPort.GetBoxCenter())

 

Should get you fairly close.

 

Thanks,

 

Matt

0 Likes
Message 3 of 3

jlpgy
Advocate
Advocate

Hi:

Try this one:

UiView.ZoomAndCenterRectangle
UIView..::..ZoomAndCenterRectangle Method
UIView Class See Also Send Feedback
 
Zoom and center the view to a specified rectangle.

Namespace: Autodesk.Revit.UI
Assembly: RevitAPIUI (in RevitAPIUI.dll) Version: 20.0.0.0 (20.0.0.377)
Since:  2013

 
Syntax
C#
public void ZoomAndCenterRectangle(
	XYZ viewCorner1,
	XYZ viewCorner2
)
Visual Basic
Public Sub ZoomAndCenterRectangle ( _
	viewCorner1 As XYZ, _
	viewCorner2 As XYZ _
)
Visual C++
public:
void ZoomAndCenterRectangle(
	XYZ^ viewCorner1, 
	XYZ^ viewCorner2
)
Parameters viewCorner1 Type: Autodesk.Revit.DB..::..XYZ
A corner of the desired view rectangle in model coordinates. viewCorner2 Type: Autodesk.Revit.DB..::..XYZ
The opposite corner of the desired view rectangle in model coordinates.
单身狗;代码狗;健身狗;jolinpiggy@hotmail.com
0 Likes