Efficient Code?


#1

As I’m working on the finishing touches to the Wall Plugin the six panel door geometry is something that keeps coming back to me.

This type of door geometry is fairly typical so eventually I would like to implement it however it does have a very high polygon count comparatively speaking. I’ve devised a fairly straightforward piece of code that generates a single panel, see below (cut and paste into the ruby console to view solid geometry):

group1 = Sketchup.active_model.entities.add_group
entities = group1.entities


new_face1 = entities.add_face [0,0,0], [500,0,0], [500,500,0], [0,500,0]
new_face1.pushpull 50

pt1 = [100,100,0]
pt2 = [200,100,0]
pt3 = [200,200,0]
pt4 = [100,200,0]

new_face2 = entities.add_face pt1, pt2, pt3, pt4

pt1 = [130,130,0]
pt2 = [170,130,0]
pt3 = [170,170,0]
pt4 = [130,170,0]

new_face2 = entities.add_face pt1, pt2, pt3, pt4

pt1 = [110,110,0]
pt2 = [190,110,0]
pt3 = [190,190,0]
pt4 = [110,190,0]

new_face2 = entities.add_face pt1, pt2, pt3, pt4

line1 = entities.add_line pt1, pt2
line2 = entities.add_line pt2, pt3
line3 = entities.add_line pt3, pt4
line4 = entities.add_line pt4, pt1

entities_to_transform = [line1, line2, line3, line4]

transform = Geom::Transformation.new([0,0,-5])
entities.transform_entities(transform, entities_to_transform)

However, my concern is that this block of code will need to be iterated twelve times in order to create the six panels on each side of the door, a lot of computation in order to create this door style. In that light, I would like for this code to be efficient and tight as possible, since the plugin is already quite heavy just in generating simple block geometry (ie. studs, casing, trim etc…).

Is there a more efficient way to write this block of code?


#2

(1) You can make one panel positive cavity group and copy transform instances where they need be, and then boolean subtract from the door ?

or …

(2) Make one nested group of the 3 panel faces, copy transform instances where they need be, explode them and transform the outer “ring” face for each in turn.

In general reusable code goes in a method.


#3

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.