Author Topic: [script] Numerical XY Move + [plugin] NumMove  (Read 136102 times)

Online dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7408
    • View Profile
    • Cambam V1.0 French Doc
[script] Numerical XY Move + [plugin] NumMove
« on: October 30, 2012, 20:28:16 pm »
Hello,

For my use I do this little script to move a selection with numerical input ; if that can help someone ;)

If you let the value empty, there is no move for this axis.

copy/paste in a blank VBscript and save it with .vbs

Code: [Select]
' Move_XY.vbs CamBam
sub main

dim move_x as double
dim move_y as double

move_x = val(inputbox("Move X","0"))
move_y = val(inputbox("Move Y","0"))

if view.SelectedEntities.Length > 0 then


for each ent as Entity in view.SelectedEntities
ent.Transform.Translate(move_x,move_y,0)
next ent

view.RefreshView()

end if

end sub

Note: You can UNDO all the transformation with the transformation matrix windows, or fix it by "Apply Transformation"

++
David

« Last Edit: January 05, 2014, 00:29:44 am by dh42 »

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8969
    • View Profile
Re: Numerical XY Move
« Reply #1 on: October 30, 2012, 23:47:10 pm »
David,
NICE!  Thanks.

I added the following line:

for each ent as Entity in view.SelectedEntities
   ent.Transform.Translate(move_x,move_y,0)
   ent.ApplyTransformation()
next ent

It does something, but not what I expected.

So, how do I do in VB what "Edit/Transform/Apply Transformations" does?

Thanks,
Lloyd
« Last Edit: October 30, 2012, 23:51:01 pm by lloydsp »
"Pyro for Fun and Profit for More Than Fifty Years"

Offline kvom

  • CNC Jedi
  • *****
  • Posts: 1612
    • View Profile
Re: Numerical XY Move
« Reply #2 on: October 31, 2012, 11:55:18 am »
Perhaps a separate loop after all moves have completed?

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8969
    • View Profile
Re: Numerical XY Move
« Reply #3 on: October 31, 2012, 12:08:36 pm »
I think that particular method is NOT the same as the menu item.  I think it's the same as the one inside the transform matrix window, and that one doesn't behave the same as the main menu item.

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: Numerical XY Move
« Reply #4 on: October 31, 2012, 12:54:56 pm »
Hello LLoyd,

 ;D same for me ; I try the ent.ApplyTransformation but I get double move if I do that.

I also don't find how to redraw the corners marks that stay at the old position (version N rc2) I must unselect then reselect the objects to get the corners at the right place.

++
David

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8969
    • View Profile
Re: Numerical XY Move
« Reply #5 on: October 31, 2012, 14:03:32 pm »
Andy,

It would sure be great if you could either flesh out that API definition for us, OR (for us non-competent programmers) depict a programmatic way (via the VB tools) we could explore the available classes, procedures, and methods.

I can muddle along, trying things until they work, but am not competent enough of a programmer in these "modern" languages to figure out what's not documented.

Any help would be appreciated.  More and more, I use scripts, and would love to begin writing my own.

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

Offline 10bulls

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 2163
  • Coding Jedi
    • View Profile
    • www.cambam.info
Re: Numerical XY Move
« Reply #6 on: November 01, 2012, 23:26:59 pm »
There is some (very rough) API documentation at...

http://www.cambam.info/doc/api/

It still needs a lot of work though.
Much of this is automatically generated so it can be rather sparse on details, but may help to show what classes, properties, methods etc are available.

Regarding ApplyTransformation():

This does not reset the Transform matrix to identity (no good reason why it doesn't  :-[ ).

The routine may also fail and return False.  This can happen if the transformation is not allowed for a particular entity.  For example trying to stretch a circle will fail (as it will no longer then be a circle),
whereas scaling and translating are allowed as these just change the radius and center point.

So the recommended way of using this method is...

Code: [Select]
if ent.ApplyTransformation() then
    ent.Transform = Matrix4x4F.Identity
end if

In this way, if the transformation is allowed, apply it and reset the transform matrix to identity,
otherwise leave the transform as is.


Online dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7408
    • View Profile
    • Cambam V1.0 French Doc
Re: Numerical XY Move
« Reply #7 on: November 02, 2012, 13:17:24 pm »
Hello Andy,

Thanks for this info  ;)

++
David

Offline billt

  • Droid
  • **
  • Posts: 90
    • View Profile
Re: Numerical XY Move
« Reply #8 on: November 23, 2012, 19:28:24 pm »
Here is the X,Y,Z move for selected items in Python, entered using a text box.
Not that useful in itself, but maybe helpful in larger scripts.

Cheers - BillT

Code: [Select]
# CamBam Python Script - Transform Selected Items

app.log("Hello");
from CamBam import *

p = Point3F()
MoveDist = ThisApplication.PromptForValue("Move Selected Macro","Enter a move distance in X,Y,Z format",p.GetType())

if (MoveDist==None):
    ThisApplication.MsgBox("Cancel Pressed")

if view.SelectedEntities.Length > 0:
    for ent in view.SelectedEntities:
        ent.Transform.Translate(MoveDist.X,MoveDist.Y,MoveDist.Z)
    ent.ApplyTransformation()
    ent.Transform = Matrix4x4F().Identity

Online dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7408
    • View Profile
    • Cambam V1.0 French Doc
Re: [script] Numerical XY Move + [plugin] NumMove
« Reply #9 on: January 05, 2014, 00:49:28 am »
Hello,

The numerical move revisited as a plugin with a Windows design.

It is in the Tools menu.

In the Step move section, the buttons (X-, X+, etc) allow to move the selected objects with the given step.

In the Num move section, the text boxes allow moving by entering a value (+ or - for direction) in the X,Y or Z boxes. (the validation is done by: Enter or Tab key, or clik in another text box, or Hide button)



The window is non modal, then you can let it open when you work.

Remain to do:

- UNDO managing
- Localization  ??? (I have not yet found the trick)

tested on XP pro, Win7 64 (CB 0.9.8 P beta 2, CB 0.9.8 N)

enjoy ;)

Edit: see in post below for the latest version

++
David
« Last Edit: February 08, 2014, 13:45:03 pm by dh42 »

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8969
    • View Profile
Re: [script] Numerical XY Move + [plugin] NumMove
« Reply #10 on: January 05, 2014, 01:18:16 am »
- Localization   ??? (I have not yet found the trick)

https://www.youtube.com/watch?v=lttkCbBVJFA

L
"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: [script] Numerical XY Move + [plugin] NumMove
« Reply #11 on: January 05, 2014, 20:06:35 pm »
Hello Lloyd,

Nothing to do, I can't get it to work   :'(

++
David

Offline pixelmaker

  • CNC Jedi
  • *****
  • Posts: 1967
    • View Profile
    • pixelmaker
Re: [script] Numerical XY Move + [plugin] NumMove
« Reply #12 on: January 05, 2014, 22:56:12 pm »
Hello,
the plugin works fine for me. Only the localisation…
With Rel 8P (beta-2) win7.

ralf

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8969
    • View Profile
Re: [script] Numerical XY Move + [plugin] NumMove
« Reply #13 on: January 06, 2014, 00:06:38 am »
It also works fine for me, but I think it should update the properties list (in the view) of the selected primitive after each move.  De-selecting and re-selecting will show the current position, but moving a 2D object in Z ends up creating 'invisible' moves, unless the properties list is updated with each change.

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

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8969
    • View Profile
Re: [script] Numerical XY Move + [plugin] NumMove
« Reply #14 on: January 06, 2014, 02:19:46 am »
Also, David, the File's "changed" property is not set after a move occurs.

If you accidentally close the file without saving, those changes will not stick, unless you make other changes afterwards by other means.

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