unearthed Posted December 5, 2024 Share Posted December 5, 2024 To reduce file sizes with graphical elements I often export an image of a viewport (or a group of elements), and then reimport that image file. As VW’s image file export dialogue is idiosyncratic at best I normally place two locus points (at top left and bottom right in enclosed graphic). I set them out a mm or so (from the corners) to produce a slight oversize image (with a mm or so of white space) and avoid a pixelated edge, and then use the loci to snap to a precise window via the image export dialogue. The loci also provide a way to accurately measure viewport width, again to be able to produce a quality file via the image export dialogue. I’d be quite happy with a script that drew locus points, one at each corner. Has anyone written or is there already a script to place locus points to define the bounding box of an object in this case a view port? In my screenshot of the viewport I have left the view port crop on as a visual guide as this defines the viewport bounding box. Quote Link to comment
Jesse Cogswell Posted December 5, 2024 Share Posted December 5, 2024 Here you go. This will work for all selected objects within the container you are in (layer, symbol edit, viewport crop or annotation, etc). PROCEDURE BoundingBoxLocusPoints; {* Places locus points at the corners of the bounding box of all selected objects Developed by: Jesse Cogswell Date: 12/5/2024 Revisions: *} VAR parentHd:HANDLE; objArr:DYNARRAY[] OF HANDLE; numObj:INTEGER; PROCEDURE AddToArray(h:HANDLE); {Checks parent of given object and if matching current container, adds to global array} BEGIN IF(GetParent(h) = parentHd) THEN BEGIN numObj:=numObj + 1; ALLOCATE objArr[1..numObj]; objArr[numObj]:=h; END; END; PROCEDURE CreatePoints(arr:DYNARRAY[] OF HANDLE; num:INTEGER); {Pulls bounding box for each object in given array and creates locus points} VAR i:INTEGER; A,B:POINT; BEGIN FOR i:=1 TO num DO BEGIN GetBBox(arr[i],A.x,A.y,B.x,B.y); Locus(A.x,A.y); Locus(B.x,A.y); Locus(A.x,B.y); Locus(B.x,B.y); END; END; BEGIN numObj:=0; Locus(0,0); parentHd:=GetParent(LNewObj); DelObject(LNewObj); ForEachObject(AddToArray,(INSYMBOL & INVIEWPORT & (SEL))); IF(numObj > 0) THEN CreatePoints(objArr,numObj) ELSE SysBeep; END; Run(BoundingBoxLocusPoints); 2 Quote Link to comment
Pat Stanford Posted December 5, 2024 Share Posted December 5, 2024 If you don't want all four Loci, you can just comment out ( put curly braces {}) around the Loci Lines you don't want. A.x, A.y should be top left B.x, B.y should be bottom right. 2 Quote Link to comment
unearthed Posted December 5, 2024 Author Share Posted December 5, 2024 39 minutes ago, Jesse Cogswell said: Here you go. This will work for all selected objects within the container you are in (layer, symbol edit, viewport crop or annotation, etc). PROCEDURE BoundingBoxLocusPoints; {* Places locus points at the corners of the bounding box of all selected objects Developed by: Jesse Cogswell Date: 12/5/2024 Revisions: *} VAR parentHd:HANDLE; objArr:DYNARRAY[] OF HANDLE; numObj:INTEGER; PROCEDURE AddToArray(h:HANDLE); {Checks parent of given object and if matching current container, adds to global array} BEGIN IF(GetParent(h) = parentHd) THEN BEGIN numObj:=numObj + 1; ALLOCATE objArr[1..numObj]; objArr[numObj]:=h; END; END; PROCEDURE CreatePoints(arr:DYNARRAY[] OF HANDLE; num:INTEGER); {Pulls bounding box for each object in given array and creates locus points} VAR i:INTEGER; A,B:POINT; BEGIN FOR i:=1 TO num DO BEGIN GetBBox(arr[i],A.x,A.y,B.x,B.y); Locus(A.x,A.y); Locus(B.x,A.y); Locus(A.x,B.y); Locus(B.x,B.y); END; END; BEGIN numObj:=0; Locus(0,0); parentHd:=GetParent(LNewObj); DelObject(LNewObj); ForEachObject(AddToArray,(INSYMBOL & INVIEWPORT & (SEL))); IF(numObj > 0) THEN CreatePoints(objArr,numObj) ELSE SysBeep; END; Run(BoundingBoxLocusPoints); Thanks so much Jesse! that works perfectly And thanks to Pat Stanford for how to change point number. 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.