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

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5332
  • Made in England
    • View Profile
Re: c# - Plugin Questions
« Reply #30 on: February 01, 2022, 10:41:54 am »
LeadMoveInfo LeadInfo = new LeadMoveInfo();
profile.LeadInMove = new CamBam.Values.CBValue<LeadMoveInfo>(LeadInfo);
LeadInfo.LeadInType = LeadInTypeOptions.Spiral;
LeadInfo.SpiralAngle = 5;
Filmed in Supermarionation

Offline ThisAmplifierIsLoud

  • Storm Trooper
  • ***
  • Posts: 231
  • Jam it !
    • View Profile
Re: c# - Plugin Questions
« Reply #31 on: February 01, 2022, 10:48:43 am »
And again you make me smile !

Thanks, Eddy !


PS.: The finish is near !
best regards

Bernhard

Offline ThisAmplifierIsLoud

  • Storm Trooper
  • ***
  • Posts: 231
  • Jam it !
    • View Profile
Re: c# - Plugin Questions
« Reply #32 on: February 01, 2022, 12:40:24 pm »
Nearby ... nearby, Eddy.

I would prefer reading out the MOP´s existing LeadInfo, change only a specific property,
then write back to the MOP. (similar to your first proposal).

There´s something strange with the "Cached" or misusing it ?

This will solve my next upcoming problem with holding tabs, too.
best regards

Bernhard

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5332
  • Made in England
    • View Profile
Re: c# - Plugin Questions
« Reply #33 on: February 01, 2022, 14:36:26 pm »
I have this piece of test code set up, the results when run give;

False
True
15

You should always check first to see if the values are Cahed (IsCaheSet) otherwise it's an error
Once values are set in the MOP these become the Cached values and it's those that should be used.

Code: [Select]

  MOPPocket pro6 = new MOPPocket();

  CamBam.ThisApplication.AddLogMessage("Leadinmove is cached ? = " + pro6.LeadInMove.IsCacheSet);

  LeadMoveInfo LeadInfo = new LeadMoveInfo();
  pro6.LeadInMove = new CamBam.Values.CBValue<LeadMoveInfo>(LeadInfo);
  LeadInfo.LeadInType = LeadInTypeOptions.Spiral;
  LeadInfo.SpiralAngle = 15;

  CamBam.ThisApplication.AddLogMessage("Leadinmove is cached ? = " + pro6.LeadInMove.IsCacheSet);

    if(pro6.LeadInMove.IsCacheSet)
      {
            LeadMoveInfo LeadInfo2 = new LeadMoveInfo();
            LeadInfo2 = pro6.LeadInMove.Cached;
            CamBam.ThisApplication.AddLogMessage("Spiral Angle = " + LeadInfo2.SpiralAngle);
        }
         

     CAMPart newpart = new CAMPart("mypart");
      newpart.MachineOps.Add(pro6);
      myfile.Parts.Add(newpart);
       view.RefreshView();
« Last Edit: February 01, 2022, 14:39:05 pm by EddyCurrent »
Filmed in Supermarionation

Offline BR52

  • Wookie
  • ****
  • Posts: 368
    • View Profile
Re: c# - Plugin Questions
« Reply #34 on: February 01, 2022, 15:27:27 pm »

I don't understand where you want to arrive or do?

   Armando

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5332
  • Made in England
    • View Profile
Re: c# - Plugin Questions
« Reply #35 on: February 01, 2022, 19:45:49 pm »
Armando,  Bernhard said this;

Dear all,

on my brave way from Script-Yedi to Plugin-Yedi I decided to convert & improve my
one-and-only-super-duper-auto-magic python script  into a real plugin.

...

Best regards

Bernhard
 

The original script thread is here, https://cambamcnc.com/forum/index.php?topic=7703.msg61743#msg61743
« Last Edit: February 01, 2022, 19:47:28 pm by EddyCurrent »
Filmed in Supermarionation

Offline BR52

  • Wookie
  • ****
  • Posts: 368
    • View Profile
Re: c# - Plugin Questions
« Reply #36 on: February 01, 2022, 21:48:03 pm »

Thank very much, Eddy for the explanation and demonstration.
All that's missing is Bernhard write in Csharp and compiling in Visual Studio.

   Armando

Offline ThisAmplifierIsLoud

  • Storm Trooper
  • ***
  • Posts: 231
  • Jam it !
    • View Profile
Re: c# - Plugin Questions
« Reply #37 on: February 02, 2022, 14:31:12 pm »
Hi Eddy,

isn´t there is a simple way to write directly to the mop f.e.
 profile.DepthIncrement = new CamBam.Values.CBValue<double>(double.Parse("2.2"));

This mechanism works fine for a lot of stuff !

Obviously the problem is, that LeadIn/Out and tabs are using a complicated mechanism to access the properties.
Seems that at first a "structure" has be copied out, then modified and then write back again. Somehow...

The snippets are running, but they all are writing new data, not modify the properties of an already exisiting mop

Problem is that this is not resolved at runtime, keep in mind that "profile" is defined as
public object profile, the concrete type is set at runtime. (Profile, Pocket, Engrave, Drill)
Until this point this was VERY "elegant".

Whatever I try, it crashed at runtime. See screenshot above.
It´s always the same bermuda triangle.

Do you have another idea ?

Best regards

Bernhard
best regards

Bernhard

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5332
  • Made in England
    • View Profile
Re: c# - Plugin Questions
« Reply #38 on: February 02, 2022, 15:03:34 pm »
It would be ideal if you could attach the project files.
Filmed in Supermarionation

Offline ThisAmplifierIsLoud

  • Storm Trooper
  • ***
  • Posts: 231
  • Jam it !
    • View Profile
Re: c# - Plugin Questions
« Reply #39 on: February 02, 2022, 16:17:50 pm »
Yes, Sir, why not... there are no secrets inside.  ;D

Hope you can read it.
The critical part you´ll find in AutoMagic in class1 nearby at the end.

a DXF-File as Playground is also included,

Thanks in advance

Bernhard
best regards

Bernhard

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5332
  • Made in England
    • View Profile
Re: c# - Plugin Questions
« Reply #40 on: February 02, 2022, 17:48:23 pm »
Okay, I've downloaded it.
Filmed in Supermarionation

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5332
  • Made in England
    • View Profile
Re: c# - Plugin Questions
« Reply #41 on: February 02, 2022, 19:44:17 pm »
No crash using your test.dxf file.

6 sections read from F:\Visual Studio Projects\CamBam\test.dxf
unhandled entity : VIEWPORT
+++ AUTOMAGIC Start +++
-------- now process one layer after the other---------------------
0
0 NP MYGOODPART
token0 = 0
token1 = NP
token2 = MYGOODPART
11 I HOLES T3 Z1 RO
token0 = 11
token1 = I
token2 = HOLES
15 P POCKETS T4 Z2
token0 = 15
token1 = P
token2 = POCKETS
16 I CORNEROVERCUTPOCKETS ADD15 T4 I1
token0 = 16
token1 = I
token2 = CORNEROVERCUTPOCKETS
20 O CONTOUR T5 H5 LIA11.1
token0 = 20
token1 = O
token2 = CONTOUR
+++ AUTOMAGIC Finished +++
Filmed in Supermarionation

Offline BR52

  • Wookie
  • ****
  • Posts: 368
    • View Profile
Re: c# - Plugin Questions
« Reply #42 on: February 02, 2022, 20:42:54 pm »
Hi Eddy,
Test with attached file.

  Armando
« Last Edit: February 02, 2022, 20:45:09 pm by BR52 »

Offline ThisAmplifierIsLoud

  • Storm Trooper
  • ***
  • Posts: 231
  • Jam it !
    • View Profile
Re: c# - Plugin Questions
« Reply #43 on: February 03, 2022, 08:22:08 am »
@Armando : This will work only with the old script, not with this plugin.

@Eddy, yes of course, it seems working correct,
but it´s not what I want to.

I want to set the lead in angle only, keeping all other properties unchanged.
Actually I have to set the Type to Spiral explicitely to keep it working.

This is .... hmmmm..  ok for the LeadIn/Out angles, but looking forward to holdings tabs
this makes no sense.

Maybe it´s a problem, that the mop exists, but is still unadded to the system ?

I´ll prepare a crashing code.

Best regards

Bernhard
best regards

Bernhard

Offline ThisAmplifierIsLoud

  • Storm Trooper
  • ***
  • Posts: 231
  • Jam it !
    • View Profile
Re: c# - Plugin Questions
« Reply #44 on: February 03, 2022, 10:25:33 am »
That´s what I want to do, but it crashed


Code: [Select]
                        // crashing at runtime
                        case "LIA":
                            profile.LeadInMove.SpiralAngle = double.Parse(ParameterValue);
                            break;

And that happens :

best regards

Bernhard