MoveToOrigin macro

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: MoveToOrigin macro

Post by keithsloan52 »

Same function ( Not by macro ) has been in workbench toSketch for some time https://github.com/KeithSloan/toSketch
Also has scale facility for imported STEP objects.
edwilliams16
Veteran
Posts: 3180
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: MoveToOrigin macro

Post by edwilliams16 »

keithsloan52 wrote: Fri Jul 02, 2021 9:05 am Same function ( Not by macro ) has been in workbench toSketch for some time https://github.com/KeithSloan/toSketch
Also has scale facility for imported STEP objects.
Never noticed that functionality - I've only ever used your toSketch capability.
It looks like your placement options differ from mine. People should check them both to see which better fits their particular need.

From your README:
**********
Reset Origin
When STEP files are imported into FreeCAD their Placements are all set to zero and the Shapes are all created accordingly. This means if you try and Rotate an object that has been imported into FreeCAD it does not rotate correctly.

Selecting an Object and clicking on the Reset Origin icon results in the following

A new PartFeaturePython object is created and stores a copy of the selected objects Shape.
The Objects Placement is set based on the Shapes Bounding box and drawn at the same position.
The Selected Object is removed
The display of the Object will not change, but the Placement will be updated and it can be correctly rotated.

For the new object

The Origin can be changed via the Object Type Parameter using the Parameter window between

min x/y/z
Center of Mass
Original ( as created by STEP import )
The parameter window shows readonly Bounding box info

The Origin type can be changed via the Objects Parameter Placement setting.

Apart from when the Origin Type is set to Original the Object should now rotate correctly

*******

From mine:

This macro translates the Placement of an object so that a selected location becomes its new origin. This can be useful when objects imported from other formats like STL or STEP are badly located for further processing by FreeCAD.

Copy the macro to your macro directory. (You can copy and paste in the macro editor and save). Select first, then run the macro. Cancellation is possible. The following selections are supported:

- Single Vertex - move to origin

- Single Line Segment - central point moved to the origin

- Single Circle or Circular Arc - center moved to origin

- Single Face - CG moved to origin

- Single Object - CG moved to the origin (supports Solid, Shell, Compound and CompSolid)

- Three Vertices - Center of the circle passing through the vertices moved to the origin (useful for tessellated circles)
User avatar
easyw-fc
Veteran
Posts: 3633
Joined: Thu Jul 09, 2015 9:34 am

Re: MoveToOrigin macro

Post by easyw-fc »

edwilliams16 wrote: Wed Jun 16, 2021 2:44 am From https://forum.freecadweb.org/viewtopic. ... 30#p510397

On importing stl, step and other files, objects are sometimes inconveniently located far from the origin. This Macro allow you designate a point in the object and change the object's placement so that it is translated to the origin.
There is a similar feature in Aligner of Manipulator WB... But not the "3 points center option", which is very nice! :D
Image
LHC
Posts: 321
Joined: Thu Sep 17, 2020 4:21 pm
Location: Canadian Coffee Shop

Re: MoveToOrigin macro

Post by LHC »

I've been fiddling with a rather large step assembly that, once I open it in FreeCad I end up with the entire assembly of shapes in a std_part container. WIthin that container are other Std_parts, along with shapes (blue box icons - don't know the right term here sorry) that are both inside and outside of the sub std_part containers.

I can happily click on the shapes and fling them to the origin as expected, but moving the entire assembly is not possible. Is this the way the macro works ? I get an error that says 'Part.Compound' object has no attribute 'CenterOfMass'. I'm not a code guy so please forgive my ignorance if this is a silly question.

Thanks again for the handy macro !

Cheers,
Lewis
edwilliams16
Veteran
Posts: 3180
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: MoveToOrigin macro

Post by edwilliams16 »

Can you give me a stripped down version of your file and instructions on what you are trying to move? I covered at least one case of compound objects - but apparently not all.
LHC
Posts: 321
Joined: Thu Sep 17, 2020 4:21 pm
Location: Canadian Coffee Shop

Re: MoveToOrigin macro

Post by LHC »

edwilliams16 wrote: Fri Jul 02, 2021 10:53 pm Can you give me a stripped down version of your file and instructions on what you are trying to move? I covered at least one case of compound objects - but apparently not all.
Looks like it's too large to attach. I may be able to shove it on my dropbox account and then PM you a link. Standby....
LHC
Posts: 321
Joined: Thu Sep 17, 2020 4:21 pm
Location: Canadian Coffee Shop

Re: MoveToOrigin macro

Post by LHC »

LHC wrote: Fri Jul 02, 2021 11:31 pm
edwilliams16 wrote: Fri Jul 02, 2021 10:53 pm Can you give me a stripped down version of your file and instructions on what you are trying to move? I covered at least one case of compound objects - but apparently not all.
Looks like it's too large to attach. I may be able to shove it on my dropbox account and then PM you a link. Standby....
ok - I think I just PM'd you the dropbox link. What I am trying to do is simply move the assembly so that the origin is about the center of the object - mainly for experimentation. This is the original step file and what I did was just open it from within FC after starting FC. You will note that the assembly comes in in a weird orientation (the top is the left side). I have been fussing with the draft workbench and did finally figure out how to rotate it around the various axes to get it oriented properly!
LHC
Posts: 321
Joined: Thu Sep 17, 2020 4:21 pm
Location: Canadian Coffee Shop

Re: MoveToOrigin macro

Post by LHC »

Back again -

Don't know why I PM'd you the link to the dropbox - sometimes I don't think things through - lol. Here's the link in case anyone else wants to have a peek. Can't guarantee how long the file will last here though - my "free" dropbox account is almost full !

Cheers,
Lewis


https://www.dropbox.com/s/vy3quroub7655 ... l.stp?dl=0
edwilliams16
Veteran
Posts: 3180
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: MoveToOrigin macro

Post by edwilliams16 »

I see the issue. I had only considered the nesting of compound objects one level deep. To move the entire object's CG to the origin, I need to compute the position of the CG recursively, so the nesting can be arbitrarily deep. Interesting exercise...
LHC
Posts: 321
Joined: Thu Sep 17, 2020 4:21 pm
Location: Canadian Coffee Shop

Re: MoveToOrigin macro

Post by LHC »

edwilliams16 wrote: Sat Jul 03, 2021 12:11 am I see the issue. I had only considered the nesting of compound objects one level deep. To move the entire object's CG to the origin, I need to compute the position of the CG recursively, so the nesting can be arbitrarily deep. Interesting exercise...
Glad I could provide you with a challenge ! :lol:
Post Reply