Author Topic: automate multiple profiles by layer  (Read 4926 times)

Offline paragon

  • Ewok
  • *
  • Posts: 15
    • View Profile
automate multiple profiles by layer
« on: April 16, 2017, 17:41:53 pm »
Hi ....I tried the sample script where a mop is automatically made and saved...I hav no experience in this but am interested to learn...can multiple profiles be made to match various layer names?

Thanks

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6141
    • View Profile
    • Cambam V1.0 French Doc
Re: automate multiple profiles by layer
« Reply #1 on: April 16, 2017, 17:54:09 pm »
Hello

Quote
can multiple profiles be made to match various layer names?

I don't understand, what you means by 'profiles' .. drawing objects ?

maybe this snippet can help about layer management, moving drawing entities from layer to another.
http://www.cambam.co.uk/forum/index.php?topic=3878.msg30260#msg30260

there is a summary here
http://www.cambam.co.uk/forum/index.php?topic=3878.msg25796#msg25796

++
David

Offline paragon

  • Ewok
  • *
  • Posts: 15
    • View Profile
Re: automate multiple profiles by layer
« Reply #2 on: April 16, 2017, 20:59:19 pm »
Sorry for lack of clarity..In the attached file I would like to do both Profile operations with one script..so I guess the question is how to do more than the one that is in the script "mop-automate.py"?

Thanks for your reply..

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6141
    • View Profile
    • Cambam V1.0 French Doc
Re: automate multiple profiles by layer
« Reply #3 on: April 16, 2017, 21:20:11 pm »
Ok, I think I understand, but I don't "speak" python.

on the VB example for the same job you have a line:

dim profile = new CamBam.CAM.MOPProfile(newdoc,newdoc.Layers("LAYER_03").Entities.ToArray())

it creates a new profile mop that will use all the drawing objects in "layer_03" (the name of the layer)

in Python the following line do almost the same, except that it's the layer position in the layer list that is used instead it's name.

profile=MOPProfile(newdoc,newdoc.Layers[0].Entities.ToArray())

so to do one profile mop per layer, you can scan for all layer in the layer list and create a new profile mop with all objects contained in each layer.

I think that to do that, you can create a function that takes a layer name as arguments, called in a loop that scan the layer list, and that return a profile mop.

++
David

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6141
    • View Profile
    • Cambam V1.0 French Doc
Re: automate multiple profiles by layer
« Reply #4 on: April 16, 2017, 21:45:42 pm »
A just cocked code in VB script that scan all layers, then create a profile mop with all object on each layer.

Code: [Select]
Sub main()
    For Each l As Layer In CamBamUI.MainUI.ActiveView.CADFile.Layers
        Try
            CamBamUI.MainUI.InsertMOP(MakeProfileMOPfromLayer(l.Name))
        Catch ex As Exception
            ThisApplication.AddLogMessage("the MOP " & l.Name & "can't by created")
        End Try
    Next
End Sub

Function MakeProfileMOPfromLayer(layername As String) As MOPProfile
    Dim profile = New CamBam.CAM.MOPProfile(CamBamUI.MainUI.ActiveView.CADFile, CamBamUI.MainUI.ActiveView.CADFile.Layers(layername).Entities.ToArray())
    profile.Name = layername

    'set other properties for the mop
    '

    Return profile
End Function

Be careful, this code do not test for existing mop with the same name.

++
David

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6141
    • View Profile
    • Cambam V1.0 French Doc
Re: automate multiple profiles by layer
« Reply #5 on: April 16, 2017, 22:43:56 pm »
and with this change in the function, you can manage duplicate name for MOP

Code: [Select]
' New CamBam VBScript

Sub main()
    For Each l As Layer In CamBamUI.MainUI.ActiveView.CADFile.Layers
        Try
            CamBamUI.MainUI.InsertMOP(MakeProfileMOPfromLayer(l.Name))
        Catch ex As Exception
            ThisApplication.AddLogMessage("the MOP " & l.Name & "can't by created")
        End Try
    Next
End Sub

Function MakeProfileMOPfromLayer(layername As String) As MOPProfile
    Dim profile = New CamBam.CAM.MOPProfile(CamBamUI.MainUI.ActiveView.CADFile, CamBamUI.MainUI.ActiveView.CADFile.Layers(layername).Entities.ToArray())
    
    dim ct as integer = 1   'test for existing name
    do while CamBamUI.MainUI.ActiveView.CADFile.ActivePart.MachineOps.NameExists(layername)      
        layername = layername & "_" & trim(str(ct))
        ct = ct + 1
    loop
      
    profile.Name = layername  
    
    'set other properties for the mop
    '
    
    Return profile
End Function
« Last Edit: April 16, 2017, 22:48:44 pm by dh42 »

Offline paragon

  • Ewok
  • *
  • Posts: 15
    • View Profile
Re: automate multiple profiles by layer
« Reply #6 on: April 16, 2017, 23:18:06 pm »
Wow..thanks so much very generous of you...I will test out some more tomorrow...when I try in v1.0..says vbscript not supported on this platform ..in 9.8 fine

Thanks again

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6141
    • View Profile
    • Cambam V1.0 French Doc
Re: automate multiple profiles by layer
« Reply #7 on: April 17, 2017, 00:44:34 am »
Yes, the V1.0 that you can download on the forum is not yet able to handle VBS, but it will come back in the next version.

++
David

Offline paragon

  • Ewok
  • *
  • Posts: 15
    • View Profile
Re: automate multiple profiles by layer
« Reply #8 on: April 17, 2017, 11:28:48 am »
Is it possible to set the various profile properties (Tool dia etc)for each profile in the same script...layer names will be consistent..

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6141
    • View Profile
    • Cambam V1.0 French Doc
Re: automate multiple profiles by layer
« Reply #9 on: April 17, 2017, 15:52:22 pm »
Hello

You can add more args to the function, so you can pass other values like tool diam, depth incr etc .. when you call it.

In the main loop you need a way to know what layer need what setting, maybe by checking the layer name.

ex:

dim tooldia as double
select l.name

  case "layer1"
    tooldia = 2

  case "layer2"
    tooldia = 4

  case else
    tooldia = 6

End select

CamBamUI.MainUI.InsertMOP(MakeProfileMOPfromLayer(l.Name, tooldia))

Function MakeProfileMOPfromLayer(layername As String, d as double) As MOPProfile
  ...
  ...

  dim td = profile.ToolDiameter
  td.SetValue(d)
  profile.ToolDiameter = td

End Function


++
David

Offline paragon

  • Ewok
  • *
  • Posts: 15
    • View Profile
Re: automate multiple profiles by layer
« Reply #10 on: April 17, 2017, 19:47:44 pm »
Hi David,

thanks so much for your help...i don't want to wear you out but i'm having a problem merging the two snippets you sent..as I said i am just beginning to learn this...if you have time could you put them together?

I feel so stupid but I have learned before that there is no other way to learn..

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6141
    • View Profile
    • Cambam V1.0 French Doc
Re: automate multiple profiles by layer
« Reply #11 on: April 17, 2017, 20:22:51 pm »
Hello

First I must eat, then I'll do a more finished example ;)

++
David

Offline paragon

  • Ewok
  • *
  • Posts: 15
    • View Profile
Re: automate multiple profiles by layer
« Reply #12 on: April 17, 2017, 20:31:02 pm »
aha...I will try the same preparation next time I work on this.....THANKS

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6141
    • View Profile
    • Cambam V1.0 French Doc
Re: automate multiple profiles by layer
« Reply #13 on: April 17, 2017, 20:48:50 pm »
Hello,

Try this with the CB file example in attachment.

it define tool dia and in out cutting depending of the layer name.
if a layer name don't match, it use the settings in the 'else' statement.


Code: [Select]
' New CamBam VBScript

Sub main()

    dim tooldia as double, inout as long
   
    For Each l As Layer In CamBamUI.MainUI.ActiveView.CADFile.Layers
        Try       
       
            select l.name

              case "L1"
                tooldia = 2
                inout = 1   'in
               
              case "L2"
                tooldia = 4
                inout = 0   'out
               
              case "L3"
                tooldia = 6
                inout = 1
               
              case else 'if no other name match
                tooldia = 2
                inout = 1
               
            End select
           
            CamBamUI.MainUI.InsertMOP(MakeProfileMOPfromLayer(l.Name, tooldia, inout))
           
        Catch ex As Exception
            ThisApplication.AddLogMessage("the MOP " & l.Name & "can't by created")

        End Try
    Next
End Sub

Function MakeProfileMOPfromLayer(layername As String, d as double, in_out as integer) As MOPProfile
   
Dim profile = New CamBam.CAM.MOPProfile(CamBamUI.MainUI.ActiveView.CADFile, CamBamUI.MainUI.ActiveView.CADFile.Layers(layername).Entities.ToArray())
   
    dim ct as integer = 1   'test for existing name
    do while CamBamUI.MainUI.ActiveView.CADFile.ActivePart.MachineOps.NameExists(layername)
        layername = layername & "_" & trim(str(ct))
        ct = ct + 1
    loop
     
    profile.Name = layername 
   
    'tool diam
    dim td = profile.ToolDiameter
    td.SetValue(d)
    profile.ToolDiameter = td
   
    'in-out
    dim io = profile.InsideOutside
    io.SetValue(in_out)
    profile.InsideOutside = io
   
   
    Return profile
   
End Function

++
David

Offline paragon

  • Ewok
  • *
  • Posts: 15
    • View Profile
Re: automate multiple profiles by layer
« Reply #14 on: April 17, 2017, 21:40:41 pm »
Hi Davis,
I own a cabinet shop and this is the application for cambam....i spend a good bit of my time teaching guys how to work...it is probably good for me and them to have the shoe on the other foot...to remember what it is like to struggle...thanks again for your patience...