Jump to content

Dhananjay Naidu

Member
  • Posts

    1
  • Joined

  • Last visited

Posts posted by Dhananjay Naidu

  1. On 6/9/2021 at 8:53 AM, Jesse Cogswell said:

    I could write a script that could pull in the XYZ locations of all selected loci and essentially use that data to "connect the dots" with a 3D polygon, but I think the biggest obstacle to making it work properly is that there is no real way to pull the order in which connect the loci.  Calling a ForEachObject callback would be the most efficient, but it will follow in the order in which the loci were created with little regard to their physical location.  Imagine you wanted to create a square with four loci, A (0,0), B (1,0), C (1,1), and D (0,1).  There's no real easy way to tell the script to create a poly in A,B,C,D order, the script might create a poly in A,C,D,B order, resulting in an hourglass shape.

     

    Someone much smarter than me could probably write an algorithm to determine a clockwise or anti-clockwise path between a selection of points, but I can't think of an easy way off the top of my head without attaching a record to each loci with the poly creation order in it, but assigning that would take more time than drawing the polygon by hand.

     

    If you can assure that the points are created in the correct order, then the script below should do the trick.

    PROCEDURE CreatePolyFromPoints;
    
    {*	Creates a 2D polygon from a selection of 2D Locus points and/or a 3D polygon from a selection of 3D Locus points
    	Developed by: Jesse Cogswell
    	Date: 6/8/2021
    	VW Version: 2019
    *}
    
    VAR
    
    	lociPoints:DYNARRAY[] OF POINT;
    	lociPoints3D:DYNARRAY[] OF POINT3D;
    	numPoints:INTEGER;
    	currentLayer:STRING;
    	finalPoly,finalPoly3D:HANDLE;
    	deleteCheck:BOOLEAN;
    
    PROCEDURE PollThePoints(h:HANDLE);
    
    {Generates array of XY locations of selected points}
    
    	VAR
    	
    		p1:POINT;
    
    	BEGIN
    		numPoints:=numPoints+1;
    		ALLOCATE lociPoints[1..numPoints];
    		GetLocPt(h,p1.x,p1.y);
    		lociPoints[numPoints]:=p1;
    		
    		IF(deleteCheck=TRUE) THEN DelObject(h);
    	END;
    	
    PROCEDURE PollThePoints3D(h:HANDLE);
    
    {Generates array of XYZ locations of selected 3D points}
    
    	VAR
    	
    		p1:POINT3D;
    		
    	BEGIN
    		numPoints:=numPoints+1;
    		ALLOCATE lociPoints3D[1..numPoints];
    		Get3DCntr(h,p1.x,p1.y,p1.z);
    		lociPoints3D[numPoints]:=p1;
    		
    		IF(deleteCheck=TRUE) THEN DelObject(h);
    	END;
    	
    FUNCTION CreatePolygon(points:DYNARRAY[] OF POINT; nPoints:INTEGER) : HANDLE;
    
    {Creates a polygon from given array of points and returns handle to polygon}
    
    	VAR
    	
    		i:INTEGER;
    		h:HANDLE;
    
    	BEGIN
    		ClosePoly;
    		BeginPoly;
    			FOR i:=1 TO nPoints DO AddPoint(points[i].x,points[i].y);
    		EndPoly;
    		
    		CreatePolygon:=LNewObj;
    	END;
    	
    FUNCTION CreatePolygon3D(points:DYNARRAY[] OF POINT3D; nPoints:INTEGER) : HANDLE;
    
    {Creates a 3D polygon from given array of points and returns handle to polygon}
    
    	VAR
    	
    		i:INTEGER;
    		h:HANDLE;
    		
    	BEGIN
    		CLosePoly;
    		BeginPoly3D;
    			FOR i:=1 TO nPoints DO Add3DPt(points[i].x,points[i].y,points[i].z);
    		EndPoly3D;
    		
    		CreatePolygon3D:=LNewObj;
    	END;
    
    BEGIN
    	numPoints:=0;
    	currentLayer:=GetLName(ActLayer);
    	
    	deleteCheck:=YNDialog('Delete Locus Points after creation?');
    	
    	ForEachObject(PollThePoints,((SEL=TRUE) & (L=currentLayer) & (T=LOCUS)));
    	IF(numPoints>1) THEN finalPoly:=CreatePolygon(lociPoints,numPoints);
    	
    	numPoints:=0;
    	
    	ForEachObject(PollThePoints3D,((SEL=TRUE) & (L=currentLayer) & (T=LOCUS3D)));
    	IF(numPoints>1) THEN finalPoly3D:=CreatePolygon3D(lociPoints3D,numPoints);
    END;
    
    Run(CreatePolyFromPoints);

    The script will follow the points in the order of their creation and gives you an option to delete the locus points afterward.  The script will handle 2D and 3D locus points and will generate accordingly, but separately.  If you include a selection of 2D and 3D points, the script will generate a separate 2D and 3D polygon.  Also keep in mind that it will be restricted to points on the active layer only to prevent it from misreading points still selected on a different layer (in case your Layer Options are set to Show/Snap).

     

    Let me know if this works for you or if this totally breaks something.  It worked in my admittedly brief amount of testing on VW2019, but there's no reason it shouldn't work in VW2021.

    Works for me in VW 2023.
    Many thanks

×
×
  • Create New...