• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

How do I change the code?

Scheduled Pinned Locked Moved Developers' Forum
3 Posts 2 Posters 561 Views 2 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    CEIT81729
    last edited by 4 Nov 2015, 09:54

    mod = Sketchup.active_model
    ent = mod.entities

    q = Sketchup.active_model.selection.add(
    Sketchup.active_model.definitions["aaa"].instances )

    a = Sketchup.active_model.selection.add(
    Sketchup.active_model.definitions["bbb"].instances )

    bb = Geom::BoundingBox.new.add(q.bounds.intersect(a.bounds))

    if bb.valid?
    puts "a"
    else
    puts "b"
    end

    It can't run...
    How do I change the code?

    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 4 Nov 2015, 11:06

      Seems like you want to find the intersections of instances.
      First remember that the instances might be in different entities contexts...
      Using the selection is not always going to work as you expect...
      Better to get a list of the definitions' instances

      as = mod.definitions["aaa"].instances
      bs = mod.definitions["bbb"].instances
      

      now iterate one list and check intersections in the other.

      hits = {} ### empty hash
      as.each{|a|
        es = a.parent.entities
        hits[a]=[]
        bs.each{|b|
          next unless es = b.parent.entities ### same context
          bb = a.bounds.intersect(b.bounds)
          hits[a] << b if bb && bb.valid?
        }
      }
      hits.each{|hit| puts "AAA #{hit[0]} intersects BBB #{hit[1]}" }
      
      

      TIG

      1 Reply Last reply Reply Quote 0
      • C Offline
        CEIT81729
        last edited by 4 Nov 2015, 12:07

        TO TIG:
        Thank you for your reply!
        If I want to get the component's dynamic attributes(lenx, leny...) by multiple components collision detection?
        and I will deduction of the overlapping area(multiple components) after...
        (1)multiple components collision detection
        (2)get the component's dynamic attributes(lenx, leny...)

        Thank you for your help!

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        1 / 1
        • First post
          1/3
          Last post
        Buy SketchPlus
        Buy SUbD
        Buy WrapR
        Buy eBook
        Buy Modelur
        Buy Vertex Tools
        Buy SketchCuisine
        Buy FormFonts

        Advertisement