Layout api style set_dimension_units

layoutapi

#1

Hello fellow developers. I’m currently exploring the Layout api and I’m having some troubles which I hope some of you might have encountered already.

I’m having troubles changing the dimension style to fractional inches. I looks like they just keep showing up as decimals.

# p1, p2, p1_3d, p2_3d and layout_su_model are given...
new_dimension = Layout::LinearDimension.new(p1, p2, 5.mm)
new_dimension.style.set_dimension_units(Layout::Style::FRACTIONAL_INCHES, 16) # attempt 1
document.add_entity(new_dimension, layout_su_model.layer_instance.definition, layout_su_model.page)
new_dimension.style.set_dimension_units(Layout::Style::FRACTIONAL_INCHES, 16) # attempt 2
p1_connection =  Layout::ConnectionPoint.new(layout_su_model, p1_3d)
p2_connection =  Layout::ConnectionPoint.new(layout_su_model, p2_3d)
new_dimension.connect(p1_connection, p2_connection)
new_dimension.style.set_dimension_units(Layout::Style::FRACTIONAL_INCHES, 16)  # attempt 3

Anyone tackled this already? I’m confident I must be overlooking something…


#2

Hi @kengey,

Sorry I didn’t see your post earlier!

The #style method actually returns a copy of the entity’s style attributes, rather than a direct reference. What you need to do is save the style to a variable, set the dimension units, then apply that style back to the original entity. It’s unintuitive and non-ideal, but was necessary due to the internal architecture.

Example:

new_dimension = Layout::LinearDimension.new(p1, p2, 5.mm)
style = new_dimension.style
style.set_dimension_units(Layout::Style::FRACTIONAL_INCHES, 16)
new_dimension.style = style

Hope that helps,
Adam


#3

Thanks Adam,

Kind regards,

Kenny