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

Offline ThisAmplifierIsLoud

  • Storm Trooper
  • ***
  • Posts: 231
  • Jam it !
    • View Profile
c# - Plugin Questions
« on: January 22, 2022, 10:58:34 am »
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.

I fear a lot of upcoming questions ... so the title is very common.
(I do NOT like python)
The way creating a plugin using C# is done.

Question of the day :

How to remove a layer ?

Code: [Select]
newdoc = CamBamUI.MainUI.ActiveView.CADFile;
newdoc.Layers[i].???????????????

Cannot find a remove, delete or somewhat.
Wrong way ?

Best regards

Bernhard

 
best regards

Bernhard

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5329
  • Made in England
    • View Profile
Re: c# - Plugin Questions
« Reply #1 on: January 22, 2022, 11:18:43 am »
newdoc.Layers.Remove(Layer);

You should get ILSpy; https://github.com/icsharpcode/ILSpy/releases
then use it to look inside CamBam.CAD.dll
« Last Edit: January 22, 2022, 11:21:34 am by EddyCurrent »
Filmed in Supermarionation

Offline ThisAmplifierIsLoud

  • Storm Trooper
  • ***
  • Posts: 231
  • Jam it !
    • View Profile
Re: c# - Plugin Questions
« Reply #2 on: January 22, 2022, 11:31:43 am »
I tried that :

https://www.cambam.co.uk/forum/index.php?topic=7795.msg62454

but it seems not  working :

The deleted layer is still visible, the entities within disappeared, but are still present.
Somewhat strange.

I looks like a kind of update is missing.

But if I try the method Update, CB wants to save a CB file.


EDIT : After saving and reloading the CB-File the deleted layers are gone,
so just a kind of "refresh", "garbage collection" ... is missing ?


EDIT :
doing this in python script works fine , the layer view is updated immediately:

newdoc.SetActiveLayer(newdoc.Layers[0].Name)
newdoc.ActiveLayer.Entities.Clear()
newdoc.Layers.Remove(newdoc.ActiveLayer)
« Last Edit: January 22, 2022, 12:48:40 pm by ThisAmplifierIsLoud »
best regards

Bernhard

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5329
  • Made in England
    • View Profile
Re: c# - Plugin Questions
« Reply #3 on: January 22, 2022, 13:35:20 pm »
Try the first one, the others are ones to keep in mind for other but similar purposes.
always use, CamBamUI.MainUI.ActiveView.RefreshView(); after making changes to the drawing window.

CamBamUI.MainUI.ActiveView.DrawingTree.Refresh();

CamBamUI.MainUI.ActiveView.RefreshView();

CamBamUI.MainUI.ActiveView.UpdateViewport();

foreach (Layer layer in CamBamUI.MainUI.ActiveView.CADFile.Layers)  layer.Update();

CamBamUI.MainUI.ObjectProperties.Refresh();
« Last Edit: January 22, 2022, 13:43:28 pm by EddyCurrent »
Filmed in Supermarionation

Offline ThisAmplifierIsLoud

  • Storm Trooper
  • ***
  • Posts: 231
  • Jam it !
    • View Profile
Re: c# - Plugin Questions
« Reply #4 on: January 22, 2022, 14:05:14 pm »
Eddy, my personal hotline ...  ;D

THX for fast reply. But none of them was working.

BTW. using Visual Studio 2022 you can also inspect the references !
best regards

Bernhard

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5329
  • Made in England
    • View Profile
Re: c# - Plugin Questions
« Reply #5 on: January 22, 2022, 14:21:02 pm »
CamBamUI.MainUI.ActiveView.DrawingTree.ReloadTree();

But with ILSpy you can also get into the actual code.
« Last Edit: January 22, 2022, 14:30:53 pm by EddyCurrent »
Filmed in Supermarionation

Offline ThisAmplifierIsLoud

  • Storm Trooper
  • ***
  • Posts: 231
  • Jam it !
    • View Profile
Re: c# - Plugin Questions
« Reply #6 on: January 22, 2022, 14:31:55 pm »
Eddy .... Thank you !

And again I owe you a can of beer.

If we ever meet, I´ll be a poor man !  ;D


What time is it actually at your site ?
best regards

Bernhard

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5329
  • Made in England
    • View Profile
Re: c# - Plugin Questions
« Reply #7 on: January 22, 2022, 14:33:15 pm »
14:33
Filmed in Supermarionation

Offline ThisAmplifierIsLoud

  • Storm Trooper
  • ***
  • Posts: 231
  • Jam it !
    • View Profile
Re: c# - Plugin Questions
« Reply #8 on: January 22, 2022, 14:42:46 pm »
"Made in England" ... these old eyes ... and the dark sunglasses ...  ::)
best regards

Bernhard

Offline ThisAmplifierIsLoud

  • Storm Trooper
  • ***
  • Posts: 231
  • Jam it !
    • View Profile
Re: c# - Plugin Questions
« Reply #9 on: January 25, 2022, 09:28:29 am »
And the next problem is around the corner - please help !

Code: [Select]
                       
                        // collect points to a pointlist for nesting ------------------------------------
                        // select complete layer
                        view.SelectAllLayerGeometry(newdoc.Layers[LayerIndex]);

                        // Edit - Join Points/Pointlists to a single Pointlist
                        PointListUtils.JoinPointlist(CamBamUI.MainUI.ActiveView);

                        // until here everything works correct, multiple pointlists are joined to a single new one, I see it in the tree

                        NestingPointlistID = newdoc.Layers[LayerIndex].Entities[0].ID; // <=== returns the no longer existingID before joining instead of new one !



Again a kind of refresh / update problem.
And -how funny- I have done this in a python script working fine !

I tried without success :
Code: [Select]
                        CamBamUI.MainUI.ActiveView.DrawingTree.Update();
                        CamBamUI.MainUI.ActiveView.DrawingTree.Refresh();
                        CamBamUI.MainUI.ActiveView.DrawingTree.ReloadTree();
                        CamBamUI.MainUI.CADFileTree.Refresh();
best regards

Bernhard

Offline ThisAmplifierIsLoud

  • Storm Trooper
  • ***
  • Posts: 231
  • Jam it !
    • View Profile
Re: c# - Plugin Questions
« Reply #10 on: January 25, 2022, 11:12:15 am »
No, Sir,  :(

(missing your post ?)

I still get the wrong ID based upon the layer´s entity list before joining.

After joining manually the result is correct.
best regards

Bernhard

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5329
  • Made in England
    • View Profile
Re: c# - Plugin Questions
« Reply #11 on: January 25, 2022, 11:43:28 am »
Sorry about removing the post, I did a quick test and it did not work so tried something else.

It appears that JoinPointlist uses a background worker thread so we have to wait until it finishes before moving on.


while (view.IsThinking)    Application.DoEvents();
« Last Edit: January 25, 2022, 12:12:27 pm by EddyCurrent »
Filmed in Supermarionation

Offline ThisAmplifierIsLoud

  • Storm Trooper
  • ***
  • Posts: 231
  • Jam it !
    • View Profile
Re: c# - Plugin Questions
« Reply #12 on: January 25, 2022, 11:49:15 am »
And again you made my day, thank you !

I think this will solve some similar "effects", I´ve seen.
best regards

Bernhard

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5329
  • Made in England
    • View Profile
Re: c# - Plugin Questions
« Reply #13 on: January 25, 2022, 11:52:00 am »
There's a similar trick when waiting for an edit mode.

while (view.CurrentEditMode != null) Application.DoEvents();
Filmed in Supermarionation

Offline ThisAmplifierIsLoud

  • Storm Trooper
  • ***
  • Posts: 231
  • Jam it !
    • View Profile
Re: c# - Plugin Questions
« Reply #14 on: January 26, 2022, 15:04:36 pm »
And here´s the new question of the day !


How to set inside/outside of a MOPProfile ?

Code: [Select]
                        CamBam.CAM.MOPProfile profile;
                        profile = new CamBam.CAM.MOPProfile(newdoc, newdoc.Layers[LayerIndex].Entities.ToArray());
                        profile.Enabled = false;  // just an example to see it working
                        profile.Name = "Captain Bacardi";

                        profile.InsideOutside = ????

                        CamBamUI.MainUI.InsertMOP(profile);


Best regards

Bernhard



EDIT : using python it worked fine :
Code: [Select]
                profile=MOPProfile(newdoc,newdoc.Layers[i].Entities.ToArray())
                profile.InsideOutside = CBValue[InsideOutsideOptions](InsideOutsideOptions.Inside)
« Last Edit: January 26, 2022, 15:06:49 pm by ThisAmplifierIsLoud »
best regards

Bernhard