Is is possible to create construction points in the C API?

Is is possible to create construction points in the C API?

If not, what is the most efficient way to create them in the Ruby API?

Creating them one at a time with entities.add_cpoint is very slow.

EntitiesBuilder does not appear to support construction points.

AFAIK, the “Live” C API is still read-only.

However, you could make sure the model is saved, then close it (ie, by starting a new empty model.)
Open the model file with the C API and add your guide points.
Then save it with C API, release it and then reopen with the Ruby API.

Did you wrap the batch creation in a undo operation with the disable UI switch true ?

model.start_operation("Add Guidepoints", true)
  ents = model.active_entities
  points.each { |point| ents.add_cpoint(point) }
model.commit_operation

In the above example, the points array would be calculated outside and before the creation loop.

I’m seeing a couple of microseconds per cpoint added. What kind of speed are your looking for?

model = Sketchup.active_model
ents = model.active_entities

count = 1_000_000
t = Time.now

model.start_operation('add cpoints', true)
  count.times { | i | 
    ents.add_cpoint([i,i,i])
  }
model.commit_operation

dt = Time.now - t
puts "#{count} cpoints added"
puts "\u0394t = #{ dt } seconds"
puts "#{ 1_000_000 * dt/count }us per cpoint"
nil

I had not set the disable_ui flag to true. Thanks for that tip.

1 Like