• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

Centering objects

rhumbaflappy

Administrator
Staff member
Resource contributor
Messages
6,525
Country
us-wisconsin
In sketchup, objects are not ordinarily centered. There are some tools to align the object to the Origin point ( 0,0,0 )... but those tools align to vertical center of the object instead of the center of the base of the object.

Here's a simple ruby plugin that will move an object, component or group to the Origin, but keeps the base flat to the ground.

Code:
require 'sketchup.rb'

def center_group_bottom
	my_model = Sketchup.active_model
	my_selection = my_model.selection
	my_component = my_selection[0]
	if my_selection.length == 1
		if my_component.typename == "Group" || my_component.typename == "ComponentInstance"
			bb = my_component.bounds
			cpoint = bb.center
			lowpoint = bb.corner(0)
			cpoint.z = lowpoint.z
			vector = cpoint.vector_to [0,0,0]
			t = Geom::Transformation.translation vector
			my_component.transform! t
		else
			UI.messagebox "Select a single group or component"
		end
	else
		UI.messagebox "Select a single group or component"
	end
end 

if( !$MyAddonLoaded )
    UI.menu("Plugins").add_item("Center Group Bottom") { center_group_bottom }
    MyAddonLoaded = true
end


Dick
 

Attachments

Thanks. Will check this one out. Seems like it would be useful. How do you find Ruby as a programming language?

scott s.
.
 
Hi Scott.

This is actually my first voyage into ruby. But it seems to be pretty decent as an interpreted language. I just used notepad, and used several other sources of scripts to make this.

I vaguely remember it was hinted that ruby might be needed for FS11.. which never materialized.

Dick
 
Actually Dick, that was Lua, which now Pete Dawson has adopted. ;)
 
Hi Bill.

Right you are. It was Lua.

+++++++++++++++++++

The above plugin needs to have a selection turned into a Group or Component. It then uses the center of the selection bounds, for the center point's x and y value. The z value is derived from the lower-left bounds corner... the bb.corner(0).

The group is the transformed ( moved ) to the origin point [0,0,0]

I think it's odd I never have found this type of centering ( so that the base is at origin ) in the plugins I've looked at. It's a pretty simple concept, and FS objects generally need the base at the centerpoint for objects.

I'm sure the code isn't foolproof.

It does center multiple objects grouped together to their center as well.

Dick
 
Hi Dick:

Many thanks for your generous contribution of a much-needed plug-in for centering objects "on-ground"; I anticipate this should prove very helpful to further work with importing models to FS via ModelConverterX ! :wizard:


I just had a chance to test the current functionality of this interesting Ruby script using the default project template in Sketchup 8, which places a 2D planar rotate-to-camera female object in the default NE "on-ground" quadrant workspace.

I ran this script on that default project template by first selecting the 2D planar rotate-to-camera female object.

IIUC, the screenies below show that the current "centering process" for this script still appears (slightly) 'offset' from the baseline center of the object's "bounding box". :scratchch


As a well-intended, but naive "non-programmer", I'm wondering if there might be an additional attribute or function in the Sketchup Ruby API that is used to derive the (precise) midpoint of the bounding box base of a "Entity", "Group" or "Component" (or the 'pivot point' of a 2D planar rotate-to-camera object) ? :eek:


IMHO, being able to determine this could also prove helpful to eventual derivation of Reference Point coordinates for XML placement output etc. when 1 (or multiple !) model(s) "Geo-located" in Sketchup... get imported into FS via ModelConverterX.


Possibly this info might prove to be of interest ? :confused:


http://groups.google.com/group/sketchup-plugins-dev/web/Ruby-BoundingBox.html

"Bounding boxes are only large enough to exactly bound the entities within your model, group, or component."

"center

The center method is used to retrieve the Point3d object at the center of the bounding box.
Syntax

point = boundingbox.center

Return Value

point – the Point3d at the center of the bounding box if successful

Example
"

Code:
# There will not be any size to your bounding box until you add at least two points prior to calling model.bounds

boundbox = model.bounds
center = boundbox.center

UI.messagebox center

http://groups.google.com/group/sketchup-plugins-dev/web/Ruby-BoundingBox.html



AFAIK, "Point3d object at the center of the bounding box" might be used to derive this coordinate ?


http://code.google.com/p/skx/wiki/BoundingBox



Hmmm... Sometimes I wish I were a programmer so I could better understand things like this: :eek:

http://code.google.com/apis/sketchup/docs/ourdoc/boundingbox.html


http://code.google.com/apis/sketchup/docs/ourdoc/point3d.html


It would be great to also be able to identify an entire "Entity" and/or a "Selected" part of an Entity in Sketchup, so that this script could be further enhanced to allow centering the current model 'under construction'... even if it is not (yet) "Grouped" or copied into a "Component". :idea:

IIUC, this might require that we first ensure our object "Entity" definition is complete... by doing this from the Sketchup workspace: :twocents:

1.) Triple-click to 'select' the entire object being working on
2.) Right-click (context menu appears)
3.) Right-click context menu > Intersect Face > With Model (intersects all objects with model on Layer "0")



Perhaps this is a discussion of the process I'm trying to describe for such a scripting option ?

Working with selection - ungrouped or within a group

http://forums.sketchucation.com/viewtopic.php?f=180&t=1696



PS: As a followup on the announcement made here:

http://www.fsdeveloper.com/forum/showthread.php?t=63380


...A search at http://www.flightsim.com/file.php?cm=SEARCH on "LFSN Nancy" as keywords reveals that we have another notable expert here at FSDeveloper with an interest in both FS and Sketchup Ruby scripting; hopefully he might be receptive to sharing some insights with us here as he has so graciously done in various other forum communities ? :wave:


I'll be excited to see how this promising plug-in develops further ! :)

GaryGB
 

Attachments

  • Center_Group_Bottom_Front View.JPG
    Center_Group_Bottom_Front View.JPG
    90.5 KB · Views: 662
  • Center_Group_Bottom_ISO View.JPG
    Center_Group_Bottom_ISO View.JPG
    93.4 KB · Views: 769
Last edited:
Hi Gary.

The code:

bb = my_component.bounds
cpoint = bb.center
lowpoint = bb.corner(0)
cpoint.z = lowpoint.z


bb.center is what the API gives as the center of the Group or Component bounding box. I then only adjust the height of the cpoint. There isn't any further adjustment we could make.

That "person" object is already made into a component. If you 'explode' it and remake the component or group, it will make a proper box, and center it correctly..

Dick
 
Last edited:
Ah, I see.

So then in light of what appears to be present limitations on precision implemented via the Sketchup Ruby API, may I ask: if we make customized versions of "Components" used as "primitives" and utilize them in a "Geo-located" Sketchup project scene, can we somehow still achieve a precise derivation of the base midpoint geographic coordinates for prospective future use via ModelConverterX for XML placement (which references that objects geographic location of the base midpoint in Sketchup from the ex: *.KMZ file)... without first "exploding" our models ? :confused:


I'd be grateful as well for your clarification on how one might best achieve greater precision in computation of the central axis position or bounding box 'base' midpoint, when "centering" individual objects / models using Ruby scripting code such as in your "Center_Group_Bottom" plug-in above, in preparation for export to ModelConverterX.


[EDITED]

I must confess I'm still baffled as to whether Ruby code might still be able to further calculate this more precisely by taking into consideration the current Sketchup project 'granularity' of fractional precision in the units of measurement setting; possibly one might compute the distance between the 2 ends (corners) of an "Entity" 'base line'... and get a midpoint from that instead ? :eek:

IIRC, fractional precision in the units of measurement is set in Sketchup via:

Sketchup Menu > Window > Model Info > Units


Again, please forgive a non-programmer's curiosity, but what about using "BoundingBox.width"... to derive a midpoint from that ?

http://code.google.com/apis/sketchup/docs/ourdoc/boundingbox.html#width

[END_EDIT]



Thanks for any additional explanation you might provide on feasibility for possible use of Sketchup with this plug-in to achieve some of the ideas I've alluded to above. :)

GaryGB
 
Last edited:
Hi Gary.

The above code does use the group or component bounding box. I don't know the precision level, as the API doesn't discuss that.

Dick
 
Hi Dick:

Thanks for your replies to my inquiries on this centering issue. :)


I probably should have tested this first with one of the Todd Burch plug-ins I discussed in a prior thread here in the Sketchup forum: :eek:


http://www.fsdeveloper.com/forum/showthread.php?t=70243


FYI: If I do not first "Explode" the 'person' component object above, then immediately "re-Group", when I use either Todd Burch's "MoveToOriginAndCenter" plug-in or your "Center_Group_Bottom" plug-in, I get the same results: IMPROPER positioning of that object off-center from the vertical axis of the Sketchup 3D world axes. :eek:


However, as you so kindly suggested, if I do first "Explode" the 'selected' object(s), then immediately "re-Group", when I use either Todd Burch's "MoveToOriginAndCenter" plug-in or your "Center_Group_Bottom" plug-in, I get the same results: PROPER <...and precise ! :p > positioning of that object ON the vertical axis of the Sketchup 3D world axes. :wizard:

Many thanks for your clarification of that extra needed step. :teacher:


Of course, now I'm wondering whether / how one might incorporate that extra step into one's Ruby script (to first "Explode" a 'selected' object, then immediately "re-Group") ...as a precaution to ensure that one ends up with a properly centered object regardless of whether 'selected' object(s) is/are a pre-existing Component, and whether 'selected' object(s) is/are a Grouped or un-Grouped "Entity" ! :D


PS: The screenies below show that your "Center_Group_Bottom" plug-in does work properly if the 'person' component object is first "Exploded" < aka: Blowed Up REAL GOOD ! >... then immediately 're-Grouped' prior to running the Ruby script. ;)


GaryGB
 

Attachments

  • Exploded_Regrouped_Center_Group_Bottom_Front View.JPG
    Exploded_Regrouped_Center_Group_Bottom_Front View.JPG
    94.5 KB · Views: 653
  • Exploded_Regrouped_Center_Group_Bottom_ISO View.JPG
    Exploded_Regrouped_Center_Group_Bottom_ISO View.JPG
    93.8 KB · Views: 678
Last edited:
Hi, well, then this "centering issue" could have something to do with the fact that when I modified a fsx model in Sketchup, (which was a ship), this appeared el little "descentered" in relation to his wake :confused:. when I put this boat in fsx. interesting :cool:
 
Hi, well, then this "centering issue" could have something to do with the fact that when I modified a fsx model in Sketchup, (which was a ship), this appeared a little "un-centered" in relation to its wake :confused: when I put that boat into fsx. interesting :cool:

Possibly so; but see these threads regarding how one can assign "offset" position for display of a wake 'effect' relative to a ship / boat MDL datum point: ;)

http://www.fsdeveloper.com/forum/showthread.php?t=8108&highlight=wake+effect+offset

http://www.fsdeveloper.com/forum/showthread.php?t=16361&highlight=wake+effect+offset


Hope this helps ! :)

GaryGB
 
Last edited:
Thanks GaryGb, very interesting post, anyway this post give me a clue of what could happen with the ship and "its" wake, but I think other ships haven't had this problem, and I appreciate the corrections :D, really, I think anyone could learn a lot with this method, but I think you would have a lot of work :o
 
Indeed, there's many scenery objects in FS which are not "centered" on their vertical axis in the 3D world; some also have an offset for associated 'effects'. ;)


Thankfully we have tools like "Center_Group_Bottom", "Attached Object Editor" and "Transform Object > Rotate" in MCX to help us set things as we prefer ! :)


PS: See Arno's informative tutorial "ModelConverterX - Add effect to object" video at: :idea:

http://www.youtube.com/watch?v=KaXb8A-9p2Y


GaryGB
 
Last edited:
Hi Scott.

This is actually my first voyage into ruby. But it seems to be pretty decent as an interpreted language. I just used notepad, and used several other sources of scripts to make this.

I vaguely remember it was hinted that ruby might be needed for FS11.. which never materialized.

Dick

Catching up

Thanks. I've played around some in the Ruby console, but don't have enough scripting experience to compare to, say, Python which seems to have a lot of support.

scott s.
.
 
Back
Top