I am trying to create a linear dimension between centers of 2 circles using this API:
Sketchup.active_model.active_entities.add_dimension_linear([c1p, c1.entity.center], [c2p, c2.entity.center], vector)
where
c1.entity
and c2.entity
- are an Sketchup::ArcCurve
c1p
and c2p
are paths, that consist of [#<Sketchup::Group:..>, #<Sketchup::ArcCurve:..>]
This produces an error:
Error: #<TypeError: Invalid start instance path leaf entity. Must be Sketchup::ConstructionPoint, Sketchup::ConstructionLine, Sketchup::Vertex, or Sketchup::Edge.>
At the same time, if I create two circles in a group and make dimension using UI, like this:
And then, in Ruby code I get that dimension and check start/end attached points, I get the same path, i.e.
vo.entity
is DimensionLinearusing this code:
puts "#{vo.entity}"
print_se_points(vo.entity.start_attached_to)
print_se_points(vo.entity.end_attached_to)
...
def self.print_se_points(attached_to)
puts "attached_to path #{attached_to[0]}, point: #{attached_to[1]}"
puts "attached_to path leaf #{attached_to[0].leaf}, point: #{attached_to[1]}"
puts "path: #{attached_to[0].to_a}"
end
then I see this:
#<Sketchup::DimensionLinear:0x000002f6791e9890>
attached_to path #<Sketchup::InstancePath:0x000002f603243898>, point: (68.813824 mm, 20.726349 mm, 0 mm)
path: [#<Sketchup::Group:0x000002f6027c7108>, #<Sketchup::ArcCurve:0x000002f6760e7be8>]
attached_to path leaf #<Sketchup::ArcCurve:0x000002f6760e6f68>, point: (12 mm, 10.574009 mm, 0 mm)
attached_to path #<Sketchup::InstancePath:0x000002f603242150>, point: (12 mm, 34.574009 mm, 0 mm)
path: [#<Sketchup::Group:0x000002f6027c7108>, #<Sketchup::ArcCurve:0x000002f6760e6f68>]
attached_to path leaf #<Sketchup::ArcCurve:0x000002f6760e6f68>, point: (12 mm, 34.574009 mm, 0 mm)
i.e. leaf of a path is ArcCurve and there is no problem that it is attached to dimension start/end
This confuses me - what am I doing wrong?
What is a proper way to create a dimension programmatically to a center of circle?
Should I just create a cpoint
at the center of circle and add it as a leaf
in a path?
UPDATE:
Creating a cpoint actually did not work either:
c1p = c1.instance_path
np = c1p.to_a + [active_entities.add_cpoint(c1c)]
puts "#{np}"
c1p = Sketchup::InstancePath.new(np)
,
Gives an error on last line:
#<Sketchup::Group:...>, #<Sketchup::ArcCurve:...>, #<Sketchup::ConstructionPoint:...>
Error: #<ArgumentError: invalid instance path>
UPDATE 2
Figured the error with my approach with cpoint - instead of adding another element to a path, i should have replaced the last element, because the construction point is “within” a group, not “within” a circle. That was an improvement, but then I realized that this approach with cpoint will not work, since this cpoint is not related to a circle, and if circle is moved or resized - cpoint will stay where it is.. therefore I consider this approach wrong. That means i’m back where I started …