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

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5332
  • Made in England
    • View Profile
Re: c# - Plugin Questions
« Reply #45 on: February 03, 2022, 12:23:27 pm »
Are you saying that if the MOP already exists then read in the value that has been set ?

What happens if the value has not been set ?
Filmed in Supermarionation

Offline ThisAmplifierIsLoud

  • Storm Trooper
  • ***
  • Posts: 231
  • Jam it !
    • View Profile
Re: c# - Plugin Questions
« Reply #46 on: February 03, 2022, 12:41:19 pm »
Yes, the mop already exists and is (pre-)set, at least inherited from actual selected Cam-Style

The result shoud be the same as clicking around :
1. select the entities
2. click Profile, Pocket, Engrave ... then all data is preset.
3. change values you want to change.

The plugin shall
1. select all entites of a layer
2. create a new mop depending on layername´s content
3. change some values depending on layername´s content
4. Add the the Mop to the active part


Quote
What happens if the value has not been set ?
This should be impossible. Values are inherited from the selected CAM Style, at least the unnamed in "standard-mm"


« Last Edit: February 03, 2022, 12:44:05 pm by ThisAmplifierIsLoud »
best regards

Bernhard

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5332
  • Made in England
    • View Profile
Re: c# - Plugin Questions
« Reply #47 on: February 03, 2022, 13:09:23 pm »
So is the logic like this ?



  if(profile.LeadInMove.IsCacheSet)   // if a value already exists
     {
          do something 1
     }
else  // there was no pre existing value set
    {
         do something 2
    }
Filmed in Supermarionation

Offline ThisAmplifierIsLoud

  • Storm Trooper
  • ***
  • Posts: 231
  • Jam it !
    • View Profile
Re: c# - Plugin Questions
« Reply #48 on: February 03, 2022, 13:24:05 pm »
in principle - yes,
but the "else" is IMHO not existing.

On creating a mop new CamBam.CAM.MOPProfile(newdoc, newdoc.Layers[LayerIndex].Entities.ToArray());

all possible values are valid and preset.

(Of course, a drill mop will not own a holding tab.)
best regards

Bernhard

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5332
  • Made in England
    • View Profile
Re: c# - Plugin Questions
« Reply #49 on: February 03, 2022, 13:27:22 pm »
 if(profile.LeadInMove.IsCacheSet)
     {
             profile.LeadInMove.SpiralAngle.Cached = double.Parse(ParameterValue);
             profile.LeadInMove.Cached.SpiralAngle = double.Parse(ParameterValue);
     }


Edit: Sorry I made an error there.
« Last Edit: February 03, 2022, 19:43:00 pm by EddyCurrent »
Filmed in Supermarionation

Offline ThisAmplifierIsLoud

  • Storm Trooper
  • ***
  • Posts: 231
  • Jam it !
    • View Profile
Re: c# - Plugin Questions
« Reply #50 on: February 03, 2022, 13:38:40 pm »
                            if (profile.LeadInMove.IsCacheSet)
                            {
                                profile.LeadInMove.SpiralAngle.Cached = double.Parse(ParameterValue);
                            }
                            else
                            {
                                Log("Mööööööööööööööööööööp !!!! not chached");
                            }


And I got : Mööööööööööööööööööööp !!!! not chached"   >:(


Can I force it to Cache ?
This is really complicated.
best regards

Bernhard

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5332
  • Made in England
    • View Profile
Re: c# - Plugin Questions
« Reply #51 on: February 03, 2022, 13:43:59 pm »
As far as I can make out, the cache is only filled when a value already exists in the LeadinMove part of the MOP

I thought the logic was,

If a value already exists in the cache then use it
else write a new value into the cache
Filmed in Supermarionation

Offline ThisAmplifierIsLoud

  • Storm Trooper
  • ***
  • Posts: 231
  • Jam it !
    • View Profile
Re: c# - Plugin Questions
« Reply #52 on: February 03, 2022, 13:48:06 pm »
But all values are existing, the LeadMoves and Holding tabs, too !

Remove the LIA11.1 option from the last layer´s name, run the plugin.
You´ll see all values are exisiting.

 Crazy story. ;D
best regards

Bernhard

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5332
  • Made in England
    • View Profile
Re: c# - Plugin Questions
« Reply #53 on: February 03, 2022, 15:05:43 pm »
Bernhard,

I'm sorry if I'm still not getting it but this seems to work as you want, i.e. it puts 11.1 into Spiral Angle of the MOP

   case "LIA":
                            LeadMoveInfo LeadInfo = new LeadMoveInfo();
                            profile.LeadInMove = new CamBam.Values.CBValue<LeadMoveInfo>(LeadInfo);
                            LeadInfo.SpiralAngle = double.Parse(ParameterValue);
                            break;
Filmed in Supermarionation

Offline ThisAmplifierIsLoud

  • Storm Trooper
  • ***
  • Posts: 231
  • Jam it !
    • View Profile
Re: c# - Plugin Questions
« Reply #54 on: February 03, 2022, 16:02:32 pm »
No, Sir !  :'(

See the difference :

The Mop without setting LIA11.1 :
All LeadIn Settings keep set in the used tool



The Mop with setting LIA11.1
here you see : Values are all set to zero, except the SpiralAngle we have set explicitely.


The problem is how to get the LeadMoveInfo from the mop in order to keep all other values unchanged.
Writing to mop is working fine.

Best regards

Bernhard



best regards

Bernhard

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5332
  • Made in England
    • View Profile
Re: c# - Plugin Questions
« Reply #55 on: February 03, 2022, 18:12:41 pm »
Okay, I see the problem now BUT where are those numbers coming from, 25,20,77 ?
When I change the Layer name to, "20 O CONTOUR T5 H5" all I see is 0,0,0

If they are coming from a Style then I don't have that Style on my system.
Filmed in Supermarionation

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5332
  • Made in England
    • View Profile
Re: c# - Plugin Questions
« Reply #56 on: February 03, 2022, 19:46:08 pm »
I forced some values into the MOP then tried it.

 case "LIA":
         if (profile.LeadInMove.IsCacheSet)
           {
                 profile.LeadInMove.Cached.SpiralAngle = double.Parse(ParameterValue);
           }


The other values stayed there and only the spiral angle was changed.
Filmed in Supermarionation

Offline ThisAmplifierIsLoud

  • Storm Trooper
  • ***
  • Posts: 231
  • Jam it !
    • View Profile
Re: c# - Plugin Questions
« Reply #57 on: February 03, 2022, 20:44:05 pm »
Eddy,

these values come from the style and library I defined in standard.template (or so).
Or the style was selected before the mop was created.
The task is to keep exactly these ones.

How did you force the values into the mop ?
best regards

Bernhard

Offline ThisAmplifierIsLoud

  • Storm Trooper
  • ***
  • Posts: 231
  • Jam it !
    • View Profile
Re: c# - Plugin Questions
« Reply #58 on: February 04, 2022, 09:20:17 am »
Were are running in a circle. :-)
Code: [Select]
                        case "LIAaaaaa":
                            // always false, so nothing happens
                            if (profile.LeadInMove.IsCacheSet)
                            {
                                profile.LeadInMove.Cached.SpiralAngle = double.Parse(ParameterValue);
                            }
                            break;


                        case "LIAxxxxxx":
                            // this crashes at runtime : Cannot perform runtime binding on a null reference
                            profile.LeadInMove.Cached.SpiralAngle = double.Parse(ParameterValue);
                            break;


                        case "LIA":
                            // this crashes at runtime : CamBam.Values.CBValue<CamBam.CAM.LeadMoveInfo> does not contain a definitionfor SpiralAngle
                            profile.LeadInMove.SpiralAngle = double.Parse(ParameterValue);
                            break;


So ... can I do anything to force this "Caching" ? Or wait for ?

Best regards

Bernhard
best regards

Bernhard

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5332
  • Made in England
    • View Profile
Re: c# - Plugin Questions
« Reply #59 on: February 04, 2022, 12:14:30 pm »
When I run this code the results are below it. (first section commented out)

Code: [Select]
case "LIA":

                            //// put some values in as though they came from a style or template
                            //LeadMoveInfo FromStyleInfo = new LeadMoveInfo();
                            //profile.LeadInMove = new CamBam.Values.CBValue<LeadMoveInfo>(FromStyleInfo);
                            //FromStyleInfo.SpiralAngle = 12.0;
                            //FromStyleInfo.LeadInType = LeadInTypeOptions.Spiral;
                            //FromStyleInfo.TangentRadius = 8.5;

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

                            // if any values pre exist in the MOP's lead in section
                            if (profile.LeadInMove.IsCacheSet)
                            {
                                profile.LeadInMove.Cached.SpiralAngle = double.Parse(ParameterValue);
                            }
                            // else there were no pre existing values
                            else
                            {
                                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;


+++ 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
 profile sprial angle = 11.1
 profile leadin type = None
 profile tangent radius = 0
+++ AUTOMAGIC Finished +++


When I run the same code with the first section not commented out, the results are below it.


Code: [Select]
case "LIA":

                             // put some values in as though they came from a style or template
                             LeadMoveInfo FromStyleInfo = new LeadMoveInfo();
                             profile.LeadInMove = new CamBam.Values.CBValue<LeadMoveInfo>(FromStyleInfo);
                             FromStyleInfo.SpiralAngle = 12.0;
                             FromStyleInfo.LeadInType = LeadInTypeOptions.Spiral;
                             FromStyleInfo.TangentRadius = 8.5;

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

                            // if any values pre exist in the MOP's lead in section
                            if (profile.LeadInMove.IsCacheSet)
                            {
                                profile.LeadInMove.Cached.SpiralAngle = double.Parse(ParameterValue);
                            }
                            // else there were no pre existing values
                            else
                            {
                                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;

+++ 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
 profile sprial angle = 12
 profile leadin type = Spiral
 profile tangent radius = 8.5
 profile sprial angle = 11.1
 profile leadin type = Spiral
 profile tangent radius = 8.5
+++ AUTOMAGIC Finished +++
« Last Edit: February 04, 2022, 12:16:56 pm by EddyCurrent »
Filmed in Supermarionation