• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Draw vs. Import Component

Scheduled Pinned Locked Moved Developers' Forum
3 Posts 2 Posters 868 Views 2 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    medeek
    last edited by 15 Mar 2017, 15:14

    I'm trying to determine if its easier to write a module that draws an anchor bolt (L-bolt with square washer and nut) or just bring in the component (pre-drawn). I've never brought in a component before so something I need to explore further. The other thing I feel is key is to make sure any of these minor components are modeled in such as way as to remain fairly lightweight within the model.

    Are there any caveats with bringing in components via the API that I should be aware of?

    Nathaniel P. Wilkerson PE
    Medeek Engineering Inc
    design.medeek.com

    1 Reply Last reply Reply Quote 0
    • M Offline
      medeek
      last edited by 19 Mar 2017, 04:48

      So I've loaded three components (sketchup files) from my components folder, a bolt, washer and nut and now I want to combine them all into one component, any hints?

      Nathaniel P. Wilkerson PE
      Medeek Engineering Inc
      design.medeek.com

      1 Reply Last reply Reply Quote 0
      • T Offline
        TIG Moderator
        last edited by 19 Mar 2017, 13:16

        You could have the three parts assembled into another SKP in your folder and then load that - bringing in the assembly and the three parts.
        However, if you want to add a new component into the model then use something like:

        model = Sketchup.active_model
        ### set up names of parts
        bolt = "MyBolt"
        washer = "MyWasher"
        nut = "MyNut"
        ### here I'm assuming they are already loaded [OR add then now]...
        ### get a reference to each from the name...
        defn_bolt = model.definitions[bolt]
        defn_washer = model.definitions[washer]
        defn_nut = model.definitions[nut]
        ### now combine them - add new empty definition
        name = "MyAssembly"
        path = Filejoin(path_to_folder, name+".skp")
        defn = model.definitions.add(path)
        name = defn.name ### in case name is preexisting, and it's now "MyAssembly#1"
        ### establish a suitable transformation of each component part - here I'll just call it 'tr_bolt' etc
        ### because the tr is within the definition's entities, center parts on the ORIGIN
        ### and move the nut/washer along the Z as needed
        ### a good idea would be to have the component parts with their insertion points
        ### at their ORIGINS and the bolt shaft facing down in the Z etc ?
        defn.entities.add_instance(defn_bolt, tr_bolt)
        defn.entities.add_instance(defn_washer, tr_washer)
        defn.entities.add_instance(defn_nut, tr_nut)
        ### you place the assembly 'defn' the same way, with another suitable transformation...
        some_entitites_collection.add_instance(defn, tr_defn)
        
        

        TIG

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        1 / 1
        • First post
          1/3
          Last post
        Buy SketchPlus
        Buy SUbD
        Buy WrapR
        Buy eBook
        Buy Modelur
        Buy Vertex Tools
        Buy SketchCuisine
        Buy FormFonts

        Advertisement