CamBam
News:
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 15, 2019, 16:38:44 pm


Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Creating holding tabs using a pointlist possible by script ?  (Read 790 times)
gmoo
Storm Trooper
***
Offline Offline

Posts: 107

Jam it !


View Profile
« on: September 24, 2019, 11:38:54 am »

Couldn´t find any informations (oh, these dark sunglasses ...) about that,
maybe I don´t know the correct terms for searching.

Did anybody ever made this ?
In the MOP I found some point definition, but the usage is not clear to me.

The goal is creating the tabs using a python script, which shall collect all points of a layer
to a list and create the holding tabs automatically based upon the pointlist.
Of course - the points have to be located on or nearby the polylines to be processed.

Is that possible ?

Best regards

Bernhard
Logged

best regards

Bernhard
onekk
Wookie
****
Offline Offline

Posts: 492


View Profile
« Reply #1 on: September 25, 2019, 11:34:30 am »

Seem to be difficult at least in Python, in C# I have the same problem, in Python is slightly more difficult due to the API not being well documented.

I have done the same question Today in another thread directly to Andy.

From my knowledge, the Tab List in stored (when set to Manually) as a Length calculated from a starting point, so maybe using some costruct to set the point for the tab and then using:

Code:
public Point3F GetNearestPoint (Point2F p, ref Vector2F VNormal, ref int NearestSegment, bool expanded_search)

and then find the parametric point (the point calculated on the perimeter from the polyline start point )

Code:
public double GetParametricPoint (Point2F p, ref Vector2F VNormal)

But this is a supposition that I hope Andy (The Creator of CamBam) maybe will solve in the future.

I have guessed this looking at the XML code stored in the CB file.

But I haven't found a way to assign some values to the TabList:

In the code:

Code:
public HoldingTab (EntityIdentifier parentid, double position, Vector2F normal)

The tab is defined as position and vector2F and the GetParametricPoint return a double (I assume that is the position) and a Vector2F as a ref in the call.

But pyhton didn't have the same exposed API.

Plus I'havent found a method to pass a Tablis to the MOP Tabllist

Code:
public List<HoldingTab> Tabs

I'm working on this problem, but in C#.

Regards

Carlo D.
Logged

Carlo D. (onekk)

eShapeoko #343 750x1000 mm + GRBL + bCNC + CamBam
gmoo
Storm Trooper
***
Offline Offline

Posts: 107

Jam it !


View Profile
« Reply #2 on: September 25, 2019, 11:42:39 am »

Hi Carlo,

so I see ... for me it´s a good choice to postpone this idea.

Nevertheless thank you !

best regards

Bernhard
Logged

best regards

Bernhard
onekk
Wookie
****
Offline Offline

Posts: 492


View Profile
« Reply #3 on: September 25, 2019, 13:15:56 pm »

After having tried to use Python, due to the lack of Documentation, I've resolved to use C# and using Linux, the learning curve is not so fast, but after some years, i could say that it is not too hard.

Many things are easy, many are a little difficult, something involve the creation of intermediate objects.

At some point I managed to create this code:

Code:

// Test per personalize Tabs

            List<HoldingTab> H_Tabs = new List<HoldingTab>();
            Polyline PP;

            HoldingTab H_Tab = new CamBam.CAM.HoldingTab();
            int n_tabs = 5;

            foreach (Entity ent in objects) {

                for (int idx = 0; idx < n_tabs; idx++)
                {
                    PP = ent as Polyline;
                    H_Tab = new CamBam.CAM.HoldingTab(ent.ID, 1.0f / idx, new Vector2F(0,-1));
                    H_Tabs.Add(H_Tab);
                }


            }

            mop.Tabs = H_Tabs;


Where:

mop is the Profile MOP (I think it is the only useful operation for a tab)

objects are the entities of the MOP

The parametric point is a value between 0 and 1 indicating the point in the polyline as a fraction of perimeter I suppose, but this can be obtained using:

Code:
public double GetParametricPoint (Point2F p, ref Vector2F VNormal)

I suppose that the Vector2F returned could be used to feed the Vector2F parameter of the Holding Tab.

The main concern is the value of Vector2F, it seem the orientation of the Tab,

I'm working in a Plugin that given an Entity (Polyline) and some lines it extracts the intersection points and then trasform them in Tabs, but it is a rought work in progress.


In python is not so easy and making a Plugin is somewhat a more fast approach, and it is not too difficult to learn how to make a plugin.

Regards

Carlo D.
« Last Edit: September 25, 2019, 18:32:44 pm by onekk » Logged

Carlo D. (onekk)

eShapeoko #343 750x1000 mm + GRBL + bCNC + CamBam
onekk
Wookie
****
Offline Offline

Posts: 492


View Profile
« Reply #4 on: October 01, 2019, 16:00:09 pm »

Some work tell that is possible at least in C#:

In the attached image, is the result in one of my plugin, creating some lines and the apply them to the MOP objects using the intesection and some polyline methods, result in holding tabs aligned anc (almost) correctly placed.

Code:
                CamBam.ThisApplication.AddLogMessage(" lftabs detected ");
                HoldTab.TabMethod = TabMethodOption.Manual; // For "custom" tabs
                List<HoldingTab> H_Tabs = new List<HoldingTab>();

                foreach (int ID in IDs)
                {
                    Entity primitive = myfile.FindPrimitive(ID);

                    // we assume that the entities are polylines
                    if (primitive.GetType() == typeof(Polyline))
                    {
                        foreach (Line2F l_id in lftabs)
                        {

                            // Test for custom Tabs
                            // left here for future work on it
                            // NOTE: Remember to set "HoldTab.TabMethod" above to Manual

                            Point2F[] int_pt = (primitive as Polyline).LineIntersections(l_id, 0.001f);

                            HoldingTab H_Tab = new CamBam.CAM.HoldingTab();

                            foreach (Point2F pt in int_pt)
                            {
                                Vector2F vnorm = new Vector2F();
                                double parampt = (primitive as Polyline).GetParametricPoint(pt, ref vnorm);
                                H_Tab = new CamBam.CAM.HoldingTab(primitive.ID, parampt, vnorm);
                                H_Tabs.Add(H_Tab);
                            }

                        }

                    }

                }

                // Add Tabs to MOP's "Tabs" property
                mop.Tabs = H_Tabs;


providing that:

IDs hold a list of integer holding the primitive.ID of the polylines that holds the profiles

lftabs, holds a list of Line2F to align the Tabs.

The relevant processing code is:

Code:
Vector2F vnorm = new Vector2F();
double parampt = (primitive as Polyline).GetParametricPoint(pt, ref vnorm);
H_Tab = new CamBam.CAM.HoldingTab(primitive.ID, parampt, vnorm);
H_Tabs.Add(H_Tab);


Regards

Carlo D.


* 2019-10-01-16:50:36_scrot.png (24.37 KB, 365x598 - viewed 39 times.)
Logged

Carlo D. (onekk)

eShapeoko #343 750x1000 mm + GRBL + bCNC + CamBam
gmoo
Storm Trooper
***
Offline Offline

Posts: 107

Jam it !


View Profile
« Reply #5 on: October 03, 2019, 09:38:54 am »

Holy cow !

Thanks for your work !
I'll try to integrate this into my Automagic script.

Perhaps I should give the c# a second chance...
Phytoning is a little weird using poor documentation.
Logged

best regards

Bernhard
dh42
Administrator
CNC Jedi
*****
Offline Offline

Posts: 5642



View Profile WWW
« Reply #6 on: October 03, 2019, 21:02:20 pm »

Hello

Quote
Perhaps I should give the c# a second chance...

If you're running the Windows version of CB, you can also use Visual Basic Script ; the syntaxe is close from C# than Python, and if you want to turn the script to a plugin later, you can use the same VB code almost "as is" in the plugin.

VBS is not usable with the Linux version.

++
David
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.127 seconds with 20 queries.

Copyright © 2018 HexRay Ltd. | Sitemap