Sam Jones Posted September 14, 2022 Share Posted September 14, 2022 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? 😊😇 Quote Link to comment
Pat Stanford Posted September 14, 2022 Share Posted September 14, 2022 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); Quote Link to comment
Sam Jones Posted September 14, 2022 Author Share Posted September 14, 2022 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, Quote Link to comment
Pat Stanford Posted September 14, 2022 Share Posted September 14, 2022 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); Quote Link to comment
Sam Jones Posted September 14, 2022 Author Share Posted September 14, 2022 I tried to get the handle to the viewport handle with FSActLayer(sheetLayerHandle), and got 0, 0 back even though the VP was not at 0,0. Before I dive deep into the above, have you been working with objects in a drawing whose user origin has been moved? Quote Link to comment
Sam Jones Posted September 14, 2022 Author Share Posted September 14, 2022 12 minutes ago, Pat Stanford said: SetObjectVariableReal(H2, 1003, 12); Why are you doing this? You seem to be setting the layer scale of the viewport to 12. 12?? Quote Link to comment
Pat Stanford Posted September 14, 2022 Share Posted September 14, 2022 1:12 was the layer scale I used on the design layer so the 1" boxes I drew would show easily. 12 for the Viewport is 1:12 or the same scale as the design layer. It was a new blank file when I started, so I doubt the user origin has been moved. Quote Link to comment
Sam Jones Posted September 15, 2022 Author Share Posted September 15, 2022 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. Quote Link to comment
Jesse Cogswell Posted September 15, 2022 Share Posted September 15, 2022 @Sam Jones To get the actual center of the VP, you would use something like this: GetOriginInDocUnits(Origin.x,Origin.y); HCenter(h,A.x,A.y); result.x:=A.x+Origin.x; result.y:=A.y+Origin.y; With h being a handle to the Viewport. Quote Link to comment
Sam Jones Posted September 16, 2022 Author Share Posted September 16, 2022 (edited) 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 September 16, 2022 by Sam Jones Add code example Quote Link to comment
Jesse Cogswell Posted September 16, 2022 Share Posted September 16, 2022 @Sam Jones Weird, when I test it (at least in VW2019), doing result:=A.x - Origin.x gets me the inverse of the coordinate, which is useful when in conjunction with an HMove command to center the VP, but not if you are just looking for the coordinate center of the VP. Quote Link to comment
Sam Jones Posted September 16, 2022 Author Share Posted September 16, 2022 I think that explains the difference. Your result provides the VP Center on the sheet layer, and my code computes the needed delta to center the VP on the page. Cool. I understand better now. Quote Link to comment
Recommended Posts
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.