Author Topic: c# - Plugin Questions  (Read 91790 times)

Offline ThisAmplifierIsLoud

  • Storm Trooper
  • ***
  • Posts: 231
  • Jam it !
    • View Profile
Re: c# - Plugin Questions
« Reply #60 on: February 04, 2022, 19:22:20 pm »
I tried an exact copy of your code with the commented assigns.
Keep in mind that the mop is already existing including assigned values, derived from somwhere over the rainbow.

Because IsCacheSet always answers false the relevant code is :
Code: [Select]
                            {
                                LeadMoveInfo LeadInfo = new LeadMoveInfo();
                                profile.LeadInMove = new CamBam.Values.CBValue<LeadMoveInfo>(LeadInfo);
                                profile.LeadInMove.Cached.SpiralAngle = double.Parse(ParameterValue);
                            }

                            Log(" profile sprial angle = " + profile.LeadInMove.Cached.SpiralAngle);
                            Log(" profile leadin type = " + profile.LeadInMove.Cached.LeadInType);
                            Log(" profile tangent radius = " + profile.LeadInMove.Cached.TangentRadius);

                            break;

Result : All values are zeroed, except the assigned SpiralAngle.


You generate a new instance of LeadMoveInfo.
It is filled with zeroes, then you set the values.
Then you handover this LeadMoveInfo to the mop.
Thats works fine, but all existing values of the mop are overwritten.


And here´s the difference :

Our mop ows already a LeadInMove and LeadOutMove, already filled with data derived from actual selected tool.
The access to this LeadMoveInfo is oviously strange/not working :
The Cache-Mechanism replies always false and the members are not accessible using a simple ...LeadInMove.SpiralAngle = 3.14;

To ensure a reasonable tool is loaded, please try it
with an existing tool at your side by changing the first LayerName from

0 NP MyGoodPart

to

0 MP MyGoodPart L<YourToolLibrary> C<YourTool>

(maybe it´s a good idea to fill LeadInMove with some data, if zeroes are derived)


Best regards and thanks a lot for yout time and patience



PS.:

using python this simple mechanism works :

Code: [Select]
                if (Command=="LIA"):
                    # getting existing data from MOP
                    LeadInfo = profile.LeadInMove.Cached
                    LeadInfo.SpiralAngle = (float) (Parameter)   
                    profile.LeadInMove = CBValue[LeadMoveInfo] (LeadInfo)
               
best regards

Bernhard

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5329
  • Made in England
    • View Profile
Re: c# - Plugin Questions
« Reply #61 on: February 05, 2022, 15:25:12 pm »
This works  ;D

The MOP has to added to the CADfile BEFORE the parameters can be read so add these lines

  WaitForCamBam();
  CamBamUI.MainUI.InsertMOP(profile);


at the start of MOP OPTIONS

Code: [Select]

                //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                // THE MOP OPTIONS
                //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

                // now we have a prepared MOP, let´s process the parameters and values ! -----------------------------------------------------------------
                WaitForCamBam();
                CamBamUI.MainUI.InsertMOP(profile);


and remove these from the end.

//   WaitForCamBam();
//   CamBamUI.MainUI.InsertMOP(profile);
//   WaitForCamBam();


Now case LIA becomes,

Code: [Select]
                        case "LIA":

                            // get existing values
                            LeadMoveInfo LeadInfoIn = profile.LeadInMove.Cached;
                            // change one of those values
                            LeadInfoIn.SpiralAngle = double.Parse(ParameterValue);
                            // write all the values back out
                            profile.LeadInMove = new CamBam.Values.CBValue<LeadMoveInfo>(LeadInfoIn);
                            // refresh the properties panel                       
                            CamBamUI.MainUI.ObjectProperties.Refresh();
                         break;
« Last Edit: February 05, 2022, 15:29:14 pm by EddyCurrent »
Filmed in Supermarionation

Offline ThisAmplifierIsLoud

  • Storm Trooper
  • ***
  • Posts: 231
  • Jam it !
    • View Profile
Re: c# - Plugin Questions
« Reply #62 on: February 05, 2022, 18:49:08 pm »
YES,  YES, YESSSSSSS, JEDI !!!  ;D ;D ;D

I fondled around in that bermuda-triangle, but without success.

You got the trick just at the right time, this morning I was thinking about giving up.

But ... if we ever meet in this life for drinking beer, I have to sell my house and my car before.  ;D


Best regards ans have nice weekend !
Now time to drink beer and play some online-blues at Jamulus !

Best regards

Bernhard


PS.: In in addition I nailed the holding tabs. Was that easy !  ;D
« Last Edit: February 05, 2022, 22:30:05 pm by ThisAmplifierIsLoud »
best regards

Bernhard

Offline ThisAmplifierIsLoud

  • Storm Trooper
  • ***
  • Posts: 231
  • Jam it !
    • View Profile
Re: c# - Plugin Questions
« Reply #63 on: February 10, 2022, 08:24:20 am »
Wohoooooo !
I got the Mojo Working !

I was not lazy and adapted the oneekk solution for generating  Holding Tabs
https://cambamcnc.com/forum/index.php?topic=8196.msg65165#msg65165

THX to Carlo !

My approach is using all points found in a layer to become holdings tabs.

There are still some cleanups necessary, it´s very beta-beta,
but I am in a good mood all my wishes wil become true very soon.  ;D



best regards

Bernhard

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5329
  • Made in England
    • View Profile
Re: c# - Plugin Questions
« Reply #64 on: February 10, 2022, 12:28:11 pm »
It's an excellent plugin but I was thinking it might be a pain to rename the layers so what about this,

1. Click on the plugin in the menu
2. a form pops up with a text edit window
3. using your codes, make a text line for each MOP, use the ADD command to specify the layer for that MOP geometry
4. the MOPs would be ordered same as the lines of text in the editor
5. the text file could be saved for use later.

Another idea could use a collection of check boxes for commands and text boxes for values
provide a button to "add new MOP", a new set of check and text boxes are added.
repeat until finished
« Last Edit: February 10, 2022, 12:34:43 pm by EddyCurrent »
Filmed in Supermarionation

Offline ThisAmplifierIsLoud

  • Storm Trooper
  • ***
  • Posts: 231
  • Jam it !
    • View Profile
Re: c# - Plugin Questions
« Reply #65 on: February 10, 2022, 13:20:53 pm »
Eddy, this is IMHO unnecessary.
Renaming the layernames might be a pita, for sure.

I set the layernames already during constructing the dxf file !
The Syntax is easy and I can set the milling order, too.
I' m doing so for years, this toolchain runs really smooth with a python script (except the holding tab positions)

Target is : I load the dxf into cambam, run the AutoMagic and generate the GCode.
No addtional clicks, pops, files or something.

After enough betatesting I'll make the code public, so you can add what you are missing.
best regards

Bernhard

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5329
  • Made in England
    • View Profile
Re: c# - Plugin Questions
« Reply #66 on: February 10, 2022, 13:43:41 pm »
Seeing as you rename the layers in the dxf file it makes sense to keep it as it is.

A while ago on this forum there was talk about automating MOPs using the dxf layer colour as a parameter, or something like that,  but I can't find it.
Filmed in Supermarionation

Offline ThisAmplifierIsLoud

  • Storm Trooper
  • ***
  • Posts: 231
  • Jam it !
    • View Profile
Re: c# - Plugin Questions
« Reply #67 on: February 14, 2022, 18:44:49 pm »
I was quiet - but not lazy !  ;D

Programming plugins is really a pita due to poor documentation.
Needed approx. 40h-50h. Most effort is figuring out the cambam stuff,
and debugging is only possible using the output window.
And a lot of try, error and asking EddyCurrent.  ;D

Mission complete, I made some successful tests with a fat smile in my face.  ;D
The AutoMagic plugin fits so perfectly in my workflow, that no further clicks in CamBam are
necessary between loading dxf and gerating the G-Code.
Beside the time reduction this prevents me from making silly mistakes like mixing inside and outside,
forget the corner overcut or holding tabs...

Feel free to use, keep in mind, it is very beta, I set the version number 0.98.  ::)
Syntax checking is also very poor, if you make a mistake, the plugin will simply stop or crash.
Watch the output window to see results or some warnings !

The test.dxf file shows a few possibilities and the syntax for dxf layernames, which is always :

LineNumber Command Name [Options]


Example for a layername generating a Profile Inside with a depth of 5, Leadin-Angle 12.2 and 7 holding Tabs :

23  I  MyHoles  T5.0  LIA12.2  H7




List of possible Commands, Options for NewParts and Options for MOPs :

Code: [Select]
        public string[] NewPart_Options = {
                                    "L", "B",           // [string] library
                                    "C",                // [string] cam-style
                                    "X",                // [double] Position X
                                    "Y",                // [double] Position Y
                                    "M", "SZ",           // [double] StockSize Z
                                    };


        public string[] Commands = {
                                    "NP", "NT",         // new Part
                                    "DEFINE", "DEF",    // Define
                                    "GC",               // MOP GCode
                                    "I",                // MOP Profile Inside
                                    "O", "A",           // MOP Profile outside
                                    "P", "T",           // MOP Pocket
                                    "D", "B",           // MOP Drill
                                    "E", "G",           // MOP Engrave
                                   };


        public string[] MOP_Options = {
                                    "ADD",              // [int] Add primitives of an given Layer number (given in layer´s NAME!)
                                                        //       HINT : multiple ADD are allowed and are collected !
                                    "LIA",              // [double] Lead in angle
                                    "LIO",              // [double] Lead out angle
                                    "HPL",              // Holding Tabs based upon points found in layer
                                    "DM",               // Drill Mode CC=Canned cycle  CW=clockwise   CCW=counter clockwise
                                    "DI", "Z",          // [double] Depth increment
                                    "MD", "G",          // Milling direction CO or G = conventional   CL or L = climb   M=Mixed
                                    "CP", "SH",         // [double] clearance plane
                                    "RC", "A",          // [double] Roughing clearance
                                    "CW", "B",          // [double] cut width
                                    "SS", "W",          // [double] Stock Surface
                                    "SO", "S",          // [double] step over
                                    "OV", "I",          // [0 or 1] Corner overcut 0=Off 1=On
                                    "CO", "R",          // Cut ordering : LF or O = Level First   DF or T = Depth First
                                    "HH",               // [double] Holding Tab Height
                                    "HL",               // [double] Holding Tab Length
                                    "H",                // [int] number of Holding Tabs
                                    "O",                // [int] Optimisation 0=no 1=Standard(legacy) 2=Experimental(new)
                                    "T",                // [double] Target Depth
                                    "N",                // [double] spindle speed rpm
                                    "V",                // [double] Cut feedrate
                                    };



EDIT : MDEF removed, options copied at defining first part NP to MachiningOptions, too.
« Last Edit: February 15, 2022, 16:29:10 pm by ThisAmplifierIsLoud »
best regards

Bernhard

Offline BR52

  • Wookie
  • ****
  • Posts: 368
    • View Profile
Re: c# - Plugin Questions
« Reply #68 on: February 16, 2022, 22:24:36 pm »

Hello Bernhard.
Analyze the attached file, this is the correct way to make a plugin for Cambam.
Use .NET Framework 4.
The file "Class1.cs" has an error.

   Armando