CamBam
News:
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
June 27, 2019, 06:03:53 am


Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Some Snippets of Code - To be improved by the Community  (Read 670 times)
onekk
Wookie
****
Offline Offline

Posts: 450


View Profile
« on: January 08, 2019, 17:16:06 pm »

In my recent work on some of my plugins, I've found some difficulties, so I'm wondering if a Collective CamBam Guide to plugin writing  is worth to be done.

Having seen that the documentation progress are very slow and (sadly) even CamBam is developed slowly, but having found that CamBam is a very good CAM, and more "friendly" to use related to some of the other product around (at least in the same range of price).

Managing the "logic" behind the "internals" of CamBam is sometimes weird as some "construct" are implemented using different types of Object List<> or even "Collection" of various types and not all the "methods" are implemented.

So in the Example Below these variable are used:
 
Code:
static ICADView view = CamBamUI.MainUI.ActiveView;
static CADFile myfile;


Speaking of some implementation notes;

There is an easy way to Add a Layer.

Code:
Layer retL = myfile.CreateLayer(l_name);
retL.Color = Color.FromName("colorname");
retL.Update();
view.RefreshView();

but to delete them is more "involuted" as there is no a "myfile.DeleteLayer(l_name)"

To delete a layer and all the entities that are present in it

(This piece of code don't show warnings when deleting entities)

Code:

myfile = view.CADFile;

// obiouvsly name is the layer name

if (myfile.HasLayer(name))
   {
        // Select as Active Layer the layer named "name"  
        myfile.SetActiveLayer(name);
        // Clear all Entities in the Active Layer
        myfile.ActiveLayer.Entities.Clear();
        // Layers is a "LayerCollection" object of myfile
        // We remove the Active Layer retrieved with "myfile.ActiveLayer" from the "LayerCollection"  
        myfile.Layers.Remove(myfile.ActiveLayer);
        //Set the Active layer to Layer[0] maybe a workaround but it works on almost all "palin" cases
        myfile.SetActiveLayer(myfile.Layers[0].Name);
      
    }


I see that this part of previous code is wrong, as it not set the default layer

Code:
// The Layer null is the default Layer i.e the Layer[0]
myfile.SetActiveLayer(null);


Let me see if this is useful.

Regards

Carlo D.
 
« Last Edit: January 09, 2019, 11:09:41 am by onekk » Logged

Carlo D. (onekk)

eShapeoko #343 750x1000 mm + GRBL + bCNC + CamBam
EddyCurrent
CNC Jedi
*****
Offline Offline

Posts: 3960



View Profile
« Reply #1 on: January 08, 2019, 20:43:28 pm »

Carlo,

Have a read here first; http://www.cambam.co.uk/forum/index.php?topic=4727.0

Then have a look here; http://www.atelier-des-fougeres.fr/Cambam/Aide/API%20Doc/menu/cambam_cad.html

My thoughts were to create an example code snippet for each method listed in the API
Logged

Made in England
dh42
Administrator
CNC Jedi
*****
Offline Offline

Posts: 5491



View Profile WWW
« Reply #2 on: January 09, 2019, 00:16:14 am »

Hello

Other snippets here:

http://www.cambam.co.uk/forum/index.php?topic=3878.0

I've added this page to the menu

++
David
« Last Edit: January 09, 2019, 00:22:27 am by dh42 » Logged
Garyhlucas
CNC Jedi
*****
Offline Offline

Posts: 1244


View Profile
« Reply #3 on: January 09, 2019, 01:38:26 am »

I am not programming anything, YET, but I can see this as a really great idea for when I want to!
Logged

Gary H. Lucas

Have you read my blog?
 http://a-little-business.blogspot.com/
onekk
Wookie
****
Offline Offline

Posts: 450


View Profile
« Reply #4 on: January 09, 2019, 10:51:27 am »

Thanks to all, I haven't noted the snippets in the APi, (Looked at it some months ago)

David For the snippets part I've missed it (Or maybe I don't remember to see it), how to contribute to the pages on ateliers..... ?

As a side note

Someone know hot to retrieve the Default Layer?

In the first version of the snippet code I've done some wrong assumption on "Layer name = null".

As the "Default Layer" name is changing between languages, how to retrieve the "default name" despite the language.

I'm assuming that setting it to Layer[0].Name will suffice, but if you move it in the treeview I don't know if the positional argument of "LayerCollection" is changed.

Someone may have found out this thing and could facilitate some research.

Regards to all and many thanks for answering.

Carlo D.

 
« Last Edit: January 09, 2019, 11:11:27 am by onekk » Logged

Carlo D. (onekk)

eShapeoko #343 750x1000 mm + GRBL + bCNC + CamBam
EddyCurrent
CNC Jedi
*****
Offline Offline

Posts: 3960



View Profile
« Reply #5 on: January 09, 2019, 11:12:17 am »

I think there is no such thing as "Default Layer" rather there are Layers and a Layer Collection with the properties shown in attached image.

If the Layer count is zero then I would assume that's the nearest thing to a default layer but it could have any "Name" if changed by the user.


* layers.jpg (103.88 KB, 679x777 - viewed 53 times.)
« Last Edit: January 09, 2019, 11:14:45 am by EddyCurrent » Logged

Made in England
onekk
Wookie
****
Offline Offline

Posts: 450


View Profile
« Reply #6 on: January 09, 2019, 13:28:10 pm »

I will use the "Layer[0].Name" as in the modified snippet, I have not tried to delete all layer and see what happens, maybe i will check this case.

But it is a "strange" user case, maybe some check whould resolve the weirdness if there will be any.

(The generally the message emitted if some layer is not found is "Layer "Name" not found" in the "log window").

Now I've some time to experiment many project (sadly not for money) but my Z axis is broken and the new axis is in transit from UK, so no "chips flying around".

Regards

Carlo D.
Logged

Carlo D. (onekk)

eShapeoko #343 750x1000 mm + GRBL + bCNC + CamBam
dh42
Administrator
CNC Jedi
*****
Offline Offline

Posts: 5491



View Profile WWW
« Reply #7 on: January 09, 2019, 23:22:02 pm »

Hello

Quote
I will use the "Layer[0].Name" as in the modified snippet, I have not tried to delete all layer and see what happens, maybe i will check this case.

Maybe with the EnsureActiveLayer() ?

Quote
As the "Default Layer" name is changing between languages, how to retrieve the "default name" despite the language.

ActiveLayer.name (in CamBam.CAD.CADFile)

there is no default name as for Entities, so the layer name used as default is always dependent of the language.

Quote
how to contribute to the pages on ateliers..

Currently, the API website is abandoned because too difficult to maintain up to date with no info from Andy when something change and also because all the pages are done by hand ... so I prefer to add the snippets on the forum.

Another reason is that it is more convenient to search for a snippet with a title like "layer management" than to search in the API by classes to find an associated snippet ; ex: in the case of layer what we need are in CADfile, Layer, Layer collection ... and you need to know that ... not easy for beginners ...

Andy as started a GIT to handle CamBam resources and hopefully He will add a more convenient way to handle the API doc in the future.

++
David
« Last Edit: January 09, 2019, 23:26:36 pm by dh42 » Logged
onekk
Wookie
****
Offline Offline

Posts: 450


View Profile
« Reply #8 on: January 12, 2019, 09:55:12 am »

Hoping of some work by Andy on Cambam, ok for the snippets part on this forum, let me see and eventually discuss on it between the guys on this forum that actively make plugins.

I'm intermittetly working on plugins, depending on my needs.

Actually I'm working on an improved version of Boxes, with some different boxes type.

But this has revelade to be a "long term project" as many rework of code is needed, and my memory isn't helping me, so I've to revise all my code to re-learn what I've done and most important why :-D.

Thanks and Regards

Carlo D.
Logged

Carlo D. (onekk)

eShapeoko #343 750x1000 mm + GRBL + bCNC + CamBam
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.145 seconds with 20 queries.

Copyright © 2018 HexRay Ltd. | Sitemap