Author Topic: Couple of scripting questions: regions and entity size  (Read 766 times)

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 4854
    • View Profile
Re: Couple of scripting questions: regions and entity size
« Reply #30 on: November 17, 2021, 12:00:51 pm »
Seek and ye shall find !

Here is the required piece of script in Python.   ;)

1. Import one of the sample dxf files
2. Select everything then use menu item, Edit->Join
3. select everything then run the script below.


Code: [Select]
from System import Array
allmyPolylines = []
myRegion = []

for layer in doc.Layers:
    for ent in layer.Entities:
        if ent.PrimitiveType == "Polyline":
            print "Got Polyline with id = ", ent.ID
            allmyPolylines.Add(ent)
        else:   
            print "Not Polyline with id = ", ent.ID
           
myRegion = Region.CreateFromPolylines(Array[Polyline](allmyPolylines))

for region in myRegion:
    doc.Add(region)
« Last Edit: November 17, 2021, 12:07:20 pm by EddyCurrent »
Made in England

Offline homba

  • Ewok
  • *
  • Posts: 42
    • View Profile
Re: Couple of scripting questions: regions and entity size
« Reply #31 on: November 17, 2021, 20:01:09 pm »
oh my! ... that's exactly what I'm looking for. Thank you! I'll incorporate and report back  :D

how did you figure out how to pass the correct data type??

Online dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6682
    • View Profile
    • Cambam V1.0 French Doc
Re: Couple of scripting questions: regions and entity size
« Reply #32 on: November 17, 2021, 21:08:15 pm »
Hello

Nice job Eddy ; you still have hairs ?  ;D

added to the snippet
https://cambamcnc.com/forum/index.php?topic=3878.msg45203#msg45203

++
David

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 4854
    • View Profile
Re: Couple of scripting questions: regions and entity size
« Reply #33 on: November 17, 2021, 21:36:18 pm »
how did you figure out how to pass the correct data type??

The information here, http://www.cambam.info/doc/api/Region.htm
and from Visual Studio showed the Region function parameter types.

Region[] CreateFromPolylines (Polyline[] plines)

which clearly shows arrays are required due to the square brackets.

I then had to find how to use arrays in Python without any add in libraries.

CamBam uses IronPython so I had a look at it's documentation here, https://ironpython.net/documentation/dotnet/
and under ".NET arrays", found the answer.

Of course it took half a day to get there.  :D
« Last Edit: November 17, 2021, 21:42:17 pm by EddyCurrent »
Made in England

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 4854
    • View Profile
Re: Couple of scripting questions: regions and entity size
« Reply #34 on: November 17, 2021, 21:43:33 pm »
Hello

Nice job Eddy ; you still have hairs ?  ;D

Yes, but not on my head  ;D
Made in England

Offline homba

  • Ewok
  • *
  • Posts: 42
    • View Profile
Re: Couple of scripting questions: regions and entity size
« Reply #35 on: November 19, 2021, 20:37:27 pm »
This is another very helpful piece of information too ... thanks :)

how did you figure out how to pass the correct data type??

The information here, http://www.cambam.info/doc/api/Region.htm
and from Visual Studio showed the Region function parameter types.

Region[] CreateFromPolylines (Polyline[] plines)

which clearly shows arrays are required due to the square brackets.

I then had to find how to use arrays in Python without any add in libraries.

CamBam uses IronPython so I had a look at it's documentation here, https://ironpython.net/documentation/dotnet/
and under ".NET arrays", found the answer.

Of course it took half a day to get there.  :D