SketchUp / api-issue-tracker

Public issue tracker for the SketchUp and LayOut's APIs
https://developer.sketchup.com/
38 stars 10 forks source link

Connect point freely in space without having it shown as disconnected #400

Open Eneroth3 opened 4 years ago

Eneroth3 commented 4 years ago

In the LayOut Ruby API you can utilize the ConnectionPoint to connect a label or dimension to a point in a SketchUp model inside of a viewport, and have it stay connected when the viewport or its camera is moved.

However, if you set up the ConnectionPoint to connect to only a Point3d, without providing a PID, it will be shown as unconnected in LayOut with the sinister red background. Sometimes you don't want to connect to an entity (e.g. a vertex) but just a point in space.

I think the red styling should only be applied if the ConnectionPoint has a PID that couldn't be found in the model, not if the PID is nil.

# Some point in SketchUp model space.
su_point = Geom::Point3d.new(1.m, 2.m, 0)

# Locate some SketchUp file to test on.
su_path = UI.openpanel("Locate some SketchUp file")

# Set save location for test LO document.
lo_path = UI.savepanel("Save", File.dirname(su_path), "test.layout")

doc = Layout::Document.new
bounds = Geom::Bounds2d.new(1, 1, 3, 3)
viewport = Layout::SketchUpModel.new(su_path, bounds)
doc.add_entity(viewport, doc.layers.active, doc.pages.first)

# Note: No PID is passed. We only want to connect to a Point3d.
conenction_point = Layout::ConnectionPoint.new(viewport, su_point)
lo_point = viewport.model_to_paper_point(su_point)

label = Layout::Label.new(
  "Some Point3d",
  Layout::Label::LEADER_LINE_TYPE_SINGLE_SEGMENT,
  lo_point,
  lo_point.offset([20.mm, 20.mm]),
  Layout::FormattedText::ANCHOR_TYPE_TOP_LEFT
)

doc.add_entity(label, doc.layers.active, doc.pages.first)
label.connect(conenction_point)

doc.save(lo_path)
UI.openURL(lo_path) # (May only work on Windows)

ezgif-6-c94dee3fd4d9

thomthom commented 4 years ago

@ackarkka - thoughts on this?

kengey commented 4 years ago

This would be helpful for one of my clients too. In one project i need to add dimensions to the boundingbox.

Eneroth3 commented 4 years ago

The boundingbox is a good use case! Mine is a little more obscure as you might think the point should be on a vertex, but for Eneroth Viewport Resizer it is important the point stays in space even if any such vertex is moved.