SketchUcation Plugin Store

 

 

Deleting duplicate components

Deleting duplicate components

Postby sabre » Fri Nov 28, 2008 5:32 pm

Hi
I am try to find a way to locate duplicate component instances and then deleting all but 1 instance by just using ruby.
The defintion of duplicate is where two or more of the same component definition have the exactly the same origin.
Thanks for any suggestions.
sabre
 
Posts: 3
Joined: Mon Nov 24, 2008 3:51 pm
Location: Windsor, UK
Name: Neil Mitchell

Re: Deleting duplicate components

Postby Matt666 » Fri Nov 28, 2008 5:38 pm

Hi Sabre, and welcome to this forum !
I think Com def has her proper origin... So how can you choose which comp instance will not be deleted ?
;)
The defintion of duplicate is where two or more of the same component definition have the exactly the same origin.

So you want to delete duplicate component definitions, right ? you want to make component definitions unique ? I don't understand... Sorry !
Frenglish at its best !
My scripts
Matt666
 
Posts: 829
Joined: Wed Dec 05, 2007 8:38 am
Location: 48.1184, -1.675
Name: Matt

Re: Deleting duplicate components

Postby sabre » Fri Nov 28, 2008 5:54 pm

As you noticed I am new to the forum (thanks for the welcome) and I am having difficulites the sketchup terminology.

I will try explaining the problem in another way:
The user selects several components and builds the first part of a frame. He then copies these components and pastes them to expand the framework. Sometimes he overlaps the existing components with the pasted copy hence he has the two of the same components sharing the same origin. In order to accurately price up the framework I need to remove the duplicate component as in real life I cannot put more than one component in the same place.
Hope that helps.
sabre
 
Posts: 3
Joined: Mon Nov 24, 2008 3:51 pm
Location: Windsor, UK
Name: Neil Mitchell

Re: Deleting duplicate components

Postby Didier Bur » Sat Nov 29, 2008 12:55 am

Hi,
So you want to remove all duplicate instances refering to the same component definition and that have the same transformation as well:

Code: Select all
def remove_instances_duplicates
defs=Sketchup.active_model.definitions
to_delete=[]
defs.each do |compo_def|
  next if compo_def.internal?
  instances=compo_def.instances
  instances2=instances
  instances2.each do |i2|
    keeping_instance=instances.shift
    instances.each do |instance|
      if instance != keeping_instance and instance.transformation.to_a == keeping_instance.transformation.to_a and instance.definition.insertion_point.transform(instance.transformation)==keeping_instance.definition.insertion_point.transform(keeping_instance.transformation)
        to_delete.push(instance)
        puts "Erasing duplicate instance of " + instance.definition.name
      end
    end
  end
end
to_delete.each { |inst| inst.erase! }
end
end


I'm not sure it works as is but it is near it...
Didier Bur (Bytes Farmer)
Ecole Nationale Supérieure d'Architecture de Nancy (F)
http://rld.crai.archi.fr/rubylibrarydepot/
User avatar
Didier Bur
 
Posts: 1238
Joined: Wed Nov 14, 2007 10:07 pm
Location: Nancy, France
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Deleting duplicate components

Postby sabre » Sat Nov 29, 2008 4:59 pm

Many thanks Didier.
You have saved me a lot of time :sketchstatic:
sabre
 
Posts: 3
Joined: Mon Nov 24, 2008 3:51 pm
Location: Windsor, UK
Name: Neil Mitchell

Re: Deleting duplicate components

Postby Gianfranco » Wed Jun 06, 2012 2:31 pm

Good day

I know this is an old thread but this seems to be exactly what I'm looking for. I would like to ask, how can I use the script that Didier posted?

Thanks.
Gianfranco
 
Posts: 1
Joined: Wed May 11, 2011 3:37 am

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago

Artisan Organic Toolset - a set of powerful organic modeling tools.

Premium Members get 20% discount!

Ad Machine
Robot
 
Posts: 2012


Return to Developers' Forum

cron

Who is online

Users browsing this forum: leminilab and 4 guests