Author Topic: Mark center of an arc  (Read 16836 times)

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8969
    • View Profile
Mark center of an arc
« on: January 30, 2013, 20:15:15 pm »
(updated with newer version which also draws a radius to make clear which point is associated with which arc)

I had a project yesterday that killed me for the time it took cutting and pasting arc center information to points lists.

IF there is an easier way, please tell me.

In the meanwhile, with a little help, I've put together a stupidly simple Python script that will drop a point on the drawing at an arc's center.

Hope it helps someone.  If there are obvious things I've not properly dealt with, please say so.  I'm not familiar with Python at all, and this took much longer to do than it should have.

It does not check if the drawing object is an arc; simply crashes on an attribute error, if so.  I don't know how to check that.

Thanks for everyone who helps,
Lloyd
« Last Edit: January 31, 2013, 14:32:50 pm by lloydsp »
"Pyro for Fun and Profit for More Than Fifty Years"

Online dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7408
    • View Profile
    • Cambam V1.0 French Doc
Re: Mark center of an arc
« Reply #1 on: January 30, 2013, 21:24:22 pm »
Hello Lloyd,

I try to do one in VBScript

Usable on any selection, detect arcs and create a pointlist with center of ALL selected arcs ; in addition coordinates are written in the log windows.

Code: [Select]
' centre d'un arc (dh42)

sub main

dim ent as Entity
dim arccircle as Arc
dim center as Point3F
dim pt as PointList = new PointList
dim empty as boolean = true

for each ent in view.SelectedEntities

if typeof ent is Arc 'only if arc

empty = false

arccircle = ent
center = arccircle.Point

'write coords in log windows
app.log ("x: " & center.x)
app.log ("y: " & center.y)
app.log ("")


pt.Add(center.x,center.y)

end if

next ent

if empty = false 'if at least one arc found
doc.Add(pt)
end if

end sub

++
David

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8969
    • View Profile
Re: Mark center of an arc
« Reply #2 on: January 30, 2013, 21:51:41 pm »
Ahh!  Thank you, David.

The names of the various methods and members are different in VB than in Python????

Also... How to SELECT the point(s) just created, so they "pop up" in the view?

Thanks again,
Lloyd
"Pyro for Fun and Profit for More Than Fifty Years"

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8969
    • View Profile
Re: Mark center of an arc
« Reply #3 on: January 30, 2013, 22:20:47 pm »
Ahah... but there is a problem, David.

Your script creates a pointlist with ALL the arc centers in it.  Thus, one arc and its accompanying center cannot be moved as an entity...all the points must move.

My script, simple as it is, creates a separate pointslist for each arc, so they may be moved around at will.

As I look at this more, the routine should also draw a ray from the arc center to the arc (which can be deleted if not needed) so that it's apparent exactly which point(list) should be associated with a particular arc.

(At this point, it's a pity there's no way to "group" objects, so when one is selected, all are.... Andy?)


I shall work on that, too! (Please, you do also... your code is much better than mine!)

LLoyd
« Last Edit: January 30, 2013, 22:24:27 pm by lloydsp »
"Pyro for Fun and Profit for More Than Fifty Years"

Online dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7408
    • View Profile
    • Cambam V1.0 French Doc
Re: Mark center of an arc
« Reply #4 on: January 31, 2013, 21:41:47 pm »
Hello,

Yes I think to this pb after the code is uploaded ; but it's always possible to explode the pointlist.

Good idea too for the ray ... for a next rev ;)

Sure that a "group" tool will be very useful !!

It will also be fine if the Draw/points/centers draw effectively the center of an arc and not the center of the bounding box ;D

++
David

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8969
    • View Profile
Re: Mark center of an arc
« Reply #5 on: February 01, 2013, 00:08:37 am »
(bumping this question to the top again)

Also... How to SELECT the point(s) just created, so they "pop up" in the view?

.... PS when Rodneyk did the "center of mass" plugin, he made it highlight the newly created point by selecting it.  That's the effect I want.

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

Offline BR52

  • Wookie
  • ****
  • Posts: 368
    • View Profile
Re: Mark center of an arc
« Reply #6 on: February 01, 2013, 16:38:07 pm »
Hi Lloyd

         Center of Gravity
If the object is a plate of any material and its thickness is uniform.
If the surface is different, the other side plate have to have the same surface equal.
To balance the center of the thickness.
The format of the accompanying drawing applies the equation.
For some formats applies the integral in equation, depends on the shape.

     Armando

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8969
    • View Profile
Re: Mark center of an arc
« Reply #7 on: February 01, 2013, 17:17:34 pm »
Thanks, Armando.  I will incorporate that in another script.

However, I was looking to mark the radial center of the arc.  I have done so, and with Andy's and others' help, cleaned it up.

Further (Andy), I added a selection of 'ent' as well as the radius and point, so that the whole of the item(s) now is highlighted after the operation.  I think I also need to push those new items onto the Undo stack, if they aren't automatically done.

Thanks, all!

(Whooda thunk an old codger like me would be learning Python!  :D  Where there's a problem to be solved, there's a language to do it!)

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

Online dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7408
    • View Profile
    • Cambam V1.0 French Doc
Re: Mark center of an arc
« Reply #8 on: February 01, 2013, 20:40:19 pm »
Hello,

It's me again  ;D

Code: [Select]
' centre d'un arc + rayon + select arc and point

sub main

dim ent as Entity
dim arccircle as Arc
dim center as Point3F
dim centroid as Point3F
dim pt as PointList = new PointList
dim pl as Polyline = New Polyline()

if (view.SelectedEntities.Length = 1) then


ent = view.SelectedEntities(0)

if typeof ent is Arc 'only if arc

arccircle = ent
center = arccircle.Point

pt.Add(center.x,center.y)
doc.Add(pt)

' get centroid
centroid = ent.GetCentroid

' create a polyline from x/y center to x/y centroid
pl.Add(center.x,center.y,0)
pl.Add(centroid.x,centroid.y,0)

doc.Add(pl)

'select the point and the arc
dim newselection as ArrayList = new ArrayList()
newselection.Add(pt)
newselection.Add(arccircle)
view.Select(newselection)


end if
end if

end sub


It's what you want Lloyd ?

++
David

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8969
    • View Profile
Re: Mark center of an arc
« Reply #9 on: February 01, 2013, 22:46:27 pm »
Ah, yes.  With changes, now, to handle multiple arcs, and make sure each radius and point is a new one for each arc...
Thank you, and thank everyone who's helping me understand this API.  (the VB is so much more intuitive to us old guys!)
Lloyd

Code: [Select]
' centre d'un arc + rayon + select arc and point
' mods to handle multiple arcs

sub main

dim ent as Entity
dim arccircle as Arc
dim center as Point3F
dim centroid as Point3F
dim i as integer
dim newselection as ArrayList = new ArrayList()

if (view.SelectedEntities.Length > 0) then

for i = 0 to view.SelectedEntities.Length-1
ent = view.SelectedEntities(i)
if typeof ent is Arc 'only if arc

' local new polyline for radius and new pointlist for center for each arc
' global arccircle is assigned to a new ent for each pass through the loop
'            all other items are global

dim pl as Polyline = New Polyline()
dim pt as PointList = new PointList

arccircle = ent
center = arccircle.Point

pt.Add(center.x,center.y)
doc.Add(pt)

' get centroid
centroid = ent.GetCentroid

' create a polyline from x/y center to x/y centroid
pl.Add(center.x,center.y,0)
pl.Add(centroid.x,centroid.y,0)

doc.Add(pl)

'select the point and the arc
newselection.Add(pt)
newselection.Add(arccircle)
newselection.Add(pl)
end if
next i
view.Select(newselection)
end if

end sub
« Last Edit: February 01, 2013, 22:59:23 pm by lloydsp »
"Pyro for Fun and Profit for More Than Fifty Years"

Online dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7408
    • View Profile
    • Cambam V1.0 French Doc
Re: Mark center of an arc
« Reply #10 on: February 01, 2013, 23:18:51 pm »
Hello,

Yes I like VB too, not ready for python  :  :( ... I hope that Andy will not remove VB from Cambam.

I think also that when I found the time I'll try to do plugins with VB. .... but when .. I don't know !

Now I'm playing with my brand new 3D scanner  :D  still lost hours of sleep!  ::)

++
David

Online dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7408
    • View Profile
    • Cambam V1.0 French Doc
Re: Mark center of an arc
« Reply #11 on: May 27, 2014, 19:25:58 pm »
Hello,

Here is the plugin version to draw centers of arcs (the item appears in the main draw/point list/ sub menu)

Works on multi selection (any, objects other than arcs are ignored)

++
David
« Last Edit: May 27, 2014, 19:36:57 pm by dh42 »

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8969
    • View Profile
Re: Mark center of an arc
« Reply #12 on: May 27, 2014, 19:38:34 pm »
AHAH!  Thank you David!

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

Online dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7408
    • View Profile
    • Cambam V1.0 French Doc
Re: Mark center of an arc
« Reply #13 on: May 27, 2014, 19:45:49 pm »
Re

Just a useful trick ; a quick way to mark arcs centers on a polyline that contain arcs.

- explode the polyline (the arcs and segments remain selected)
- use immediately the Arcs Centers plugin ; nothing is changed in the previous selection, you just need to do a Ctrl+J to "redo" the polylines

enjoy

++
David

Offline pixelmaker

  • CNC Jedi
  • *****
  • Posts: 1967
    • View Profile
    • pixelmaker
Re: Mark center of an arc
« Reply #14 on: May 27, 2014, 21:36:47 pm »
Thank you for the plugin David.

ralf