But ComponentDefinition inherits from Drawingelement and this class has a layer method? I don't understand
Posts made by kat
-
RE: Component layer?
-
Component layer?
Hello,
I have a issue about the layername of a component that I really don't understand.
At the start of my program, new componentdefinitions are loaded from an external folder. Then I attach them to a layer with the following code:
constructionlayer = $model.layers.add "Construction" componentdef.layer = constructionlayer componentdef.entities.each{ |e| e.layer = constructionlayer }
When the component further is instanced in het model and asked for its layer with the following code snippet, it returns first "Construction" and then "Layer0". So the layer of the ComponentDEFINITION is initialized as "Construction", but the layer of the ComponentINSTANCE isn't.
selection[0].definition.layer.name selection[0].layer.name
When I then save the SU file, open it again and ask an other time for the component's layer with the same piece of code, I get first "Layer0" en secondly "Construction". I assume that the layer of the ComponentDEFINITION is now "Layer0" and the layer of the ComponentINSTANCE is "Construction".
How is this possible?
Does anyone know about a workarround for this problem?
After building the SU model, I make a selection of components based on layername, so it is important that this is correctly set in both situations.Thanks a lot for all help!
-
RE: Command icon
Yes exactly, that was my question, i didn't understand why i needed to add two different sizes of icons to the Command.
I think i did everything as explaned in the API docs, but i still won't display the icon. Are there any settings that i should check? Or something like .visible = true? -
Command icon
Hey,
I 'm working on a toolbar for my script, but the icon that i've asociated with the command won't appear on the button.
Does anyone see what i'm doing wrong?
This is my code snippet:$plugins = Sketchup.find_support_file "Plugins", "/" result = UI;;Command.new("Print results"){print_info} result.status_bar_text = "Print the resultfile" result.small_icon = File.join($plugins,"Icons","Result.png") toolbar = UI;;Toolbar.new("SuFiQuaD") toolbar = toolbar.add_item result toolbar.show
Does the image of the icon has to be exactly 16x16 or 24x24 pixels? Can i put the image file in the Plugins folder?
Why is there a difference between small and large icon?
thanks a lot for any help. -
RE: Resize inputbox
hmm, i did some Java programming before, but that was a long time ago...
-
Save panel when new SU file
Hey,
In a script I try to make a new SU file to save in the components folder and draw a text object into. Therefore I first have to know the path of the old SU file in order to be able to open it again after opening, drawing in, saving and closing the new SU component file.
I do this with an inputpanel so I can save the path the user has chosen, but when I then make a new SU file withSketchup.file_new
Sketchup automatically asks the user to save the current file and opens a second save panel again.
def make_skp() ss = Sketchup.active_model.selection skp = Sketchup.active_model.name # Name of the current SU model path1 = Sketchup.active_model.path # Path of the current SU model # Settings of the selected text object tekstlabel = ss[0] v = ss[0].vector name = ss[0].text l = ss[0].leader_type a = ss[0].arrow_type p = ss[0].point tekstlabel.erase! # Delete the text object UI.messagebox "Please save your SU file." path2 = UI.savepanel("Save as",path1,skp) # Check if path2 ends with skp p = path2.split(".") if p[1] != "skp" path2=path2+".skp" end Sketchup.active_model.close_active # Close the current SU model su = Sketchup.file_new # Make a new SU file for the text object path3= File.join($components, "Opbouw", name+".skp") su.active_model.save(path3) # Make a new text object with the same settings in the new file t = su.active_model.entities.add_text(name,[0,0,0]) t.vector = v t.leader_type = l t.arrow_type = a t.display_leader = true su.active_model.save(path3) # Save the new SU file su.active_model.close_active # Close the new SU file # Open the old SU file again Sketchup.open_file(path2) end
The code I wrote works perfectly, but does anyone has an idea of how to avoid this second savepanel witch is a little bit annoying to fill in all over again?
-
Resize inputbox
Hello,
I use a SU inputbox in my script with some predefined possibilities for the user.
for example:def dialog3() number_layers = 2 prompts3 = Array.new(number_layers) { |i| "Layer "+(i+=1).to_s} defaults3 = Array.new(number_layers) { |i| "--Select--"} list3 = [ "WFEX0001;Wall, external finishes - closing sub-element - blocks/stones - natural stone - breuksteen (09 cm) |WFEX0002;Wall, external finishes - closing sub-element - blocks/stones - concrete blocks - white (190x90x90) |WFEX0003;Wall, external finishes - closing sub-element - blocks/stones - concrete blocks - grey (190x90x90)", "THINS0001;Thermal insulation in cavity - blanket, batt - anorganic fiber - rock wool - hard (6 cm) |THINS0002;Thermal insulation in cavity - blanket, batt - anorganic fiber - rock wool - hard (10 cm) |THINS0003;Thermal insulation in cavity - blanket, batt - anorganic fiber - rock wool - hard (14 cm)"] d3 = UI.inputbox(prompts3,defaults3, list3, "Layers ") end
Because my list contains very long strings, SU automatically produces this ridiculously huge inputbox that won't even fit the screen. Does someone know how to resize it?
-
RE: Suface scaled component instances
Hey thanks, this last one was a very good tip.
I think what AdamB proposed is a very professional approach of the problem.
I 've tried it out in my code and it works fantastically.
Yet, it would be interesting to understand WHY this actually works,
does someone know a bit more about the matematical background of this vector based solution? -
RE: Faces area in a group ?
Hey thanks a lot AdamB for your super professional approach!
Finally found what I was looking for, now my code works fantasticly.I did some additional reading about the Frennet-Serret/TNB frame but I don't really understand everything.
If I get it wel, the normal(N) is perpendicular to the face, the tangent(T)'touches' the face and de binormal(B) is perpendicular to both normal and tangent. But then how do you know on which side of the face formed by N and T, is B? I don't get the
@unknownuser said:tangent = (normal * binormal)
multiplication. Isn't B supposed to be the cross product of N and T?
And why is gives
@unknownuser said:(xform * binormal).length * (xform * tangent).length
you the scale factor?
Could you give me some extra matematical information about this?
I would like to understand why this code works,thanks, kat
-
Suface scaled component instances
Hello,
I work on a script to get information about window and doors components placed in a SUmodel.
One of the things a need to know is the current surface of the window instance, even if a user has changed its original surface by scaling it etc. I tried with this piece of code:component.definition.entities.each { |subentity| if subentity.typename == "Face" surface = subentity.area.inch_to_m @surf = @opp + oppervlakte end }
But this gives me -off course- the original surface of the component definition.
I have been looking for a similar method in the SU api to get the entities of a component instance, but didn't find one.I suppose I should do something with the transformation matrix of the component instance, but I really don't know how to do so. How can you know with which matrices the transformation matrix has been multiplied, and in which order, to get the final matrix? And how can you see which transformations have been done?
For now, I wrote this methode to get by exploding the component and then undoing the operation.
def surface?(entity) #entity = a face in the SUmodel @surf = 0 i = 0 # counter entity.get_glued_instances.each{ |component| # Explode components to get its entities entities = component.explode i += 1 entities.each { |subentity| if subentity.typename == "Face" surface = subentity.area.inch_to_m @surf = @surf + surface end } } # Undo the operation i times i.times { Sketchup.undo } return @opp end
It works, but i don't think this kind of destructive operation is a good solution.
Does anyone have another idea of a way to approach this problem?
I don't have SUpro, so can't work with dynamic components.Or maybe someone has allready written a scipt that uses transformation matrices in this way?
thanks a lot,
greets, kat -
RE: Window components
yes, it works!
I made my windows in the SU components folder in the upright position,
should have done it in the horizontal plane...
thanks a lot tig!!! -
RE: Window components
Hey,
Thanks a lot for your help last time, I've changed my script a bit, but unfortunally, it still doesn't work.
The component doesn't cut a hole in the face it is placed into and it is not placed on the right layer.
I really can't see what is wrong. I am sending you the entire method I wrote to load the window components placed in the components folder into the SU model.def laad_componenten # Define correct path for the csv information file windowcomponents = File.join($components,"Ramen","*.csv") files = Dir.glob(windowcomponents) # String loaded components @loaded_comp = " " # Look for the windows files.each { |file| f = File.open(file,"r") f.each {|line| line.to_s @data = line.split(';').each { |string| string.strip} } name = @data[0].to_s # Define the path of the SU window path = File.join($components,"Ramen", name+".skp") # Load the component into the current model componentdef = Sketchup.active_model.definitions.load path # Attatch csv information to component using attributes componentdef.set_attribute "info", "naam", naam.to_s componentdef.set_attribute "info", "diktes", @data[1] componentdef.set_attribute "info", "U-waarde", @data[2] componentdef.set_attribute "info", "g-waarde", @data[3] componentdef.set_attribute "info", "kostprijs", @data[4] componentdef.visible = true componentdef.behavior.is2d = true componentdef.behavior.cuts_opening = true # Put component on the right layer windowlayer = $model.layers.at("Ramen") componentdef.layer = windowlayer # Name of loade component in string @loaded_comp = @loaded_comp+naam+" ;" f.close } end @loaded_comp.chop! UI.messagebox "All windows components loaded;"+@loaded_comp end
Hopefully you can help me
thanks -
Window components
Hello,
I'm working on a script to get information about the windows a user placed in his Sketchup model.
To do so, I'v made some window models and placed them into the 'Components' folder.
With a Ruby script, I attach the information about the windows by using attributes. Now, I also want my windows to cut a hole in the wall they are placed into, but this doesn't really work.
I've tried to change the behavior of the componentdefinition of my windows with this code:componentdef = Sketchup.active_model.definitions.load path componentdef.behavior.snapto = SnapTo_Vertical componentdef.behavior.cuts_opening = true
But when a user now places an instance of the window component in his model, nothing happens, the wall stays intact and no hole is cut out. I think the component isn't really glued to the face because when i ask all the faces in the model whether they have a component glued to with get_glued_instances, nil is returned.
Is my approach to simplistic? Or does anyone know what I am doing wrong?
Thanks a lot for any help