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:

Recommended Posts

I am writing a VB script that uses a programmer defined point and then creates geometry based on that point location. The catch is I want to prompt the programmer to indicate a point on the screen (right click mouse) during the VB script then use that point location to add the geometry. Can this be done? If so, any one have any suggestions on how?

Link to comment
Share on other sites

Here is one way, it should give you some ideas.

 

Call Main()
' ////////////////////
' Sub Declaration
' ////////////////////
Sub Main()
   ' -- Define a point object to hold user pick point co-ords
Dim CPoint
Set CPoint = New McPt

With CPoint
        .X = 0
        .Y = 0
        .Z = 0
End With 

  ' -- Prompt user for a point on the screen 
  If askPoint(CPoint) Then

       ' -- Define an Arc object
	Dim CArc
	Set CArc = New McAr

	' -- Set some properties
	With CArc
         .X = CPoint.X
         .Y = CPoint.Y
         .Z = CPoint.Z
         .R = 1
         .SA = 0
         .SW = 360
         .VIEW = mcVIEW_TOP
	End With 

	Dim ret

  	' -- Create arc at the user pick point
  	ret  = CreateArc(CArc, mcCOLOR_LIGHTGREEN , 1)

  End If
End Sub

Link to comment
Share on other sites
  • 4 years later...

The VB Script askPoint just retrieves World coordinates,

just like the NETHook's AskForPoint, but in the Script there is no ConvertToViewCoordinates function.

 

I would use a NETHook (VB or C# as shown below)

 

You can use the free Microsoft Visual Studio "Express" editions for building NETHooks.

VS 2008 or VS 2010 for X5 and VS 2010 for X6

*If you use VS 2010 for an X5 NETHook be sure to set the target NET Framework version less than v4.0

For X6 you can use the v4.0 .NET Framework, but not for X5, as it did not exist when X5 was released.

 

/// <summary> Prompt the user to select a point position. </summary>
/// <param name="display"> Display the point coordindates? (debugging) </param>
/// <param name="prompt"> The "prompt" to display to the user. </param>
/// <param name="pt"> The Point data (in current CPlane View). </param>
/// <returns> Success/Failure </returns>
public bool GetPointFromUser(bool display, string prompt, ref Mastercam.Math.Point3D pt)
{
   bool result = Mastercam.IO.SelectionManager.AskForPoint(prompt, Mastercam.IO.Types.PointMask.Null, ref pt);
   if (result)
   {
       if (display)
       {
           string dataWorld = string.Format("X: {0}\nY: {1}\nZ: {2}", pt.x, pt.y, pt.z);
           MessageBox.Show(dataWorld, "Point (World)", MessageBoxButtons.OK, MessageBoxIcon.Information);
       }

       Mastercam.Database.MCView cPlane = Mastercam.IO.ViewManager.CPlane;
       // Convert the World coordinates of the point to a specific View# (in this case the CPlane)
       //Mastercam.Math.Point3D ptInView = Mastercam.IO.ViewManager.ConvertToViewCoordinates(pt, cPlane.ViewNumber);

       // Convert the World coordinates of the point to the current CPlane View
       pt = Mastercam.IO.ViewManager.ConvertToViewCoordinates(pt);

       if (display)
       {
           string dataView = string.Format("View#: {0}\nName: {1}\nX: {2}\nY: {3}\nZ: {4}",
                                           cPlane.ViewNumber, cPlane.ViewName, pt.x, pt.y, pt.z);
           MessageBox.Show(dataView, "Point (View)", MessageBoxButtons.OK, MessageBoxIcon.Information);
       }
   }

  return result;
}

  • Like 1
Link to comment
Share on other sites

NETHook debugging should be quite simple.

 

In your Project Properties, select the Debug tab and set...

Start external program: full path to your Mastercam.exe

Working directory: path the your main Mastercam folder.

*See attached image. <- This is VS 2010 Professional

 

For VS 2010 Express you'll need to set the .EXE and Working folder another way - See Below...

 

Now in Visual Studio set a Breakpoint on the desired code line(s).

Now Debug, Start Debugging (F5)

Mastercam should start up.

If needed, load up your test MCX file.

Run the the DEBUG build of your NETHook project's DLL.

Settings - Run User Application and be sure to select the DEBUG build of your DLL

(Usually in the <project>\bin\Debug folder)

or to make it a bit easier, I set that DLL has the default

Setting - Configuration - Start/Exit(page)

and in the Add-In programs groupbox, set the Default to point to the desired DLL.

Then it is just Settings-Run User Application [enter]

-or-

You can even setup an FT (Function Table) file for you NETHook that points to the DEBUG DLL.

Now you can place an icon on a toolbar that will fire off your NETHook.

 

* Visual Studio 2010 Express *

The DEBUG settings for a project in Visual Studio 2010 Express are different.

You don't have all of the options shown as in the Professional (and higher $$$) versions.

But... There is a simple way around that. ;)

You just need to supply a simple file for your Project that sets up this information, by creating a (text) file with your C# project's name + ".user"

 

For example, you have a C# NETHook project file -> MySuperAddOn.csproj

 

You would create a file called MySuperAddOn.csproj.user

in the same folder as your .csproj file that contains the data shown here ->

(Of course you may need to adjust the paths for where Mastercam is installed on your system.

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
   <StartAction>Program</StartAction>
   <StartProgram>C:\Program Files (x86)\mcamx5\Mastercam.exe</StartProgram>
   <StartWorkingDirectory>C:\Program Files (x86)\mcamx5</StartWorkingDirectory>
 </PropertyGroup>
</Project>

For a VB.NET project it's the same except this ".user" file would have vbproj instead of csproj -> 'MySuperAddOn.vbproj.user

 

*** After you add this new .user file, you'll need to restart/reload your NETHook project so that Visual Studio Express will read it. ***

post-1117-0-84268700-1321375658_thumb.jpg

Link to comment
Share on other sites
  • 9 years later...
On 11/15/2011 at 7:17 AM, Roger Martin from CNC Software said:

/// <summary> Prompt the user to select a point position. </summary> /// <param name="display"> Display the point coordindates? (debugging) </param> /// <param name="prompt"> The "prompt" to display to the user. </param> /// <param name="pt"> The Point data (in current CPlane View). </param> /// <returns> Success/Failure </returns> public bool GetPointFromUser(bool display, string prompt, ref Mastercam.Math.Point3D pt) { bool result = Mastercam.IO.SelectionManager.AskForPoint(prompt, Mastercam.IO.Types.PointMask.Null, ref pt); if (result) { if (display) { string dataWorld = string.Format("X: {0}\nY: {1}\nZ: {2}", pt.x, pt.y, pt.z); MessageBox.Show(dataWorld, "Point (World)", MessageBoxButtons.OK, MessageBoxIcon.Information); } Mastercam.Database.MCView cPlane = Mastercam.IO.ViewManager.CPlane; // Convert the World coordinates of the point to a specific View# (in this case the CPlane) //Mastercam.Math.Point3D ptInView = Mastercam.IO.ViewManager.ConvertToViewCoordinates(pt, cPlane.ViewNumber); // Convert the World coordinates of the point to the current CPlane View pt = Mastercam.IO.ViewManager.ConvertToViewCoordinates(pt); if (display) { string dataView = string.Format("View#: {0}\nName: {1}\nX: {2}\nY: {3}\nZ: {4}", cPlane.ViewNumber, cPlane.ViewName, pt.x, pt.y, pt.z); MessageBox.Show(dataView, "Point (View)", MessageBoxButtons.OK, MessageBoxIcon.Information); } } return result; }

Thanks Roger, this example made the difference for me, a newbby in the Chooks /C# world, I am getting the converted values for my application.  Cheers!! 

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