SketchUp crashing on me with this code...why?
-
Hi, here is part of a test I am doing to see if I can get Animatex Plugin to animate multiple faces but SketchUp keep crashing on me. Any particular reason why this happening so I can fix it?...thanks!
If you don't know what Animatex is here is a link.... http://sketchucation.com/forums/viewtopic.php?f=323&t=52238
One quick note is the def push_frame(dialog,data) is being updated couple frames a second by the web dialog.
def push_frame(dialog,data) params = query_to_hash(data) ; # parse state information if @animate == true model = Sketchup.active_model ents = model.entities faces = [] ents.each do |e| if e.is_a? Sketchup;;Face faces << e end end faces.each do |e| mat = e.material pt_array = [] pt_array[0] = Geom;;Point3d.new(@speed_x,@speed_y,0) pt_array[1] = Geom;;Point3d.new(0,0,0) on_front = true e.position_material mat, pt_array, on_front end end endAny help will be welcome!

-
I don't see how I can reproduce anything from this code. Got a complete case for testing?
Sidenote:
You indentation appear inconsistent. I'd recommend you keep it consistent with something like 2 or 4 space indentation. Makes it easier to read and debug.
if @animate == truethis doesn't need to be so verbose, You can do justif @animateents = model.entitiesis that really the context you want to change? Notents = model.active_entitiesin case the user opens a group/component. Maybe your crash is related to modifications in the wrong context?faces = [] ents.each do |e| if e.is_a? Sketchup;;Face faces << e end endThis is be simplified, and made faster by:
faces = ents.grep(Sketchup;;Face) -
Hi,
There is an attachment with a more complete code but it is still a test code...for example the @speed_x is not increasing in number yet.
Note: I am using Notepad++ and for indenting space I use tab but for some reason when I copy & paste code from there to forum it looks like that.
Again thanks thomthom!
-
What are
@speed_xand@speed_y- if these aren't 'numbers' it'll cause issues.
Perhaps trap at the code's start up with something like
@speed_x = 0 unless @speed_x @speed_y = 0 unless @speed_y
etc...Also you should trap that the two points used in the positioning-points' array are
!=- with something like this...
return nil if @speed_x == 0 && @speed_y==0 ### because then pts_array[0]==pts_array[1] pt_array = [Geom::Point3d.new(@speed_x ,@speed_y, 0), Geom::Point3d.new(0, 0, 0)] on_front = true
Note that you do not need to set the positioning-points' array etc multiple times, because it is always the same - do it outside of the 'faces' loop. Unless you intend to increment @speed_x etc inside the loop, then you need to put it in the loop...Also, also you are re-positioning every face's material, but if a face's material is the default-material [
nil] it'll probably throw a wobbler ??
Try something like this near the start of the 'faces' loop...
next unless mat = e.material
to skip over any faces that have no material... -
Yea, as TIG says, check the values of your code. Output the values and add traps to ensure you are using valid data from start to end.
-
#position_material is quite brittle and will die if you give it anything but clean parameters.
If memory serves, it will explode with either zero-area or degenerate geometry.
Adam
-
Thanks everyone now SketchUp is not crashing!

Here is that bit of code again revised...
@speed_x = 0 unless @speed_x @speed_y = 0 unless @speed_y def push_frame(dialog,data) params = query_to_hash(data) ; # parse state information if @animate model = Sketchup.active_model ents = model.active_entities faces = ents.grep(Sketchup;;Face) faces.each do |e| next unless mat = e.material mat = e.material return nil if @speed_x == 0 && @speed_y==0 ### because then pts_array[0]==pts_array[1] pt_array = [Geom;;Point3d.new(@speed_x ,@speed_y, 0), Geom;;Point3d.new(0, 0, 0)] on_front = true e.position_material mat, pt_array, on_front end end endAgain thanks everyone!

-
Hi,
Thank you guys so much could not do it without you guys!...Here is the latest update for Animatex; http://sketchucation.com/forums/viewtopic.php?f=323&t=52238
There is no scrambler for code so you guys can take a peek and will be grateful if you tell me any inefficiency in code so I can keep learning...cheers!

New Web Dialog::

Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement