CamBam
News:
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 21, 2019, 03:02:15 am


Login with username, password and session length


Pages: 1 2 [3] 4 5 ... 8
  Print  
Author Topic: Drag-Knife Script  (Read 60676 times)
Dragonfly
CNC Jedi
*****
Offline Offline

Posts: 2216



View Profile
« Reply #30 on: May 05, 2014, 18:56:31 pm »

Bill,
I tried the new script on geometry I use to test my version of it (it passes all successfully ATM). On the first letter 'F' of the 'Flight Service' text your script enter and endless loop so I had to terminate CB.
BTW, Is there a way to terminate a script running from the keyboard. I tried Ctrl-C, (Ctrl)-Break, Esc with no result.

Here's what I set the parameters to:
Code:
KnifeTipOffset = .25
CutDepth = .05
SwivelAngle = 10
RetractEnable = 0
RetractAngle = 40
RetractDepth = .05
I am working in millimeters. And I need an output for vinyl cutting only so 0.050 mm is still too deep but left this value for the test.
Attached is the .cb file in millimeters.
Note, the letters are quite small and there are other thin elements because I want to see what happens with tiny cuts, large will cut OK even if with some inaccuracy.
P.S. I am attaching also my current work script, but it is not tidied up, nor commented. I have to do this soon.

* VinylTest.cb (58.31 KB - downloaded 218 times.)
* DragPath.txt (5.38 KB - downloaded 281 times.)
« Last Edit: May 05, 2014, 18:59:24 pm by Dragonfly » Logged
billt
Droid
**
Offline Offline

Posts: 90


View Profile
« Reply #31 on: May 06, 2014, 10:43:50 am »

Dragonfly -
I do not understand how your system ended in an endless loop, mine ran with your parameters.
I did find an error in the logic for the first segment with the RetractEnable set to 0.
The point was set to be placed at C1 instead of CFirst so the first swivel path was not placed.
The logic has been fixed and script updated.

I ran your file with your parameters and the result is attached.
The generated cut lines are on Layer 1.
Please try the updated script and let me know if you get the same result.

Cheers - BillT

* drag_knife_6-May-2014.txt (8.87 KB - downloaded 213 times.)
* VinylTest.cb (170.42 KB - downloaded 178 times.)
Logged
bendelange
CNC Ewok
*
Offline Offline

Posts: 10


View Profile
« Reply #32 on: June 03, 2014, 18:16:14 pm »

Can anyone tell me how to use this script in CamBam. I never used scripts in CamBam and can't find how to do this.
Logged
lloydsp
CNC Jedi
*****
Offline Offline

Posts: 8058



View Profile
« Reply #33 on: June 03, 2014, 18:23:33 pm »

Click on "script" in the top toolbar, then 'open'.  Select this script from the list.

It will open up in a text window.

Then, in that window, click "tools", and "compile", or just press F5.

In order for that all to work, the script itself must be copied to the Cambam system/scripts folder.

In XP, this appears at: C:\Documents and Settings\All Users\Application Data\CamBam plus 0.9.8\scripts

Elsewhere on other OS's.

You can find AND open that folder for copying things into it most easily by using (from an open CamBam session) Tools/Browse system folder, then opening the scripts folder.


Lloyd

« Last Edit: June 03, 2014, 18:25:27 pm by lloydsp » Logged

"Pyro for Fun and Profit for More Than Fifty Years"
dh42
Administrator
CNC Jedi
*****
Offline Offline

Posts: 5643



View Profile WWW
« Reply #34 on: June 03, 2014, 19:28:27 pm »

Can anyone tell me how to use this script in CamBam. I never used scripts in CamBam and can't find how to do this.

Hello,

You can find a little video here
http://www.usinages.com/cambam/pilotage-couteau-rotatif-t65995-15.html#p734970

++
David
Logged
bendelange
CNC Ewok
*
Offline Offline

Posts: 10


View Profile
« Reply #35 on: June 03, 2014, 20:57:23 pm »

I found the scripts directory (it was a hidden folder on Windows 7) copied the file and changed the extension to py.
I drew a rectangle in CamBam (CamBam plus [0.9] Rel 8P (beta-2)) selected it and run the script (drag_knife_6-May-2014.txt),
I got an error unexpected newline on line 236. In the editor it seemed that the right parenthesis was missing on the last line. I added a parenthesis and it seemed to run it gave some lines output on the bottom screen but nothing changed in my rectangle.
Then I modified the rectangle as shown in the movie by adding some circles to the rectangle selecting them all and do a union on it. Selected all and ran the script. After this I got a lot of output in the lower screen and it ran forever.
Any suggestions?
Logged
dh42
Administrator
CNC Jedi
*****
Offline Offline

Posts: 5643



View Profile WWW
« Reply #36 on: June 03, 2014, 21:03:09 pm »

Hello,

Yes, same for me, but I'm not familiar with python and I don't search for the error.  Embarrassed

The one on the vidéo is on the first message of this page (reply #30 from dragonfly)

++
David
Logged
billt
Droid
**
Offline Offline

Posts: 90


View Profile
« Reply #37 on: June 11, 2014, 03:25:07 am »

bendelange -
Note, the script is designed to only work with polylines.
If you tested a polyrectangle, convert it to a polyline before running the script.
I have not gotten a newline error on line 236 - seems OK for me.
If you still get the same error, please upload your file so I can test it.
Cheers - BillT
Logged
bendelange
CNC Ewok
*
Offline Offline

Posts: 10


View Profile
« Reply #38 on: June 11, 2014, 13:37:03 pm »

I downloaded "drag_knife_6-May-2014.txt" again and checked it but there is still a parenthesis missing at the last line.
Adding the parenthesis and running the script on a simple polyline that I drew in CamBam results in an endless loop.
Same polyline with the script from October 2013 "drag_knife.txt" runs nicely.
Logged
billt
Droid
**
Offline Offline

Posts: 90


View Profile
« Reply #39 on: June 11, 2014, 17:47:39 pm »

It appears that there were several lines cut from the end of the script when I uploaded it.
This explains the missing parenthesis and the endless loop.
Attached is the file again which has been working for me.
I will check this time to make sure that it has uploaded fully.
Cheers - BillT

* drag_knife_6-May-2014.txt (8.87 KB - downloaded 180 times.)
Logged
billt
Droid
**
Offline Offline

Posts: 90


View Profile
« Reply #40 on: June 11, 2014, 17:54:04 pm »

The file got cut short again at the same spot - I am not sure what is the problem with the upload.
Attached below is the full script, you will need to copy/paste and save as a Drag-Knife.py file.
Cheers - BillT

Code:
# DRAG_KNIFE.PY
# Rev: 4-May-2014
# Bill Trondsen
# billtrondsen@yahoo.com
###########################################################################
# This CAMBAM script creates a polyline for Drag-Knife cutting
# Select all desired polylines and run the script
# Note: Material Surface set to Z=0
# Use an engraving path with depth of cut set to zero
# Drag-Knife Path Concept comes from:  www.DonekTools.com
# Cut path is simulated by the path of a rear bicycle wheel
# Knowing the rear wheel path, calculate the front wheel (tool path)
# Formulas come from: http://math.ucsd.edu/~ebender/87/bicycle.pdf
#
# Release: 23-Sep-2013 Bill Trondsen
# Rev: 4-May-2014 Bill Trondsen
#      - fix Acos precision errors by adding a round() function
#      - add SwivelAngle for precision control
#      - add RetractEnable toggle to prepare for pluginizing
#      - resequence point logic to include RetractEnable and SwivelAngle
# Rev: 6-May-2014 Bill Trondsen
#      - fix error in FirstSegment with RetractEnable=0
#      - Point placed should be CFirst not C1
#
###########################################################################
#  VARIABLES:  Set these values for your tool and material
#
#    KnifeTipOffset: knife tip distance from tool centerline
#        (typically this is 1/2 the tool diameter)
#
#    CutDepth: set to material thickness or slightly larger to assure cutting through the material
#        A positive value for CutDepth will be set as a -Z value.
#        This value would be equivalent to the Engrave Depth.
#
#    SwivelAngle: this angle is used as a precision factor
#        If the angle between segments is SMALLER than SwivelAngle, a Swivel move will NOT be produced.
#        This will make the cut smoother, but less precise to the original path.
#        Default value is 5 degrees.
#
#    RetractEnable: this is a toggle to enable the Retract Feature
#        Value of (1) enables Retract and (0) disables it
#
#    RetractAngle: this angle is used for the Retract feature
#        If the angle between segments is LARGER than RetractAngle, a Retract move will be produced.
#        For thicker material like cardboard, this prevents gouging of material during the swivel move.
#        Default value is 40 degrees
#
#    RetractDepth: a smaller retract depth used during the swivel move
#        A positive value for RetractDepth will be set as a -Z value.
#        As a suggestion, try 1/2 the value of the CutDepth.
#
###########################################################################


KnifeTipOffset = .25
CutDepth = .05
SwivelAngle = 10
RetractEnable = 0
RetractAngle = 40
RetractDepth = 0.05


app.log("KnifeTipOffset "+KnifeTipOffset.ToString())
app.log("CutDepth       "+CutDepth.ToString())
app.log("SwivelAngle    "+SwivelAngle.ToString())
app.log("RetractEnable  "+RetractEnable.ToString())
app.log("RetractAngle   "+RetractAngle.ToString())
app.log("RetractDepth   "+RetractDepth.ToString())


####### MAIN LOOP #########################################

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

for ent in view.Selection:
  if ent.GetType().Name == "Polyline":
    xpoly = XPolyline(ent)
    app.log("**********************************************************")
    app.log("************************Polyline**************************")
    app.log("**********************************************************")
    app.log("Polyline:      "+ent.ID.ToString())
    seg = xpoly.FirstSegment
    poly = Polyline()
    SegNum = 1

  ######## Loop for each segment within the Polyline #########
    while seg is not None:

      P1X = seg.P1.X
      P1Y = seg.P1.Y
      P2X = seg.P2.X
      P2Y = seg.P2.Y
      V1 = seg.VNormal1.Normal().Normal().Normal()
      V2 = seg.VNormal2.Normal().Normal().Normal()
      VFirst = Vector2F(1,0)
      VLast = Vector2F(1,0)

  #### First Point is oriented to X-axis and calculate sweep/bulge to first segment
      if seg == xpoly.FirstSegment:
        CFirst = Point2F(P1X+KnifeTipOffset, P1Y)
        CFirstXP = Vector3F.CrossProduct(Vector3F(1,0,0),Vector3F(V1.X,V1.Y,0))
        CFirstDirection = Math.Sign(CFirstXP.Z)
        if CFirstDirection == 0:
          CFirstDirection = 1
        CFirstSweep = Math.Acos(round(Vector2F.DotProduct(VFirst,V1)/(VFirst.Length*V1.Length),10))
        CFirstB = Math.Tan(CFirstSweep/4)*CFirstDirection

        app.log("CFirst         "+CFirst.ToString())
        app.log("CFirstSweep    "+CFirstSweep.ToString())
        app.log("CFirstXP       "+CFirstXP.ToString())
        app.log("CFirstDirection"+CFirstDirection.ToString())
        app.log("CFirstB        "+CFirstB.ToString())


  #### Set the VN1 vector direction of the next segment

      if seg == xpoly.LastSegment: 
        VN1 = VLast    # vector VLast points toward +X after last segment

      else:
        VN1 = seg.NextSegment.VNormal1.Normal()
        VN1.Invert()


  #### Remaining Segments - Calculate Cut Points (C1,C2) and Cut Segment Bulge (C1B)

      C1 = Point2F(P1X+V1.X*KnifeTipOffset,P1Y+V1.Y*KnifeTipOffset)

      if seg.GetType().Name == "XPolySegLine":     
        C1B = 0
        C2 = Point2F(P2X+V2.X*KnifeTipOffset, P2Y+V2.Y*KnifeTipOffset)

      elif seg.GetType().Name == "XPolySegArc":
        C1B = Math.Tan(seg.Sweep/4)
        C2X = P2X+KnifeTipOffset/((1+(V2.Y/V2.X)**2)**.5)*Math.Sign(V2.X)
        C2Y = P2Y+(KnifeTipOffset*V2.Y/V2.X)/((1+(V2.Y/V2.X)**2)**.5)*Math.Sign(V2.X)
        C2 = Point2F(C2X,C2Y)


  #### Calculate Bulge (C2B) for the Sweep Path between segments

      VC2 = Vector2F(seg.P2,C2)  # vector from P2 to C2 used for calculating sweep path bulge
      C2XP = Vector3F.CrossProduct(Vector3F(VC2.X,VC2.Y,0),Vector3F(VN1.X,VN1.Y,0))
      C2Direction = Math.Sign(C2XP.Z)
      if C2Direction == 0:
        C2Direction = 1
      C2Sweep = Math.Acos(round(Vector2F.DotProduct(VC2,VN1)/(VC2.Length*VN1.Length),10))
      C2B = Math.Tan((C2Sweep)/4)*C2Direction
      C2Angle = C2Sweep*180/Math.PI


  #### Calculate CLast to orient the tool in the +X direction to prepare for additional segments

      CLast = Point2F(seg.P2.X+VLast.X*KnifeTipOffset, seg.P2.Y+VLast.Y*KnifeTipOffset)


  ######  End of Calculation Section

      app.log("******************Segment*******************")
      app.log("Segment        "+SegNum.ToString())
      app.log("P1             "+seg.P1.ToString())
      app.log("P2             "+seg.P2.ToString())
      app.log("V1             "+V1.ToString())
      app.log("V2             "+V2.ToString())
      app.log("V2X SIGN       "+Math.Sign(V2.X).ToString())
      app.log("V2Y SIGN       "+Math.Sign(V2.Y).ToString())
      app.log("C1             "+C1.ToString())
      app.log("C2             "+C2.ToString())
      app.log("C1B            "+C1B.ToString())
  app.log("VN1            "+VN1.ToString())
  app.log("VN1.Length     "+VN1.Length.ToString())
  app.log("VC2            "+VC2.ToString())
  app.log("VC2.Length     "+VC2.Length.ToString())
      app.log("C2Sweep        "+C2Sweep.ToString())
      app.log("C2B            "+C2B.ToString())


########################################################
# Add points to path with depth logic###################
########################################################


#If First Segment
#  If RetractEnable = 1
#    Place CFirst, RetractDepth, CFirstB
#    Place C1, RetractDepth, 0
#  ElseIf RetractEnable = 0
#    Place CFirst, CutDepth, CFirstB
#
#
#Place C1, CutDepth, C1B
#
#
#If C2Angle >= SwivelAngle then do a swivel move
#  If RetractEnable = 1
#    Place C2, CutDepth, 0
#    Place C2, RetractDepth, C2B
#  If RetractEnable = 0
#    Place C2, CutDepth, C2B
#
#ElseIf C2Angle < SwivelAngle then do not do a swivel move
#  Place P2+Offset*VN1, CutDepth, 0
#
#
#If Last Segment
#  If RetractEnable = 1
#    Place CLast, RetractDepth, 0
#  If RetractEnable = 0
#    Place CLast, CutDepth, 0


      if seg == xpoly.FirstSegment:
        if RetractEnable == 1:
          poly.Add(CFirst.X, CFirst.Y, RetractDepth, CFirstB)
          poly.Add(C1.X, C1.Y, RetractDepth, 0)
        elif RetractEnable == 0:
          poly.Add(CFirst.X, CFirst.Y, CutDepth, CFirstB)

      poly.Add(C1.X, C1.Y, CutDepth, C1B)

      if C2Angle >= SwivelAngle:  # then do a swivel move
        if RetractEnable == 1:
          poly.Add(C2.X, C2.Y, CutDepth, 0)
          poly.Add(C2.X, C2.Y, RetractDepth, C2B)
        elif RetractEnable == 0:
          poly.Add(C2.X, C2.Y, CutDepth, C2B)

      elif C2Angle < SwivelAngle:  # then do not do a swivel move
        poly.Add(P2X+KnifeTipOffset*VN1.X, P2Y+KnifeTipOffset*VN1.Y, CutDepth, 0)

      if seg == xpoly.LastSegment:
        if RetractEnable == 1:
          poly.Add(CLast.X, CLast.Y, RetractDepth, 0)
        elif RetractEnable == 0:
          poly.Add(CLast.X, CLast.Y, CutDepth, 0)

      app.log("SwivelAngle    "+SwivelAngle.ToString())
      app.log("C2Angle        "+C2Angle.ToString())

#### End of Main Loop #####################################
      SegNum += 1
      seg = seg.NextSegment
    doc.Add(poly)
Logged
BR52
Wookie
****
Offline Offline

Posts: 329



View Profile
« Reply #41 on: June 11, 2014, 17:56:06 pm »

Hello bendelange,

You need to put examples having problems.
The BillT said:
               please upload your file so I can test it.  Roll Eyes

   Armando


* 508.jpg (5.28 KB, 256x192 - viewed 406 times.)
Logged
bendelange
CNC Ewok
*
Offline Offline

Posts: 10


View Profile
« Reply #42 on: June 11, 2014, 18:31:24 pm »

Copy/pasted last file and that works!
Logged
billt
Droid
**
Offline Offline

Posts: 90


View Profile
« Reply #43 on: June 11, 2014, 19:28:50 pm »

Great!  If you have any problems or suggestions for additional features let me know.
Cheers - BillT
Logged
Dragonfly
CNC Jedi
*****
Offline Offline

Posts: 2216



View Profile
« Reply #44 on: July 12, 2014, 12:51:42 pm »

Hi Bill,
I had to move with all my junk to a new place and didn't have time to play with foil cutting and your last script.
Now that all the lines of code are present it ran on a ragged example curve where my version fails  Sad
I have a question though. As you can see on the attached picture the script inserts moves which at least for my needs are not required. How can I and is it possible to avoid them by defining the initial control values?
Here are the values I use:
Offset = .25
CutDepth = 0
RetractDepth = 0
SwivelAngle = 90
I do not want the polyline points to go below zero level but rather set the DOC in the MOP, so CutDepth is set to 0. In fact I want a flat polyline with no points above zero too.
I am attaching also a DXF file with the test shape.

Cheers,
Ivan


* notch.jpg (182.66 KB, 716x362 - viewed 344 times.)
* boardTestA.dxf (22.97 KB - downloaded 169 times.)
Logged
Pages: 1 2 [3] 4 5 ... 8
  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.156 seconds with 19 queries.

Copyright © 2018 HexRay Ltd. | Sitemap