Efficient Code?

Efficient Code?

Postby medeek » Tue May 08, 2018 9:47 pm

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):


Code: Select all
  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?
0
Nathaniel P. Wilkerson PE
Medeek Engineering Inc
design.medeek.com
User avatar
medeek 
PluginStore Author
PluginStore Author
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 


 

Return to Developers' Forum

Who is online

Users browsing this forum: No registered users and 13 guests

Visit our sponsors: