Jump to content
Developer Wiki and Function Reference Links ×

Location of a viewport on its sheet layer.


Sam Jones

Recommended Posts

Is it possible to get the location of a viewport on its sheet layer?

HCenter(ViewPort, X1, Y1);     yields its location on the source design layer.  I would like to locate it on the sheet layer.  If the user origin has not been moved and I create a VP with a location of 0,0 on a design layer, it ends up at 0,0 on the parent sheet layer.   If the user origin has been moved the VP ends up somewhere else.  If I make the parent sheet layer active, and select the viewport, I can send it back to 0,0 (the center of the page), by entering 0 in the X and Y coordinates in the OIP.  So, in VS, how would I get the location of the VP on the sheet layer so that I can move the VP with and HMove() call?

😊😇

 

 

Link to comment

Not what I am seeing in VW2023.

 

HCenter and GetBBox when passed a handle to a viewport both return the location relative to the 0,0 of the Sheet Layer they are on. Are you sure you are passing the correct handle to HCenter?

 

Procedure Test;

VAR	H1		:Handle;
	X1,Y1,X2,Y2, X3, Y3	:Real;

BEGIN
	H1:=FSActLayer;
	GetBBox(H1,X1,Y1,X2,Y2);
	HCenter(H1, X3,Y3);
	
	Message(Date(2,2),'  ',X1,' ',Y1,' ',X2,' ',Y2,'  ---  ',X3,' ',Y3);
End;

Run(Test);

 

Link to comment

OK, the process, in VW 2022.

1. Create a design layer

2. Create objects from X1 to X2 all at (X#, 0).

3. Select All

4. Create Viewport with

          TheVP := CreateVP(ParentSheetLayer);

5. Try HCenter(TheVP, vpX, vpY

 

vpX and vpY return 0,0 unless the origin has been moved; in which case they return other stuff.

 

What you are doing is getting the handle of the first object on the sheet layer and assuming that it is the viewport.  That might actually work for me but what if there are other viewports, or even objects on the sheet layer?

 

I'll try some stuff and see if I can get it to work. 

 

Thanks,

Link to comment

Get the handle to the viewport however you want. 


What I was trying to demonstrate is that BBox and HCenter both return the correct location.

 

This one draws the objects, including a crop, makes the VP, and then returns the position before and after a move.  Seems correct to me.  Both BBox and HCenter seem to return the proper values both before moving the viewport and after.

 

May (or may not) need more RedrawAll and/or ResetObject.

 

Procedure Test;

VAR	H1, H2, H3			:Handle;
	X1,Y1,X2,Y2, X3, Y3	:Real;
	B1					:Boolean;

BEGIN
	Rect(0,0,1',1');
	Rect(0,2',1',3');
	Rect(0,4',1',5');
	Rect(0,0,1',5');  {Crop ObjectType}
	H3:=LNewObj;
	H1:=GetLayerByName('Sht-1');  {rename to match your sheet layer name}
	H2:=CreateVP(H1);
	B1:=SetVPCropObject(H2,H3);
	B1:=SetVPLayerVisibility(H2, GetLayerByName('Design Layer-1'), 0);  {Zero is normal visibility, -1, invisible, 4, grey}
	B1:=SetVPClassVisibility(H2, 'None',0);
	SetObjectVariableReal(H2, 1003, 12);
	
	ResetBBox(H2);
	ResetObject(H2);

	GetBBox(H2,X1,Y1,X2,Y2);
	HCenter(H2, X3,Y3);
	
	Layer('Sht-1');	
	ReDraw;
	AlrtDialog(Concat('Created:  ',X1,' ',Y1,' ',X2,' ',Y2,'  ---  ',X3,' ',Y3));
	
	HMove(H2, 2", 2");
	
	GetBBox(H2,X1,Y1,X2,Y2);
	HCenter(H2, X3,Y3);
	
	ReDraw;	
	AlrtDialog(Concat('Moved:  ',X1,' ',Y1,' ',X2,' ',Y2,'  ---  ',X3,' ',Y3));
End;

Run(Test);

 

Link to comment

A

44 minutes ago, Pat Stanford said:

It was a new blank file when I started, so I doubt the user origin has been moved.

Ah.  That's the issue.  If the user origin is not moved there is no problem.  I need to know where, on the sheet layer, the VP ended up if, at the beginning of the whole process the user origin has beem moved away from the document/page origin.

Link to comment

Jesse,

Thank you!  You nailed it.        Except that it should be

result.x:=A.x - Origin.x;

result.y:=A.y - Origin.y;

 

Still, you found the magic sauce:

GetOriginInDocUnits(Origin.x,Origin.y);

 

I had done a get origin at the beginning of the command, but manipulating the VP in the doc units was crucial in moving the VP to the correct location.

👍👍

 

                                    {IF the Viewport is not in the center of the sheet layer, center it on 0,0}
                                    GetOriginInDocUnits(OriginBx, OriginBy);
                                    HCenter(TrussTapeVP, X1, Y1);
                                    DeltaX := X1 - OriginBx;
                                    DeltaY := Y1 - OriginBy;
                                    HMove(TrussTapeVP, DeltaX, DeltaY);

Edited by Sam Jones
Add code example
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...