api-issue-tracker icon indicating copy to clipboard operation
api-issue-tracker copied to clipboard

Layout::Document#add_entity Lacks Return (Layout::Entity)

Open 3dmod opened this issue 9 months ago • 0 comments

Layout::Document#add_entity does not have any return currently.

This is not the norm with adding entities in SketchUp. The norm is to return the entity added

Changing the return to the added entity will not break the current api because currently there is no return.

The current behavior makes running a method on the newly added entity cumbersome by having to select the added entity from the document entities.

For example if I want to add a locked entity then I need to do the following

doc = Layout::Document.open("path")
text  = Layout::FormattedText.new("Test", Geom::Point2d.new(1, 1), Layout::FormattedText::ANCHOR_TYPE_TOP_LEFT)
layer = doc.layers.first
page =  doc.pages.first
doc.add_entity( text, layer, page )
entity = 
	case
	when layer.shared?
		doc.shared_entities.to_a.last
	else
		page.nonshared_entities.to_a.last
	end
entity.locked = true

If the Layout::Document#add_entity returns the added entity then the code would look like this

doc = Layout::Document.open("path")
text  = Layout::FormattedText.new("Test", Geom::Point2d.new(1, 1), Layout::FormattedText::ANCHOR_TYPE_TOP_LEFT)
entity = doc.add_entity( text, doc.layers.first, doc.pages.first )
entity.locked = true

3dmod avatar May 03 '24 15:05 3dmod