Hej Thom,
Then it sounds like I have to switch to Sketchup 2014
Hej Thom,
Then it sounds like I have to switch to Sketchup 2014
Hi!
This one might be though, since most of you are US-Guys. But if you come from an ancient country like mine you have special characters like æøå.
And that appears to be a problem if you want to save a file with a name containing letters like æ, ø or å.
Do you have any ideas how to fix that?
-Rasmus
@sdmitch said:
Interesting! In the Ruby Console, type ENV and press Enter. Does that show anything? How about ENV['HOME'].
When I type ENV in Ruby Console:
"PUBLIC"=>"C:\\Users\\Public", "SESSIONNAME"=>"Console", "SystemDrive"=>"C:", "SystemRoot"=>"C:\\windows", "TEMP"=>"C:\\Users\\RASMUS~1\\AppData\\Local\\Temp", "TMP"=>"C:\\Users\\RASMUS~1\\AppData\\Local\\Temp", "USERDOMAIN"=>"RasmusVS-pc-Pc", "USERNAME"=>"RasmusVS-pc", "USERPROFILE"=>"C:\\Users\\RasmusVS-pc", "windir"=>"C:\\windows", "windows_tracing_flags"=>"3", "windows_tracing_logfile"=>"C:\\BVTBin\\Tests\\installpackage\\csilogfile.log"}
As you can see there is no ENV['Home'] variable.
I would use ENV['USERPROFILE']
instead.
I use Sketchup 8.0.15158 - Maybe thats why...?
@sdmitch said:
ENV['Home'] is your user account, ie C:/Users/Rasmus. In this case filename would equal 'C:/Users/Rasmus/Desktop/mysketchup.skp'
Great, thanks! I figured it out with your help
model = Sketchup.active_model status = model.save('d:/rs_model.skp')
But ENV['Home'] dont seems to work.
I have tried:
test = ENV['Home'] puts(test.to_s)
and nothing shows...
Hi!
How do I save the model to a file?
I have tried the following but it don't seems to work.
` model = Sketchup.active_model
filename = File.join(ENV['Home'], 'Desktop', 'mysketchup.skp')
status = model.save(filename)`
And can anyone tell me what ENV['Home'] is?
And if I want to save to a diffenrent location than desktop will it then be, eg:
'c:\my\project\folder'?
Thanks in advance
-Rasmus
Great, this solved my problem! Thank you very much Dan!
@dan rathbun said:
Problem is you are already within the
EntitiesObserver
instance attached to the Group'sEntities
collection !
You must be careful not to set up an infinite loop !Changing the model from within observer callbacks can crash SketchUp !
Ok, for now I will abandon this approach.
Please consider this example:
mod = Sketchup.active_model
ent = mod.entities
i = 0
h= {}
ent.each do |o|
attr = o.get_attribute "rsdict","area"
if attr
h[i] = {'structid' => 201, 'area' => attr}
i += 1;
end
end
Here it scans the entire model for groups with the attribute_dictionary "rsdict", "area".
Lets say it finds a group with the "rsdict" attribute. Inside the group there are a face
with an attribute attached to it.
Is it possible to scan that group for all its entities? Something like this:
mod = Sketchup.active_model
ent = mod.entities
i = 0
h= {}
ent.each do |o|
attr = o.get_attribute "rsdict","area"
if attr
o.entites.each do |u|
yv_face_area = u.get_attribute "rsdict", "yv_face_area"
if yv_face_area
h[i] = {'structid' => 201, 'area' => yv_face_area} i += 1;
end
end
end
Thank you Dan, but I try to explain it again:
My goal is to set an attribute to the group when a face has been modified. As you can see in the code below Im able to set an attribute to the face inside the group, but not the group containing the face. Do you have any ideas how to work around this problem?
If the group is called rsgroup:
yv_face_height = rsgroup.entities.add_face pts[0..3]
rsgroup.set_attribute "rsdict","area", yv_area
yv_face_height.set_attribute "rsdict", "yv_face_area", yv_area
class MyEntitiesObserver < Sketchup;;EntitiesObserver
def onElementModified(entities, entity)
attr_area = entity.get_attribute "rsdict", "yv_face_area"
if attr_area
yv_area_new = i.area.to_m.to_m
entity.set_attribute "rsdict", "yv_face_area", yv_area_new
#(HERE I WOULD LIKE TO SET THE ATTRIBUTE OF THE GROUP-something like;)
entity.parent.set_attribute "rsdict","area", yv_area_new
end #attr_area
end #onElementModified_end
end #class
Hi,
Im working with EntitiesObserver
, and having trouble understanding the method
def onElementModified(entities, entity)
.
For instance, if you add an EntitiesObserver
to a group consisting of a face, the EntitiesObserver
will fire when you doubleclick the group and alter the face.
(Eg. moving one of the edges so that the area of the face will increase.) In that case it will fire 3 times because 2 edges will get longer, and the face itself will increase in size.
If you have set an attribute to the face it is then possible to retrieve the value by saying
myFaceAttr = entity.get_attribute "rsdict", "face_attr"
, and you can set a new value with set_attribute "rsdict", "face_attr", "new value"
.
But now my question is: what if I have an attribute set to the group, and I want to alter that when the EntitiesObserver
fires. Is it possible to see name of the parent of the entity? (The face is a child of the group)
Hope the question is understandable...
-Rasmus
Ok. hopefully there is a solution. If I find one I will return...