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:

Roger Martin from CNC Software

CNC Software
  • Posts

    2,870
  • Joined

  • Last visited

  • Days Won

    6

Posts posted by Roger Martin from CNC Software

  1. Peter,

    STL Container -> Use them.

    Zaffin's statement here are words of wisdom.

    11 hours ago, Zaffin said:

    A (very) wise women once said "If you don't know what type of container you need, use a vector". 

    If you take advantage of lambdas and iterators you can likely measure the performance between any of the STL containers just by changing the type.

     

     

     

     

  2. Pete,

    I have no idea what you have going on here. The constructor error make no sense.

    To be sure that the code in the previous post was not mangled, I copied that code directly from that post to a C++/CLI project (that references the NETHook API).

    And... It builds, runs and produces the expected result. Tested in Mastercam 2018 and 2020.

    Expanding it out to include processing of Surfaces/Solids may be a bit more involved.

    To see exactly what the "type" you're dealing with, add some diagnotics.

    auto gt = selectedEnts->GetType ();
    System::Diagnostics::Debug::WriteLine ("gt=> " + gt->ToString ());
    if (gt == pointType) {...}

     

  3. Try this.

    /// <summary> Get the selected wireframe geometry by type. </summary>
    ///
    /// <param name="points"> [out] The points. </param>
    /// <param name="lines">  [out] The lines. </param>
    /// <param name="arcs">   [out] The arcs. </param>
    void SelectedWireframeGeometryByType (
    	System::Collections::Generic::List<Mastercam::BasicGeometry::PointGeometry ^> ^points,
    	System::Collections::Generic::List<Mastercam::Curves::LineGeometry ^> ^lines,
    	System::Collections::Generic::List<Mastercam::Curves::ArcGeometry ^> ^arcs)
    	{
    	auto pointType = Mastercam::BasicGeometry::PointGeometry::typeid;
    	auto lineType = Mastercam::Curves::LineGeometry::typeid;
    	auto arcType = Mastercam::Curves::ArcGeometry::typeid;
    
    	auto selectedEnts = Mastercam::Support::SearchManager::GetSelectedGeometry ();
    
    	// Iterate through each wireframe entity 
    	for (auto i = 0; i < selectedEnts->Length; i++)
    		{
    		auto gt = selectedEnts[i]->GetType ();
    		if (gt == pointType)
    			{
    			// dynamic_cast here is like the "as" keyword in C#
    			points->Add (dynamic_cast<Mastercam::BasicGeometry::PointGeometry ^> (selectedEnts[i]));
    			}
    		else if (gt == lineType)
    			{
    			lines->Add (dynamic_cast<Mastercam::Curves::LineGeometry ^> (selectedEnts[i]));
    			}
    		else if (gt == arcType)
    			{
    			arcs->Add (dynamic_cast<Mastercam::Curves::ArcGeometry ^> (selectedEnts[i]));
    			}
    		}	
    	}
    
    void TestGetByType ()
    	{
    	auto points = gcnew System::Collections::Generic::List<Mastercam::BasicGeometry::PointGeometry ^> ();
    	auto lines = gcnew System::Collections::Generic::List<Mastercam::Curves::LineGeometry ^> ();
    	auto arcs = gcnew System::Collections::Generic::List<Mastercam::Curves::ArcGeometry ^> ();
    
    	SelectedWireframeGeometryByType (points, lines, arcs);
    	auto msg = System::String::Format ("{0} - Points\n{1} - Lines\n{2} - Arcs", points->Count, lines->Count, arcs->Count);
    	System::Diagnostics::Debug::WriteLine (msg);
    
    	// Using the 'native' MessageBox here just so that we don't need to reference System::WindowsForms.
    	MessageBox (nullptr, CString (msg), _T ("Wireframe Geometry"), MB_ICONINFORMATION);
    	}

     

  4. Where at the “source” points coming from?
    Are you having the user select the Point geometry entities to be translated?
    Or, are you going to have your add-in do this selecting?
    Once you have the “source” points you could translate them it a couple ways…

    In the Mastercam.IO.ViewManager class you have multiple overloads of these methods ->
    ConvertToWorldCoordinates and ConvertToViewCoordinates
    You could convert the coordinate data for each source point using ConvertToWorldCoordinates.
    Then convert that new (world) point into the desire target view using ConvertToViewCoordinates.
    -or-
    In the Mastercam.GeometryUtility.GeometryManipulationManager class you have the TranslateGeometry method.
     

    /// <summary> XForm-Translate all the 'selected' geometry entities. </summary>
    ///
    /// NOTE!
    /// Any Geometry objects that get altered will NOT be reflected in that entity's data
    /// "on the NET-Hook side" if that entity's data is being held in a NET-Hook Geometry object! 
    /// You can use SearchManager.GetResultGeometry to retrieve the result of the XForm operation. 
    /// If a supplied view is null, the active Construction View will be used.
    /// If there was no 'selected' geometry found to be XForm'd, the return result will be 'true'.
    /// Also note that all 'selections' will be cleared by the XForm operation.
    ///
    /// <param name="FromPoint"> The 'from' point (in world coordinates). </param>
    /// <param name="ToPoint"> The 'to' point (in world coordinates). </param>
    /// <param name="FromView"> The 'from' view. </param>
    /// <param name="ToView"> The 'to' view. </param>
    /// <param name="Copy"> true to copy, else false to move. </param>
    ///
    /// <returns> true if it succeeds, false if it fails. </returns>

     

    • Thanks 1
  5. NET-Hook API Reference Guide
    https://nethookdocs.mastercam.com

    Search for: "DrillPoint"
    See: DrillPoint Constructor (ArcGeometry)

    In a "Point-Based" type operation in the NET-Hook API...
    The toolpath geometry assigned to it are "DrillPoint" objects.
    The operation has the "DrillPoints" member data that contains these points.

    -Pseudo code-

    // MyArc - is an existing ArcGeometry object.
    // MyDrillOp - is a "Point-Based" type operation.

    var drillPt = new DrillPoint(MyArc);
    MyDrillOp.DrillPoints.Add(drillPt);
    MyDrillOp.Commit();
    MyDrillOp.Regenerate(); 
                            

  6. Quote

    ...visual scripting for MasterCAM

    Forget about VB Scripting in Mastercam, as no further development will be happening with the old style VBScript support within Mastercam.
    You want to develop your add-in using the NET-Hook API (C#, VB.NET) or the the C-Hook SDK (C++, C++/CLI).

    Quote

    ...pass the 3D point coordinates (x,y,z), along with the view number to have the application return converted coordinates values for x,y,z.

    So, you are basically translating the points "between views"?
     

  7. OK...

     You're trying to chain what, on which level, while having the chaining ignore what type(s) of geometry?

    You're said you're doing this by blanking the unwanted entities, which while this will work...

    You don't like the need to have to call rebuild_graphics after. Fair enough, as that can take some time to complete.

    There may be other ways to segregate the wanted from the unwanted geometry when chaining.

    If I have details, I may be able to offset suggestions,

  8. Quote

    could the call set_clr_sel_bits() be interfering

    Depends if you're messing with the BLANK_BIT when using this.

    So you are "blanking" the items you don't want included in the chain(s) and then chaining all on that level?

    Quote

    In order to avoid inadvertently chaining existing geometry on the target levels

    Is that the only way you have to separate the items to be chained?
    Can you separate the desired items - by type, by color, or...
     

  9. The now un-blanked entities are not appearing visually on-screen?

    ref: interfaces\GUI\CGui_ch.h

    // Try this first after the un-blanking.
    repaint_graphics ();  

    // This 'repaint_graphics' does do it for you, replace it with this ->
    rebuild_graphics();  //  Only use if really needed, as this can take time.

    } while (succf);
    
    if (suc) //  Was anything changed?
      repaint_graphics ();  
    
    return suc ? 1 : 0;

     

  10. Not sure what you mean about "does not work".

    This worked for me (tested in 2018 and 2020) ->

    extern "C" __declspec (dllexport) int m_main (int not_used)
    	{
    	// Must call this prior to accessing any Resources in the C-Hook DLL !
    	ChangeResCl res (GetChookResourceHandle ());
    
    	ent entity;
    	if (AskForGeometry (_T ("Select an Arc..."), A_ID, entity))
    		{
    		sel_bit_turn_on (&entity, BLANK_BIT);
    		write_ent_sel (&entity, entity.eptr);
    		AfxMessageBox (_T ("Entity was Blanked"));
    
    		sel_bit_turn_off (&entity, BLANK_BIT);
    		write_ent_sel (&entity, entity.eptr);
    		AfxMessageBox (_T ("Entity was UnBlanked"));
    		}
    
    	return MC_NOERROR | MC_UNLOADAPP;
    	}

     

     

  11. I think this may be what you are looking for.

    If not, email us:  Your code sample file and company contact info to > SDK [at] mastercam [dot] com

    As you see in the View data for the arc you have the ViewNumber of the selected arc. You can use that View Number data.

    // arc = the user selected arc
    var ctr = ViewManager.ConvertToWorldCoordinates(arc.Data.CenterPoint, arc.ViewNumber);
    // Use this as the center point for the new arc...

    NET-Hook API Docs - https://nethookdocs.mastercam.com
    See in Mastercam.IO.ViewManager:
    Point3D ConvertToViewCoordinates(Point3D WorldCoordinates, short ViewNumber)
    Point3D ConvertToViewCoordinates(Point3D WorldCoordinates, short ViewNumber)
    Point3D ConvertToWorldCoordinates(Point3D ViewCoordinates, MCView View)
    Point3D ConvertToViewCoordinates(Point3D WorldCoordinates, MCView View)
     

  12. I am not sure what you mean be "exotic" views.
    Mastercam has Named Planes (views). Those are displayed in the Planes Manager pane in Mastercam.
    ViewManager.GetAllViews(False) retrieves ALL of these known views.
    The arc you have the user select contains ViewNumber data of the view that arc is in.
    You can work with that value to get all of the Plane (MCView) data for the arc’s view if needed.
     

  13. Something to try.

    Note that it's looking for the Plane (view) with the name of "MyTargetPlane" to use as the to Translate To View.

    Private Function TranslateArc() As Boolean
        Dim entTypeMask = New GeometryMask(False) With {
            .Arcs = True
        }
        
        ' Ask the user to select a single Arc geometry item.
        Dim geom = SelectionManager.AskForGeometry("Select Arc", entTypeMask)
    
        If geom Is Nothing Then
            Return False
        End If
    
        ' Cast the Geometry to it's specific type.
        ' We know it's an Arc, so this direct-cast is safe.
        Dim arc = CType(geom, ArcGeometry)
        
        ' Get ALL MCView (Planes) data in the file.
        Dim allViews = ViewManager.GetAllViews(False)
        
        ' Search for the destination view "by name".
        Dim targetView = New MCView()
        Dim found = False
    
        For Each view In allViews
            If String.Compare(view.ViewName, "MyTargetPlane", StringComparison.OrdinalIgnoreCase) = 0 Then
                targetView = view
                found = True
                Exit For
            End If
        Next
    
        If Not found Then
            Return False
        End If
    
        ' Create a new Arc and the same center point as the selected arc in Top.
        Dim topView = SearchManager.GetSystemView(SystemPlaneType.Top)
        Dim arcSup = New ArcGeometry(topView.ViewNumber, New Point3D(0, 0, 0), 15.0, 0.0, 360.0)
        arcSup.Commit()
        
        ' The center point of the selected arc in world coordinates.
        Dim ptWorldCoordinates = ViewManager.ConvertToWorldCoordinates(arc.Data.CenterPoint, arc.ViewNumber)
        
        ' Translate this new arc to the "MyTargetPlane" view.
        Return arcSup.Translate(New Point3D(0, 0, 0), ptWorldCoordinates, topView, targetView)
    End Function

     

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