Author Topic: unclosed polylines to one direction  (Read 408 times)

Offline pixelmaker

  • CNC Jedi
  • *****
  • Posts: 1825
    • View Profile
    • pixelmaker
unclosed polylines to one direction
« on: June 07, 2021, 12:19:52 pm »
Hello
I am looking for a simple script that rotates the direction of all selected unclosed polylines to one direction.
Is it possible at all?
Does an unclosed polyline have a direction at all?

ralf

Offline Dragonfly

  • CNC Jedi
  • *****
  • Posts: 2445
    • View Profile
Re: unclosed polylines to one direction
« Reply #1 on: June 07, 2021, 13:07:48 pm »
Do you want to automate the process?
Because the manual option is with polyline selected Right Click for drop down menu -> Polyline -> Reverse.

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8449
    • View Profile
Re: unclosed polylines to one direction
« Reply #2 on: June 07, 2021, 13:43:38 pm »
Ralf,
In answer to the last question -- yes.  Polylines (open or not) have a 'start point', then a list of points to their end.

The ordering of those points determines the 'direction'.

Lloyd
"Pyro for Fun and Profit for More Than Fifty Years"

Offline pixelmaker

  • CNC Jedi
  • *****
  • Posts: 1825
    • View Profile
    • pixelmaker
Re: unclosed polylines to one direction
« Reply #3 on: June 07, 2021, 13:46:48 pm »
Yes I want a script for this.
A user has a file with many open polylines. He wants to align them all in one direction.
For closed polylines I can query the direction  (CW,CCW) and flip all polylines that have a certain direction. This way I can align all polylines in one direction.
With open polylines I only get back "unknown" as direction.
If I flip all polylines with the direction "unknown" this only reverses all selected open polylines.
But I can't find a way to turn all selected open polylines in one direction.

ralf


Offline pixelmaker

  • CNC Jedi
  • *****
  • Posts: 1825
    • View Profile
    • pixelmaker
Re: unclosed polylines to one direction
« Reply #4 on: June 07, 2021, 13:52:16 pm »
He tells me that in Qcad there is a funktion to switch open polylines betwenn CW and CCW.
I do not know the CAD.
But I can not imagine the sense.
If I now reverse the coordinates of the point list in the order I still get no defined direction.
How can there be a CW or CCW for an open polyline?

ralf

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8449
    • View Profile
Re: unclosed polylines to one direction
« Reply #5 on: June 07, 2021, 14:23:40 pm »
Ralf,
It depends upon the 'net vector' described by the line.

It's only a 'common descriptor' -- a 'convention', not a true descriptor.  Any line could violate the common terms simply with points that meander.

Lloyd
"Pyro for Fun and Profit for More Than Fifty Years"

Offline pixelmaker

  • CNC Jedi
  • *****
  • Posts: 1825
    • View Profile
    • pixelmaker
Re: unclosed polylines to one direction
« Reply #6 on: June 07, 2021, 15:49:50 pm »
Thank you Lloyd,
for me such a script is much too complicated.

ralf

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 4739
    • View Profile
Re: unclosed polylines to one direction
« Reply #7 on: June 07, 2021, 15:58:36 pm »
Have a look at the dragknife script here; https://cambamcnc.com/forum/index.php?topic=3628.msg23778#msg23778

search for "direction" and you should find the required  code.
Made in England

Offline pixelmaker

  • CNC Jedi
  • *****
  • Posts: 1825
    • View Profile
    • pixelmaker
Re: unclosed polylines to one direction
« Reply #8 on: June 07, 2021, 19:38:36 pm »
Hello
thank you for the answers.
The problem is solved. I now got a file from the user and see the error. In the attached file there should be simply an overcut in the corners. Every second line is in the wrong direction.
The easiest solution is to select all objects on the "Zapfen ausecken" layer and then set the polyline to closed in the options.
I now also understand why it is not possible to automatically align open polylines in the same direction.
Also the plugin Collision Detection always produces some lines in wrong direction.
To close the Lines soves the problem.

ralf

Offline dave benson

  • CNC Jedi
  • *****
  • Posts: 1468
    • View Profile
Re: unclosed polylines to one direction
« Reply #9 on: June 08, 2021, 03:28:13 am »
Ralf

Simply closing all the polylines causes other issues, it depends on the  line.
For me, I use it to make relatively simple shapes into geometry for mechanical components, it's not
that bad of a job, but if I were to do engravings where the pattern is very complex, then it would
get old pretty quick.

Some of the decisions of whether a line should be closed or open depends on what the user
wants to do, and its hard to second guess what the users intent is.

You can go some way (don't know how much) towards automating the process by using a state machine
with it's states informed by a preferences file.
These become settings for the state machine, generally the more states the better the performance
on complex tasks.

States = Rules
In sudo code it might look like this:
Is this a polyline
is it closed or open
make a decision on whether the line should be left in it's present state
or modified according to the preferences selected by the user in the prefs file and perhaps some
'on the fly' generated states.

For an complex engraving, there would be many rules, and you would have to do rigorous checking, as a rule
may conflict with other rules (perhaps only in rare cases only) making the rules would be a long and tedious.
The drilling plugin is an example of a moderately complex state machine with it's own sim, the ability to
remember what it did earlier, and to look forward and backward in the file to see if anything there might influence
the decision that it's going to make now.

The thing is that plugin took 3 months to do, and the state machine rules became to numerous to keep track of
in my head and I had to use the 'state machine nanny' from the turrets.

The CC should be re-written with a different programming paradigm, from the ground up.
When I realised this I stopped all further work on it.

Dave

Offline pixelmaker

  • CNC Jedi
  • *****
  • Posts: 1825
    • View Profile
    • pixelmaker
Re: unclosed polylines to one direction
« Reply #10 on: June 08, 2021, 10:22:02 am »
Hallo Dave,
there are always projects that are best done on the beach in nice weather without time pressure. I think programming something like this is one of those jobs. Bad is when you live on the beach where the sun always shines and you still have no time. ;-)
I find your plugins very good and use them often.
I have suggested Collision Detector to solve this problem.
Quote
Simply closing all the polylines causes other issues.
That is correct, but here it led to the goal.

There are questions in my forum every day how to get something done with CamBam. I must admit, with the 143 plugins that exist for CamBam, I lose sometimes the overview. Often I know a function, but no longer know which plugin contains this function, maybe my age.
Sometimes I search for a long time and find no solution. Then I ask here, I know that here the specialists read along.
I would like to thank everyone here for always helping and making CamBam what it is.
Only Andy could get in touch again. ,-)

ralf

Offline dave benson

  • CNC Jedi
  • *****
  • Posts: 1468
    • View Profile
Re: unclosed polylines to one direction
« Reply #11 on: June 08, 2021, 11:59:51 am »
Hi Ralf
I agree with your sentiments, I've often realised after doing some cad work, that I could have made life easier for myself by using a plugin.
There are some (what I consider essential) plugins that should be migrated to CB.
nummove being one of them.
When testing if  CB 64 bit would run on my laptop, I installed CB (without any plugin's) and was a
little underwhelmed.
For the 2.5d work on the mill, it's my goto (I have and use other cam programs) but they generally
take longer to set up and get a result.
On a side note, I wrote a CB to Freecad tool library converter a few weeks ago using 0.18, this took
some time, (CB's tool library structure was far better) only then to realise that they (the path developer\s) changed the tool libraries and my code was useless for 0.19.

I was actually glad about this as they must have had someone with cnc machining experience
providing knowledgeable input.
I inspected the new lib code and visited Sliptronic's youtube channel (the path guy).
He stated that the tool compensation already works for endmills,bull nose,ball nose and vee cutters in 0.19. and the new changes were made for upcoming things like the lathe module. I'm looking forward to this more than I can say.
I would like to help Sliptronic he comes across like a nice guy, the thing is, I feel the same way about python as Integza does about tomatoes.

Dave