Jump to content

Welcome to eMastercam

Register now to participate in the forums, access the download area, buy Mastercam training materials, post processors and more. This message will be removed once you have signed in.

Use your display name or email address to sign in:

Nethook API for creating of a plane?


Doug Rice
 Share

Recommended Posts

I  am creating a plane to execute a Roll and translate on a surface.  I am  performing the following when running mastercam.

1.       Planes-> Create New Plane -> Relative to WCS -> Top Z: r_v -152

2.       Planes -> set new plane to C/T (construction/Tool Plane)

Link to comment
Share on other sites

@Doug Rice

I'm not sure what you meant with 'r_v -152 ' ?  A plane parallel to an existing plane is the same plane (same matrix) with just a new origin.

Here is a sample code

//Settings
		Point3D offset = new Point3D(10, 5, 3); // Origin offset value
		
		//Get original plane data from WCS selected
		MCView wcs = ViewManager.WorkCoordinateSystem; // Get WCS view
		Matrix3D matrixwcs = wcs.ViewMatrix; // Get WCS Matrix
		Point3D originwcs = wcs.ViewOrigin; // Get WCS Origin

		//Create a new plane with same matrix and origin offset
		MCView newPlane = new MCView();
		newPlane.ViewMatrix=wcs.ViewMatrix;
		newPlane.ViewOrigin = VectorManager.Add(originwcs,offset);
		newPlane.Commit();
		
		// Set C/T Plane
		ViewManager.CPlane=newPlane;
		ViewManager.TPlane=newPlane;
		ViewManager.RefreshPlanesManager();

CreatePlaneOffset.csx

  • Like 1
Link to comment
Share on other sites

Just in case here is an example with any transform rotation + prompt to enter data.

	public void Run()
	{	//Ask for origin offsets
		String offsetStr = "";
		DialogManager.AskForString("Enter origin offsets values from selected WCS (x,y,z)", ref offsetStr);
		string[] offsetCoord  = offsetStr.Split(',');
		Point3D offset = ViewManager.ConvertToWorldCoordinates(new Point3D(Convert.ToDouble(offsetCoord[0]),Convert.ToDouble(offsetCoord[1]),Convert.ToDouble(offsetCoord[2])));		

		//Ask for angles transformation
		String anglesStr = "";
		DialogManager.AskForString("Enter angle values (u,v,w) (degrees)", ref anglesStr);
		string[] angles  = anglesStr.Split(',');
		Double angleX = VectorManager.DegreesToRadians(Convert.ToDouble(angles[0]));
		Double angleY = VectorManager.DegreesToRadians(Convert.ToDouble(angles[1]));
		Double angleZ = VectorManager.DegreesToRadians(Convert.ToDouble(angles[2]));
		
		//Get original plane data from WCS selected
		MCView wcs = ViewManager.WorkCoordinateSystem; // Get WCS view
		Matrix3D matrixwcs = wcs.ViewMatrix; // Get WCS Matrix
		Point3D originwcs = wcs.ViewOrigin; // Get WCS Origin
		
		//Create a new plane with same matrix and origin offset
		MCView newPlane = new MCView();
		newPlane.ViewMatrix = wcs.ViewMatrix;
		newPlane.ViewOrigin = VectorManager.Add(originwcs, offset);

		//Transform matrix about X
		Matrix3D rotatedMatrix = newPlane.ViewMatrix;
		rotatedMatrix.Row1 = VectorManager.Rotate(rotatedMatrix.Row1, rotatedMatrix.Row1, angleX);
		rotatedMatrix.Row2 = VectorManager.Rotate(rotatedMatrix.Row2, rotatedMatrix.Row1, angleX);
		rotatedMatrix.Row3 = VectorManager.Rotate(rotatedMatrix.Row3, rotatedMatrix.Row1, angleX);
		
		//Transform matrix about Y
		rotatedMatrix.Row1 = VectorManager.Rotate(rotatedMatrix.Row1, rotatedMatrix.Row2, angleY);
		rotatedMatrix.Row2 = VectorManager.Rotate(rotatedMatrix.Row2, rotatedMatrix.Row2, angleY);
		rotatedMatrix.Row3 = VectorManager.Rotate(rotatedMatrix.Row3, rotatedMatrix.Row2, angleY);
		
		//Transform matrix about Z
		rotatedMatrix.Row1 = VectorManager.Rotate(rotatedMatrix.Row1, rotatedMatrix.Row3, angleZ);
		rotatedMatrix.Row2 = VectorManager.Rotate(rotatedMatrix.Row2, rotatedMatrix.Row3, angleZ);
		rotatedMatrix.Row3 = VectorManager.Rotate(rotatedMatrix.Row3, rotatedMatrix.Row3, angleZ);
		
		// Affect transformed matrix to view
		newPlane.ViewMatrix = rotatedMatrix;
		
		//Add plane to Mastercam database
		newPlane.Commit();
		
		// Set C/T Plane
		ViewManager.CPlane=newPlane;
		ViewManager.TPlane=newPlane;
		ViewManager.RefreshPlanesManager();
	}

CreatePlaneRotate.csx

  • Like 2
Link to comment
Share on other sites
  • 2 weeks later...

You can directly modify your original plane in view manager (but it wil update all your toolpaths using that plane) or you can create a new tilted plane and affect it to your facing operation.

You can change operation toolplane with field ToolPlane from Operation class.

Here is an example reusing example i wrote above.

Script will reverse toolplane of selected operations. It will create a new plane rotated 180° on X-axis from original plane and will affect it to Construction/Tool plane operations.

public void Run()
	{	
		// settings
		bool used = true ;  // True will only modify selected toopath

		// Get all operations from toolpath manager
		Operation[] toolpaths = SearchManager.GetOperations(used);
		
		// Iterate operations
		foreach (Operation op in toolpaths)
				{
				try 
					{
					//Angles transformation
					Double angleX = VectorManager.DegreesToRadians(180); //Convert.ToDouble(angles[0]));
					Double angleY = VectorManager.DegreesToRadians(0);  //Convert.ToDouble(angles[1]));
					Double angleZ = VectorManager.DegreesToRadians(0); //Convert.ToDouble(angles[2]));

					// Get original toolplane view
					MCView Tplane = op.ToolPlane;					

					//Get original toolplane data 
					Matrix3D matrixTplane = Tplane.ViewMatrix; // Get Matrix
					Point3D originTplane = Tplane.ViewOrigin; // Get Origin
					
					//Create a new plane with same matrix and origin offset
					MCView newPlane = new MCView();
					newPlane.ViewMatrix = matrixTplane;
					newPlane.ViewOrigin = originTplane;
			
					//Transform matrix about X
					Matrix3D rotatedMatrix = newPlane.ViewMatrix;
					rotatedMatrix.Row1 = VectorManager.Rotate(rotatedMatrix.Row1, rotatedMatrix.Row1, angleX);
					rotatedMatrix.Row2 = VectorManager.Rotate(rotatedMatrix.Row2, rotatedMatrix.Row1, angleX);
					rotatedMatrix.Row3 = VectorManager.Rotate(rotatedMatrix.Row3, rotatedMatrix.Row1, angleX);
					
					//Transform matrix about Y
					rotatedMatrix.Row1 = VectorManager.Rotate(rotatedMatrix.Row1, rotatedMatrix.Row2, angleY);
					rotatedMatrix.Row2 = VectorManager.Rotate(rotatedMatrix.Row2, rotatedMatrix.Row2, angleY);
					rotatedMatrix.Row3 = VectorManager.Rotate(rotatedMatrix.Row3, rotatedMatrix.Row2, angleY);
					
					//Transform matrix about Z
					rotatedMatrix.Row1 = VectorManager.Rotate(rotatedMatrix.Row1, rotatedMatrix.Row3, angleZ);
					rotatedMatrix.Row2 = VectorManager.Rotate(rotatedMatrix.Row2, rotatedMatrix.Row3, angleZ);
					rotatedMatrix.Row3 = VectorManager.Rotate(rotatedMatrix.Row3, rotatedMatrix.Row3, angleZ);
					
					// Affect transformed matrix to view
					newPlane.ViewMatrix = rotatedMatrix;
					
					//Add plane to Mastercam database
					newPlane.Commit();
					
					// Set C/T Plane to operation
					op.ConstructionPlane = newPlane;						
					op.ToolPlane = newPlane;
					op.Commit(true);
					op.Regenerate();	
					}
				catch
					{
					}	
				}
	ViewManager.RefreshPlanesManager();
	}

ReverseToolpathToolplane.csx

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

Join us!

eMastercam - your online source for all things Mastercam.

Together, we are the strongest Mastercam community on the web with over 56,000 members, and our online store offers a wide selection of training materials for all applications and skill levels.

Follow us

×
×
  • Create New...