Draw vs. Import Component

Draw vs. Import Component

Postby medeek » Wed Mar 15, 2017 4:14 pm

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

Re: Draw vs. Import Component

Postby medeek » Sun Mar 19, 2017 5:48 am

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

Re: Draw vs. Import Component

Postby TIG » Sun Mar 19, 2017 2:16 pm

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:
Code: Select all
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)
0
TIG
User avatar
TIG 
Global Moderator
 

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 7 guests

Visit our sponsors: