Jump to content

Seeking script to create locus points at viewport bounding box


Recommended Posts

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.

script to create locus points at viewport bounding box.JPG

Link to comment

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);

 

  • Like 2
Link to comment
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.

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...