CamBam
News:
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 17, 2018, 04:43:02 am


Login with username, password and session length


Pages: 1 [2]
  Print  
Author Topic: Vb to Python  (Read 1880 times)
dave benson
CNC Jedi
*****
Offline Offline

Posts: 1018


View Profile
« Reply #15 on: August 08, 2018, 23:03:40 pm »

Thank's Eddy
I wouldn't have guessed that you could form the function that way.
Dave
Logged
EddyCurrent
CNC Jedi
*****
Offline Offline

Posts: 3700



View Profile
« Reply #16 on: August 08, 2018, 23:09:49 pm »

Neither would I until today   Cheesy
I hate Python  Grin
Logged
dave benson
CNC Jedi
*****
Offline Offline

Posts: 1018


View Profile
« Reply #17 on: August 09, 2018, 02:19:10 am »

Hi Eddy

Bloody Hell,  Curiosity got the better of me, once again Roll Eyes (just can't help myself)  and felt compelled to find out “BUT WHY”  even though I couldn't see it benefiting me at all .

Turns out I had a myopic view of the serialisation process in general, and after a couple of hours at the Python site and after reading this  https://docs.python.org/3/library/pickle.html#module-pickle  “The light turned on” and I now have a clearer view of the “Bigger Picture” of the concept itself, and may be able to apply it  more effectively  in my own C#  programming efforts.

Sometimes, you just don't where your curiosity can take you.

Dave
Logged
EddyCurrent
CNC Jedi
*****
Offline Offline

Posts: 3700



View Profile
« Reply #18 on: August 09, 2018, 09:48:41 am »

Thanks Dave, I'll have a look at that.

So I thought, why stop there ?

This is the script Dragonfly is after.
Select one Polyline then all other Polylines at the same Z depth will also be selected.
It only works correctly if each polyline is 'flat', i.e. all point in each polyline have the same Z value

Attached is a very simple test cb file


Code:
# ** Select Polylines at same Z level **

# ArrayList to hold selected Polylines
entList = Collections.ArrayList()

# return Z level of Polyline
def getZlevel(polyLine):
    
    minextrema = Point3F()
    maxextrema = Point3F()
    (minextrema, maxextrema) = polyLine.GetExtrema(minextrema,maxextrema)
 
    return maxextrema.Z

# get Polyline entities at same Z  level as Selected entity    
def getMorePolylines(zlevel):    

    for layer in doc.Layers:
        for ent in layer.Entities:
            if(ent.GetType() == Polyline):
                poly1 = Polyline(ent)
          
                polyZlevel = getZlevel(poly1)
        
                if(polyZlevel == zlevel):          
                    entList.Add(ent)



if (view.SelectedEntities.Length == 1):
   for ent in view.SelectedEntities:
     if (ent.GetType() == Polyline):
        poly = Polyline(ent)
        
        SelectedZlevel = getZlevel(poly)
        getMorePolylines(SelectedZlevel)
        app.log("Z level of Polyline " + poly.ID.ToString() + " = " + SelectedZlevel.ToString())
        view.Select(entList)    

else:        
        app.log("Error: Please select a single poly.")


* Zlevels.cb (2.97 KB - downloaded 19 times.)
« Last Edit: August 09, 2018, 14:10:02 pm by EddyCurrent » Logged
dave benson
CNC Jedi
*****
Offline Offline

Posts: 1018


View Profile
« Reply #19 on: August 09, 2018, 12:18:36 pm »

Yep, that does the job.
Here is a script from Billt with some more python functions that I know to work.

Code:
Here is a quick Python script to generate the internal and external fillets for engraving using a cylindrical cutter.
It simply uses a sequence of four offsets from the original path.
Then, use a profile or pocket MOP for the male and female components.
Note, you will probably want to use a small roughing clearance on both to make sure that the parts will fit.
If this is useful to you guys, I can add a simple gui front-end to enter the Tool Diameter.
Or even better, maybe someone can volunteer to make a Plugin?  Eddie?  Dave Benson?
Cheers - BillT


Code:

# inlay_fillet_shapelist.py
ToolDiameter = 2

CamBamUI.MainUI.UndoBuffer.AddUndoPoint("Undo Here")
CamBamUI.MainUI.UndoBuffer.Add(doc.ActiveLayer.Entities)

###Store selected entities in ShapeList, copy, to polylines, to shapelist
ScreenSelections = ShapeList()
ScreenSelections.AddSelectedEntities(view)
InlayFillet = ScreenSelections.Clone()
InlayFillet = InlayFillet.ToPolylines()
InlayFillet = ShapeList(InlayFillet, True)

### Fillet inside and outside by doing four offset operations
### Each offset uses the value for tool radius (R)
### First offset -R, Second +R
### Third +R and Fourth -R
### Note the Second and Third are same direction and can be combined
InlayFillet = InlayFillet.Offset(-ToolDiameter/2)
InlayFillet = InlayFillet.Offset(ToolDiameter)
InlayFillet = InlayFillet.Offset(-ToolDiameter/2)

doc.Add(InlayFillet.ToEntities())

If I find any more python snippets I'll Post them.

Dave
Logged
Dragonfly
CNC Jedi
*****
Offline Offline

Posts: 2046



View Profile
« Reply #20 on: August 09, 2018, 17:25:26 pm »

Thanks for your input, Dave and Eddy!
I actually did the script in VB and it works. But I'll dig into Python too, just out of curiosity but some time later.
Undertook a long planned renovation in our flat and these days I am away from CNC machining and script writing  Grin
Logged

Before asking a question do some effort and walk through all menus and options in CamBam.  Maybe the answer is there. Please.
EddyCurrent
CNC Jedi
*****
Offline Offline

Posts: 3700



View Profile
« Reply #21 on: August 11, 2018, 14:59:51 pm »

So does CamBam for Linux support VB script now ?
Logged
EddyCurrent
CNC Jedi
*****
Offline Offline

Posts: 3700



View Profile
« Reply #22 on: August 11, 2018, 15:04:49 pm »

Hello

Because the silhouete return always 'flat' polylines, you can use the Polyline.FirstPoint() to get the Z pos of the first point of the line.
++
David

God thinking David

and sorry Dave, I see your code was not so bad if only I'd read David's post correctly first  Roll Eyes but then I would not have persevered to find the 'marshalling' method for calling the getextrema method.
« Last Edit: August 11, 2018, 15:09:35 pm by EddyCurrent » Logged
Dragonfly
CNC Jedi
*****
Offline Offline

Posts: 2046



View Profile
« Reply #23 on: August 11, 2018, 18:22:01 pm »

So does CamBam for Linux support VB script now ?
Haven't  tried but I think it won't work. I have CB on a Windows machine because although I am using the Linux version for simpler jobs I use the much more reliable Windows version as the main one.
Logged

Before asking a question do some effort and walk through all menus and options in CamBam.  Maybe the answer is there. Please.
dh42
Administrator
CNC Jedi
*****
Offline Offline

Posts: 5240



View Profile WWW
« Reply #24 on: August 11, 2018, 20:52:26 pm »

Hello
So does CamBam for Linux support VB script now ?

No, only Python

++
David
Logged
dave benson
CNC Jedi
*****
Offline Offline

Posts: 1018


View Profile
« Reply #25 on: August 12, 2018, 05:35:31 am »

Hi Eddy

I think you found the most elegant solution, when I went to the Python site and looked at the extreama function, I had the “working with array's  Addressing mentality”  and this let me down.

I think the main problem using Python with CB, is unlike VB scripting  where David has done a mountain of work with the code snippets section (where there are many examples for would be coders to get started)  there are only a few examples for Python.

Dave
Logged
onekk
Wookie
****
Offline Offline

Posts: 403


View Profile
« Reply #26 on: August 12, 2018, 15:01:38 pm »

 But i think that the writing

Code:
poly.GetExtrema(polyMin,polyMax)

is somewhat strange as I'm asking for a return vale and the

Code:
..a(polyMin,polyMax)

is simply ignored by the interpreter and assumed as

Code:
...a()

and the return value is a "list" (polyMin,polyMax) that is assigned on the fly with the writing


Code:
(polyMin,polyMax) = poly.GetExtrema(polyMin,polyMax)

is only a writing artifice to make the assignement more compact when writing them.

But the Python API is not well documented and is difficult to inspect the API exposed by CamBam.

I hope in a better python API documentation in future.

Regards

Carlo D.

Logged

Carlo D. (onekk)

eShapeoko #343 750x1000 mm + GRBL + bCNC + CamBam
dh42
Administrator
CNC Jedi
*****
Offline Offline

Posts: 5240



View Profile WWW
« Reply #27 on: August 12, 2018, 19:15:34 pm »

Hello

Quote
(polyMin,polyMax) = poly.GetExtrema(polyMin,polyMax)

This statement can also be written without the parenthesis ; found in the gbr2cb.py script from jk (line 40)

Code:
            p0, p1 = e.GetExtrema(p0, p1, False)

http://www.cambam.co.uk/forum/index.php?topic=5193.0

++
David
Logged
onekk
Wookie
****
Offline Offline

Posts: 403


View Profile
« Reply #28 on: August 13, 2018, 16:40:29 pm »

Yes python is very flexible and coould make some "transformation" on the fly but with CamBam we are talking about IronPython.dll (the "internal" interpreter of CamBam).

David, any hope in a more documented  Python API for v1.0?

Regards

Carlo D. 
Logged

Carlo D. (onekk)

eShapeoko #343 750x1000 mm + GRBL + bCNC + CamBam
dh42
Administrator
CNC Jedi
*****
Offline Offline

Posts: 5240



View Profile WWW
« Reply #29 on: August 13, 2018, 17:19:13 pm »

Hello

Quote
David, any hope in a more documented  Python API for v1.0?

I don't know, I've no info about this .. sorry

++
David
Logged
Pages: 1 [2]
  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.15 seconds with 20 queries.

Copyright © 2018 HexRay Ltd. | Sitemap