ArcCurve start and end points in global coordinate system

Hi,
I’m working on an architectural project and i’m using the same SketchUp model for the wiring. I know some people advise against this but the pain of updating two models seems worse than the problems of doing it all in SketchUp. Anyway, it all seems fine but I’m trying to automate some task with Rubi Api to do things like name my components. That all works great. But I would also like to determine which components a cable (always drawn as an ArcCurve) is connecting. This way I can make the Ids given to the components be reflected in the names given to the cables. So radiator TRV cable “R-A1-7” (Radiator, Block A, floor 1, Id=7) will be given the name “TC-A1-7”. So the 7 matches.

My code finds the cables and the components but I’m struggling to find the end points of the ArcCurve in the global coordinate system as well as the centre of the bounding box of the components.

What I want is a function that given an ArcCurve, or a Group with a single ArcCurve in it will answer the end points positions in the world. Also the same for a ComponentInstance, but answering its bounds.centre, also in the world coordinate system.

current I check every componentInstance (that’s been identified as a relevant component) like this:
componentInstance.bounds.center.distance(location)
passing in location from each end of my curve
arcCurve.vertices[0].position
and
arcCurve.vertices[-1].position

but the points are all over the place.

Is there an existing example project that does something vaguely similar someone could point me towards?

Thanks!

Euan

For any Curve (or subclass ArcCurve) start point, in the parent’s local coordinates …

def curve_start_point(curve)
  curve.first_edge.start.position
end

For any Curve (or subclass ArcCurve) end point, in the parent’s local coordinates …

def curve_end_point(curve)
  curve.last_edge.end.position
end

Assuming that “child” is a group in the top level model entities context, and “point” is a curve end point in that groups’s child coordinates, … to convert to world (model) coordinates …

def model_coordinates(point, child)
  point.transform(child.transformation)
end

See:

If the component instances are also within the model’s top level entities then their bounds corners should be expressed in model coordinates.

Hi Dan,
thanks for your reply.
If child is not at the top level, would it work for me to have something like this:

def model_coordinates(point, child)
point.transform(child.transformation)
parent = child.parent
while !parent.nil?
  point.transform(child.transformation)
  parent = parent.parent
end
end

really appreciate your help.
thanks,
Euan

Be carefull. The SketchUp core has a weird thing to do with coordinates. If you are within an editing context (ie, you’ve double clicked to enter a group,) the API methods return values in world coordinates.

So you’ll want to be at the top level outside all nesting levels when you run your naming utility.

model.close_active until model.entities == model.active_entities

See also:

No this will not work. Mainly because (ignoring the coding errors) … because #parent returns the owner of the geometric entities collection (ie, a definition or the model) and not an instance or group that has a transformation. (FYI, a group is a special component instance and so also has a component definition.)

If you’ve multi-nested things you will need to know the InstancePath to the particular cable or component instance.
The only API method that can give you this is Sketchup::Model#active_path meaning the target must be open for edit.

So it’d make it easier on yourself if you use a known container say for the Cabling and/or target instances.