I want to create an extension where you open up a box and can select several trim styles or make your own. After loading the trim into the model, the extension will use followme to build it along selected edges.
In order to do this in SketchUp, you need to program a UI::HtmlDialog
object.
This will mean you will need to know Ruby, JavaScript, HTML and CSS (as well as the SketchUp API.)
There are many topics where others have already asked about HTML dialogs in this Ruby subcategory (where I’ve moved your topic, BTW.) Please use the magnifying glass search menu (upper right) when inside a category to search only that category. For programming, using class or method names is a good way to filter searches.
You can begin your plugin with the fancy web dialog replaced with a simple UI.inputbox
, that has a basic dropdown picklist of trim names. Later on, when it is working, you can replace the inputbox at your leisure.
The user would use SketchUp to draw the profile according to a help file instructions you provide and then make it a component, saving it to it’s own .skp
file. Your dialog would have an “Add profile…” command, which you’d implement UI.openpanel
so they can choose the component file giving it’s pathstring. You then use this pathstring to copy the component into your plugin’s profile library (probably in a special directory for custom profiles.) Once in your library you can display it’s thumbnail image in your web dialog so it can be chosen like the other stock profiles.
See the following methods …
Sketchup::DefinitionList#[]
- getting a existing definition by nameSketchup::DefinitionList#load
- loading a definition into the model’s definition collectionSketchup::Entities#add_group
- adding a group into an entities collectionSketchup::Entities#add_instance
- adding a component instance into an entities collectionGeom::Transformation
class to locate the group and profile instances
You’ll likely insert a profile instance then explode the profile instance (otherwise you’ll be modifying the definition.)
There are numerous posts already in both the Ruby category, and in the main SketchUp modeling categories on the pitfalls of followme. (Please you forum search as described earlier.)
You’re command will either expect the edges to be prepicked …
… or, you’ll need to activate a custom picking tool …
You’ve chosen a very complex project. So as not to become overwhelmed, break it down into smaller subprojects.
Before you attempt coding a followme, learn the tricks of doing it manually.
There are many examples of complete extensions, and of snippets as said in your other topic thread. There are many examples and snippets over at the long-lived SketchUcation forums.
~
About those extensions…I download them but the code is question marks and dashes…what should I do?
prompts=["Trim Height:", "Trim Width:", "Quarter Round:"]
defaults=[5.0,0.5,"No"]
list=["","","Yes|No"]
input=UI.inputbox prompts,defaults,list,"Trim Information"
a,b=input
ent=Sketchup.active_model.active_entities
end
There are two difficulties that come to mind. Extensions are normally packaged as .rbz files, which are actually renamed from .zip. You can’t simply view a compressed zip archive, you must unzip it and then look at the contents. Secondly, if the extension has been scrambled to protect intellectual property, you can’t view the Ruby code at all.
Start with small steps…
Learn how to create a face from set of points [perhaps imported from a CSV file ]- there are several non-encrypted scripts available.
Once you have that make the face and then learn how to transform its vertices to make that face’s normal parallel to a certain vector***.
Next you have a path get the vector*** of its first [start] edge - there’s some ‘trickery’ to to get the ‘end’ nearest the face…
Now you have the face and a path of edges to use with the API’s follow me code…
One parting point, the cw/ccw direction of the face’s vertices affects its orientation.
So you need to compare the face.normal to the vector got from the path’s first edge, and reverse the face if the final extrusion would be ‘inside out’ - easily established by so testing…
PS: make your parts and extrusion inside a group.entities context…