CamBam

Resources => Scripts and Plugins => Topic started by: EddyCurrent on September 22, 2020, 20:18:02 pm

Title: In Place Resize plugin
Post by: EddyCurrent on September 22, 2020, 20:18:02 pm
As a result of this thread; https://cambamcnc.com/forum/index.php?topic=8720.msg69458#msg69458

I thought about a plugin to address some of the issues.
The plugin will resize all selected objects and will ensure the selected "Base point" stays in place following the resize.
It measures the current distance between two points then prompts the user for a final target distance, scale factor is calculated then the objects are scaled accordingly.

Ctrl + Z will Undo the resize if required.

Please download and install the plugin
then download the attached sample cb file and open it
now follow these instructions.

It's best to have "snap to grid" off, the plugin will automatically enable "snap to object" while it is working.

In this example we require the distance between points A and B to be 118mm

1. Select the objects, (circle and shape)
2. Edit->Transform->In Place Resize
3. "Select Base point (A)", this is a point on the objects that will remain in place following the resize
4. choose the centre of the small circle as "Base point"
5. "Select Reference point (B)", this is another point on the objects that is the required distance from Base point
6. Choose the right most tip of the object.
7. A form will appear showing the current length between Base point (A) and Reference point (B)
8. Type the required length into "Target Length" box, enter 118
9. click the OK button
10 the objects have been resized and the Base point has not moved
11. Use Tools->Measure to check the new distance between A and B

Obviously the Centroid of an object or objects can be selected as the "Base point"

Edit:

Version 2 attached, also works with bitmap entities.
Title: Re: In Place Resize plugin
Post by: dh42 on September 22, 2020, 20:47:47 pm
Hello

Very nice job and useful plugin ! thanks !!

I often thought to add something like this to the NumMove plugin as a new resize tab .... but I never did it ...  :-*

++
David
Title: Re: In Place Resize plugin
Post by: Bob La Londe on September 22, 2020, 22:15:29 pm
Resize with a selectable anchor point is standard in ViaCAD which would address most issues.  VC also allows the origin or overall center as one of the selectable points. 
Title: Re: In Place Resize plugin
Post by: EddyCurrent on September 24, 2020, 06:37:25 am
@David, Attached are the source project files for version 1.0.

If you want to incorporate it into your NumMove plugin that would be fine with me.
Title: Re: In Place Resize plugin
Post by: dh42 on September 24, 2020, 17:14:24 pm
Hello

thanks ;)

++
David
Title: Re: In Place Resize plugin
Post by: dh42 on June 03, 2021, 14:23:13 pm
Hello Eddy

I just tried to use this plugin to resize a Bitmap object, and it seems to have no effect with this object ...  ;)

Edit:
a workaround

https://www.screencast.com/t/4F5piK836o

++
David
Title: Re: In Place Resize plugin
Post by: EddyCurrent on June 03, 2021, 15:44:12 pm
David,

You are correct, I did not consider bitmaps at the time.
I like your alternative method and time permitting I might try to update the plugin.
Title: Re: In Place Resize plugin
Post by: EddyCurrent on June 04, 2021, 20:03:01 pm
David,

I see why it's not working with a bitmap.

The code goes like this;

Code: [Select]
// do resize with Params.basePoint staying in place
            foreach (Entity entity in view.SelectedEntities)
            {
                entity.Transform.Translate(-Params.basePoint.X, -Params.basePoint.Y, -Params.basePoint.Z);
                entity.Transform.Scale(Params.scaleFactor);
                entity.Transform.Translate(Params.basePoint.X, Params.basePoint.Y, Params.basePoint.Z);
                entity.ApplyTransformation();
                entity.Transform = Matrix4x4F.Identity;
           
                entity.Update();
                view.Selection.RefreshExtrema();
                CamBamUI.MainUI.ObjectProperties.Refresh();
            }

The problem is with line, entity.Transform = Matrix4x4F.Identity;

It seems to work for everything except a bitmap.
My intention was to do the required transforms then set that to "identity" to reset the matrix.

EDIT:

I knew the answer but forgot it  ???

It should say;

 if (entity.ApplyTransformation()) entity.Transform = Matrix4x4F.Identity;


Title: Re: In Place Resize plugin
Post by: dh42 on June 04, 2021, 20:35:11 pm
Hello

Yes, in manual mode, it seems that Edit/transform/apply transformation has no effect on a bitmap (the matrix is no recalculated), so I assume that when you "identity" it's equal to "reset" the matrix to his default state.

I guess that the bitmap object must be left "as is" after a transformation ... so the lines

entity.ApplyTransformation();
entity.Transform = Matrix4x4F.Identity;

must be skipped if the object is a bitmap object ..

.... maybe  ;D

++
David
Title: Re: In Place Resize plugin
Post by: EddyCurrent on June 04, 2021, 20:42:45 pm
David,

I think you are correct.

Even using, if (entity.ApplyTransformation()) entity.Transform = Matrix4x4F.Identity;

The bitmap transform matrix is still left "as is" rather than being set to "identity"

If it is set to "identity" it reverts back to it's original state.

Title: Re: In Place Resize plugin
Post by: EddyCurrent on June 04, 2021, 20:46:11 pm
Version 2 of the plugin attached to the first post in this thread.

It also works with bitmaps.
Title: Re: In Place Resize plugin
Post by: dh42 on June 04, 2021, 20:57:20 pm
Quote
Even using, if (entity.ApplyTransformation()) entity.Transform = Matrix4x4F.Identity;

Note sure, but I think that entity.ApplyTransformation() only return the state of the matrix (true if in modified state, false if the matrix is already in "identity" state), but this don't say if the object can be "identity" or not.

I searched for a CanIdentity() function (like the CanConvert() function) ... but can't find one.

Quote
Version 2 of the plugin attached to the first post in this thread.

Thanks !!  ;D

++
David
Title: Re: In Place Resize plugin
Post by: dh42 on June 04, 2021, 21:03:47 pm
Works well ! (but it is not translatable)  ;D

++
David
Title: Re: In Place Resize plugin
Post by: EddyCurrent on June 05, 2021, 09:37:35 am
David,

I have replaced the v2 file in the first post, please see if the translation works now.
Title: Re: In Place Resize plugin
Post by: dh42 on June 05, 2021, 19:10:47 pm
Hello

Ok for all, except for the Cancel button that is not translatable.

Also, there is a typo on the title (in place resuze)

(http://www.atelier-des-fougeres.fr/Cambam/Aide/Plugins/In%20Place%20Resize/UI_FR.png)

++
David
Title: Re: In Place Resize plugin
Post by: EddyCurrent on June 05, 2021, 21:02:16 pm
David,

Thank you for testing again.

Maybe I've got it right this time  :D

New version 2 attached to first post.

Title: Re: In Place Resize plugin
Post by: dh42 on June 05, 2021, 21:55:30 pm
Hello

Perfect ;)

thanks

++
David
Title: Re: In Place Resize plugin
Post by: Bubba on June 05, 2021, 22:22:23 pm
Thanks to both of you. Eddy for modifying the plugin, and David for testing it.
Title: Re: In Place Resize plugin
Post by: EddyCurrent on June 25, 2021, 21:39:34 pm
Bubba,

It's a pleasure for fine folk.
Title: Re: In Place Resize plugin
Post by: Garyhlucas on June 25, 2021, 23:42:45 pm
I am going to have to try this plugin. I am machining styrofoam for lost foam casting and I need to compensate for shrinkage of about 2% when casting aluminum. This should be useful.