Author Topic: MopInfo script  (Read 10821 times)

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7422
    • View Profile
    • Cambam V1.0 French Doc
MopInfo script
« on: October 16, 2017, 02:47:02 am »
Hello

I'm starting to play with a VB script that summarize mop info, like tools, toolpaths length, machining duration etc.

It's is not perfect because a lot of things are not taken in account in cambam functions (look at the comments in the code), but it give at least the same result as what we get when generating the toolpath with diagnostic level = 2

this is a first test, and of course it needs some enhancements and to be turned into a plugin, but it is workable as is.

currently the script act on all mops, even hidden mop/parts.

Code: [Select]
' dh42 10/2017
' an attempt to get toolpath lenght, machining time and more
'
' WARNING ; calculation is an approximation !
' Drill mop only return rapids value (even with spiral mill option)
' Trochopocket and trochoprofile plugin never return value
' Thread plugin never return value
' rapids lenght (and of course duration) take only the horizontal moves in account, so move to clearance plane duration is ignored
' toolpath lenght between 2 adajacent toolpaths is not taken in account if done in normal feedrate move.(but taken in account if rapid move)
' no way currently to distinguish leadin move and normal move, so leadin move are calculaded with the normal feedrate
' vertical moves (plunge) between levels are not taken in account
' The axes acceleration is not taken in account.
' rapids between 2 mop are not taken in account
' except for Drill and Trocho mops, the values returned are the same as those obtained with diagnostic level = 2

'TODO
' exclude hiden Parts/mops
' specific treatment for Drill mop
' specific treatment for trocho mop
' specific treatment for Thread mop
' rapids between mops
' compute true rapide value (horizontal + vertical)
' display current units
' use machine definition in system tab to get rapids value for XY and Z
' display the results in an editor or a spreedsheet like display + save option


Sub main()

    Dim prt As CAMPart
    Dim mop As MachineOp
    Dim toolpathseq As ToolPathSequence
    Dim tps As System.Collections.Generic.list(Of Toolpathitem)
    Dim p As polyline
    Dim rapidvalue As Double = 600 ' rapid value(mm/min)
    
    Dim mach_time As Double = 0
    Dim rapid_time As Double = 0
    
    Dim total_machtime As Double = 0
    Dim total_rapidtime As Double = 0

    'scan all the mops in all the parts
    For Each prt In CamBamUI.MainUI.ActiveView.CADFile.Parts
        App.Log(prt.Name)

        For Each mop In prt.MachineOps
            App.Log("  Mop Type: " & mop.MOPTypeName & " - Name: " & mop.Name)

            toolpathseq = mop.Toolpaths2   'get the toolpath sequence

            app.log("    Tool Diam: " & mop.ToolDiameter.Value)
            app.log("    Tool number: " & mop.ToolNumber.Value)
            app.log("    Tool profile: " & mop.ToolProfile.Value)
            app.log("    Feedrate: " & mop.CutFeedrate.Value)

            If mop.HasToolpathSequence Then 'toolpath are existing
                app.log("    Toolpath Distance: " & format(toolpathseq.GetToolpathDistance, "0.000"))
                mach_time = val(toolpathseq.GetToolpathDistance / mop.CutFeedrate.Value * 60)
                app.log("    Rapid Distance: " & format(toolpathseq.GetRapidDistance, "0.000"))
                rapid_time = val(toolpathseq.GetRapidDistance / rapidvalue * 60)

                app.log("    machining duration: " & SecToHMS(mach_time))
                app.log("    rapids duration: " & SecToHMS(rapid_time))
            Else

                If mop.MOPTypeName = "Drill" Then
                    'only rapids are know with drill mops and HasToolpathSequence() is always false
                    ' so I need something to handle error if no rapid is calculated

                    Try
                        app.log("    Rapid Distance: " & format(toolpathseq.GetRapidDistance, "0.000"))
                        rapid_time = val(toolpathseq.GetRapidDistance / rapidvalue * 60)
                        app.log("    rapids duration: " & SecToHMS(rapid_time))
                    Catch ex As exception
                        app.log("    No Toolpaths, please run toolpath calculation")
                    End Try

                Else
                    app.log("    No Toolpaths, please run toolpath calculation")
                End If
            End If
            app.log("")

            total_machtime = total_machtime + mach_time
            total_rapidtime = total_rapidtime + rapid_time
        Next mop
    Next

    app.log("Total machining duration: " & SecToHMS(total_machtime))
    app.log("Total rapids duration: " & SecToHMS(total_rapidtime))
    app.log("")
    app.log("Overall duration (machining + rapids): " & SecToHMS(total_machtime + total_rapidtime))

End Sub

Function SecToHMS(ByVal s As Double) As String

    'return time as HH:MM:SS

    Dim Sec64 As Int64 = CType(s, Int64)
    Dim spanTM As New TimeSpan(TimeSpan.TicksPerSecond * Sec64)
    Dim TimeStr As String

    TimeStr = spanTM.Hours.ToString("00") & "h " & spanTM.Minutes.ToString("00") & "m " & spanTM.Seconds.ToString("00") & "s"

    Return TimeStr

End Function


You can copy the results in the log window with this old plugin.
http://www.atelier-des-fougeres.fr/Cambam/Aide/Plugins/MessageLogCopy.html

++
David
« Last Edit: July 28, 2019, 19:20:24 pm by dh42 »

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5269
  • Made in England
    • View Profile
Re: MopInfo script
« Reply #1 on: October 16, 2017, 14:26:20 pm »
David,

I was working on a similar thing a while ago but it used the cb file to get the information.
Filmed in Supermarionation

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7422
    • View Profile
    • Cambam V1.0 French Doc
Re: MopInfo script
« Reply #2 on: October 16, 2017, 14:41:48 pm »
Hello

Yes cb file can give info about tools, mop name, part name, etc ... but it do not give a way to calculate machining duration / toolpath length.

IMHO, the more accurate way is to work with the GCode itself, because it is possible to know the length and the feedrate of all toolpaths, even those that are not in the MOP and that are added by the PP .. but it's a hard works and it may not works on all Gcode syntax, depending of the PP used.

++
David

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8988
    • View Profile
Re: MopInfo script
« Reply #3 on: October 16, 2017, 16:25:29 pm »
David,
To that end, what if your routine automatically generated the g-code (just for reading it!) from a 'standard' PP that does have the suitable syntaxes?

Then you could read directly from the g-code, and just delete the .nc file afterwards (if it was not of the same PP as the user had selected for the job).

Lloyd
"Pyro for Fun and Profit for More Than Fifty Years"

Offline Bob La Londe

  • CNC Jedi
  • *****
  • Posts: 4492
  • ^ 8.5 pounds on my own hand poured bait.
    • View Profile
    • CNC Molds N Stuff
Re: MopInfo script
« Reply #4 on: October 16, 2017, 17:29:49 pm »
You would almost need to have machine profiles defined within CamBam like you can in some other software.  Then you could simply tell your plugin which machine is being used to do the job, and you could get much more accurate information. 

In defense of this idea machine profiles would be a good idea anyway.  This would allow you to create a tool library and a style library for each machine profile making overall code generation even faster and more efficient than is possible with just styles and tools when you are using multiple different machines with different specs. 

You could enter HP, rapid, max feed, acceleration, tool change time, and a specific tool library and style library for each machine.  Well, and to fix the precision error causing bad 3D toolpaths in 1.0.13.



Of course pairing this with a real material library with real SF calculations would be awesome as well. 

However, I stand by what I said in the past.  I want better 3D, better HSM strategies, and REST/3dREST before most other improvements. 





Getting started on CNC?  In or passing through my area?
If I have the time I'll be glad to show you a little in my shop. 

Some Stuff I Make with CamBam
http://www.CNCMOLDS.com

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8988
    • View Profile
Re: MopInfo script
« Reply #5 on: October 16, 2017, 17:51:23 pm »
Heck!  For this function, the 'standard' PP could be built into the script, so one wouldn't need any 'externals' except the script itself.

Lloyd
"Pyro for Fun and Profit for More Than Fifty Years"

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5269
  • Made in England
    • View Profile
Re: MopInfo script
« Reply #6 on: October 16, 2017, 18:42:13 pm »
David,

It sounds like the duration is important to you however when running the machine I often increase the rates in Mach3 so times are changed outside of CamBam.
Filmed in Supermarionation

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7422
    • View Profile
    • Cambam V1.0 French Doc
Re: MopInfo script
« Reply #7 on: October 16, 2017, 18:59:30 pm »
Hello

Quote
David,
To that end, what if your routine automatically generated the g-code (just for reading it!) from a 'standard' PP that does have the suitable syntaxes?

Then you could read directly from the g-code, and just delete the .nc file afterwards (if it was not of the same PP as the user had selected for the job).

Lloyd

yes, it's one of the ways I think about if I can't do more with mops.

Quote
You would almost need to have machine profiles defined within CamBam like you can in some other software.

Yes, they already exists in Cambam from a while (but they are not used by the soft) and it's planed to use them in future version of the script/plugin. (picture)

Quote
It sounds like the duration is important to you however when running the machine I often increase the rates in Mach3 so times are changed outside of CamBam.

Yes, it's the major reason why I do this script, so I can optimize the mop that "slow" the things and get statistics about what cost time or not in a machined part.

++
David

Offline Dragonfly

  • CNC Jedi
  • *****
  • Posts: 2656
    • View Profile
Re: MopInfo script
« Reply #8 on: August 14, 2024, 16:20:40 pm »
Ha! I came to this old thread because I now have similar task to solve. Tried the script, even added exclusion of disabled MOPs. But problems are just as described by David. Especially when there a a number of holes to drill and then do a thread milling MOP.

Best way IMHO is to generate .nc files (even a single one for all parts) and then run simulation in Mach3. Fast as a snail approach though   ;D