sketchucation logo sketchucation
    • Login
    1. Home
    2. njeremy2
    3. Posts
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    🔌 Smart Spline | Fluid way to handle splines for furniture design and complex structures. Download
    N
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 7
    • Posts 58
    • Groups 1

    Posts

    Recent Best Controversial
    • RE: Explode group, retrive all entities and recreate group

      I'm a student in computer science into a small business. My boss use Sketchup Pro and he asks me do make a plugin which count all entities in a design.

      It tells you how many components and groups are they in the design.
      We have already use that plugin but there are some bugs.
      If we don't put a name into the component, the plugin display nothing (that's why I ask you how to copy definition name into name).
      The other problem is : when you have a group, into that group you can have some components and the plugin didn't count these components, that's why I ask how to get into a group without exploding this.

      Voila 😄

      posted in Developers' Forum
      N
      njeremy2
    • RE: Explode group, retrive all entities and recreate group

      I try this code

      Maybe I don't know how to use that...

      What I need to do is to retrive all entities, then I select what I need to do if it's a group or if it's a component.

      If it's a component, I copy the DefinitionName into Name.
      If it's a group, I need to copy DefinitionName into Name for all components into the group

      The problem : I don't know how get into the group then copy the definition without exploding this

      code for copying definition into name

      if	element.definition.name[0] != 0 && element.name == ""
      element.name = "#{element.definition.name}"
      end # end if
      
      posted in Developers' Forum
      N
      njeremy2
    • RE: Explode group, retrive all entities and recreate group

      lol !
      wowowowo!
      I have 2 bigs difficulties :
      The first one is to understand correctly the English 😄 (I can manage that)
      The second one is to understand Ruby and SketchUp language subtleties ---> AAAHHHH 🤢

      Thanks

      posted in Developers' Forum
      N
      njeremy2
    • RE: Explode group, retrive all entities and recreate group

      Hmmm, I will meditate on this.
      It's a new notion for me, let me a little time to understand it

      now, I try the code

      [edit]
      WOOOOOW TIG !

      I don't have time enough to read all answer and you wrote that !! 😲

      posted in Developers' Forum
      N
      njeremy2
    • RE: Explode group, retrive all entities and recreate group

      How do you use "next unless" ?

      I search it into "Automatic_SketchUp.pdf", I found nothing

      posted in Developers' Forum
      N
      njeremy2
    • RE: Explode group, retrive all entities and recreate group

      Hmmm,
      It seems to be good, I will try to execute it

      I have a group which contains components. And with this component, I need to copy definition name into name (the copy works thanks to you. Thank to you TIG!!).
      So, to access to this component for doing modification, I tought I need to explode it.

      You just tell me it's possible to make modification without exploding groups.

      I will try this and I tell you if it's work or not. 😉

      posted in Developers' Forum
      N
      njeremy2
    • Explode group, retrive all entities and recreate group

      Hello everyone, I need you 😄

      I have this code :

      def DefToName
      @tab = []
      @tabgroup = []

      #retrive all entities
      Sketchup.active_model.entities.each do |entities|
      # put all entities into TAB called @tab
      @tab << entities

      	@tab.each do |element|
      	%(#00FF00)[# If the entity is a group, explode the group]
      		if element.is_a?(Sketchup::Group)
      		element.explode
      

      %(#FF0000)[# I need to retrives all entities from this group HERE,
      # If I put this code : "Sketchup.active_model.entities.each do |entities|" it takes all entities, and I just need only entities from the group
      # after explosion, I'll do actions on this entities (ComponentInstance or Group)
      # After actions, I need to recreate the group with all the entities from this group.
      # For recreate the group, I have to pick the name of group before explosion into @name for example,
      # Then, when I need to recreate the group, I put that name into the new name of group
      ]

      		end %(#00FF00)[#is_a?]
      	end %(#00FF00)[#tab.each]
      

      end #|entities|
      end # end DefToName

      Thank you 😄

      posted in Developers' Forum
      N
      njeremy2
    • RE: ComponentInstance name and Group name

      Hi everyone !

      I have found how to correct my code !! 😄

      It's was just an error of algorithm.

      At first time I had this condition :

      chose.name[0] != 95
      

      And I would like to have this :

      chose.name[0] != 95 || chose.definition.name[0] != 95
      

      but it doesn't work ...

      The solution is :

      chose.name[0] != 95 && chose.definition.name[0] != 95
      

      As I said, I'm beginning !

      Thanks to all! especially TIG

      posted in Developers' Forum
      N
      njeremy2
    • RE: ComponentInstance name and Group name

      @tig said:

      If you have a reference to the instance you can easily get its definition, from which you can easily get the name of that.
      I don't see where the difficulty is ?
      You just need to add some extra tests to your code of instances... in more than one place - my example was how to get the initial name to use...

      Yeah but i'm beginning ! so I have to learn what is exactly the difference between componentdefinition and componentinstance, it's hard for me !

      Every document is written in english, I have to translate some words and then i have to understand each specific vocabulary of sketchup ... (in less than 1 week !)

      I have to go easily on that !! 😄

      I will continue monday because I have no tools to continue at home

      thx TIG! 👍

      posted in Developers' Forum
      N
      njeremy2
    • RE: ComponentInstance name and Group name

      it didn"t work ...

      I will try something else. Another way

      I practice in how I get the name of definition through a table, and then I will associate that with my code

      posted in Developers' Forum
      N
      njeremy2
    • RE: ComponentInstance name and Group name

      I'm not hiding anything, I just forgot to sent you! ^^

      
      =begin
      author ; njeremy2
      # This software is provided as an example of using the Ruby interface
      # to SketchUp.
      
      # Permission to use, copy, modify, and distribute this software for 
      # any purpose and without fee is hereby granted, provided that the above
      # copyright notice appear in all copies.
      
      # THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
      # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
      # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
      =end
      
      Sketchup;;require 'sketchup'
      
      # Conversion pouces² vers m²
      def p2m2(superficie)
      	superficie/1550.0
      end
      
      #Conversion pouces3 vers m3
      def p2m3(volume)
      	volume/61023.7440947323
      end
      
      #Ajoute à la classe float une méthode permettant d'arrondir avec 2 chiffres après la virgule
      class Float
      	def round2
      		i=((self*100).round.to_f)/100
      		return i
      	end
      end
      
      #Permet d'exporter dans un fichier html le nom et la quantité des Composants, Matières, Groupe (+volume). L'utilisateur peut choisir d'exporter les données qu'il souhaite
      #L'utilisateur peut choisir d'ignorer certains composants ou groupes (comme les végétaux) en les préfixant d'un _
      class Export
      	#Initialisation
      	def initialize
      		UI.messagebox "Variables chargés 1"
      		@model = Sketchup.active_model
      		@entities = @model.entities
      		@materials = @model.materials
      		UI.messagebox "Variables chargés 2"
      		
      		
      		
      		
      		
      		
      		
      		@tabGroupes = []
      		@tabMateriaux = []
      		@tabComposants = []
      		@nomFichier = @model.path
      		@cheminScript= '/ATI/scripts/exportS.html'
      		4.times do
      			@nomFichier.chop!
      		end
      		@nomFichier += "_ExportS.html"
      		input()
      	end
      	
      	#Demande de renseignements à l'utilisateur
      	def input
      		prompts = ["Nom et chemin du fichier à exporter", 
      			   "Composants",
      			   "Matières en m²",
      			   "Groupes"
      			   ]
      			   # "Volume des Groupes" supprimé du formulaire
      		defs = ["#{@nomFichier}", "Oui", "Oui", "Oui", "Non"] # "non" supprimé pour volume des groupes
      		list = ["", "Oui|Non", "Oui|Non", "Oui|Non"]		
      		resultats = inputbox(prompts, defs, list, "Paramétrer l'export")
      		@nomFichier = resultats[0].to_s
      		@composants = resultats[1].to_s
      		@matiere = resultats[2].to_s
      		@groupe = resultats[3].to_s
      		# @volume = resultats[4].to_s
      	end
      	
      	#Exporte le nombre et le nom de chaque chose dans un fichier html défini par l'utilisateur
      	def exporter
      		listerElements()
      
      		#Créer le fichier
      		fichierExport = File.new("#{@nomFichier.to_s}", "w")
      		
      		#Ecrire les informations dedans
      		#Formulaire html
      		fichierExport.write "<html>"
      			fichierExport.write "<form method=\"GET\" action=\""
      			fichierExport.write @cheminScript.to_s
      			fichierExport.write "\">"
      			
      			#Titre en haut a gauche de l'écran (titre du fichier de sauvegarde)
      			fichierExport.write "<head>"
      				fichierExport.write "Projet ; <b>"+(@model.title).to_s+"</b><br />"
      				fichierExport.write "<input type=\"hidden\" value=\"#{@model.title}\" name=\"nomModele\">"
      			fichierExport.write "</head>"
      			
      			#Tableau
      			fichierExport.write "<table border=\"1\" align=\"CENTER\">"
      			
      			#Affichage des têtes de colonnes
      			fichierExport.write "<tr><td></td><td bgcolor=\"#99FF00\"><b>Nom</b></td><td bgcolor=\"#99FF00\"><b>Quantité ou surface</b></td></tr>"
      			
      			#Composants
      			fichierExport.write "<tr><td bgcolor=\"#7CF8F8\"><b>Composants</b></td></tr>"
      			i = 0
      			@tabComposants.each do |composants|
      				fichierExport.write "<tr><td></td>"
      				fichierExport.write "<td>"
      				if (composants[0].name == "")
      					fichierExport.write (composants[0].definition.name).to_s
      					fichierExport.write "<input type=\"hidden\" value=\"#{composants[0].definition.name}\" name=\"nomComposant#{i}\">"
      					else
      					fichierExport.write (composants[0].name).to_s
      					fichierExport.write "<input type=\"hidden\" value=\"#{composants[0].name}\" name=\"nomComposant#{i}\">"
      				end #endif
      				fichierExport.write "</td>"
      				# fichierExport.write "<td>" ## Ajout colonne début
      				# fichierExport.write (composants[0].definition.name).to_s
      				# fichierExport.write "<input type=\"hidden\" value=\"#{composants[0].definition.name}\" name=\"nomComposant#{i}\">"
      				# fichierExport.write "</td>" ## Ajout d'une colonne fin
      				fichierExport.write "<td>"
      				fichierExport.write composants[1].to_s
      				fichierExport.write "<input type=\"hidden\" value=\"#{composants[1].to_s}\" name=\"nbComposant#{i}\">"
      				fichierExport.write "</td>"
      				fichierExport.write "</tr>"
      				i += 1
      			end			
      			
      			#Groupes
      			fichierExport.write "<tr><td bgcolor=\"#7CF8F8\"><b>Groupes</b></td></tr>"
      			i = 0
      			@tabGroupes.each do |groupe|
      				fichierExport.write "<tr><td></td>"
      				fichierExport.write "<td>"
      				fichierExport.write (groupe[0].name).to_s
      				fichierExport.write "<input type=\"hidden\" value=\"#{(groupe[0].name).to_s}\" name=\"nomGroupe#{i}\">"
      				fichierExport.write "</td>"
      				# fichierExport.write "<td>" ## Ajout colonne début
      				
      				
      				
      				# fichierExport.write "</td>" ## Ajout d'une colonne fin
      				fichierExport.write "<td>"
      				fichierExport.write groupe[1].to_s
      				fichierExport.write "<input type=\"hidden\" value=\"#{groupe[1].to_s}\" name=\"nbGroupe#{i}\">"
      				fichierExport.write "</td>"
      				# #Si on gère les volumes et que le groupe n'est pas plat, on affiche son volume
      				# if @volume == "Oui" && p2m3(groupe[0].volume) > 0
      					# fichierExport.write "<td>"
      					# fichierExport.write (p2m3(groupe[0].volume).round2).to_s
      					# fichierExport.write " m3"
      					# fichierExport.write "<input type=\"hidden\" value=\"#{(p2m3(groupe[0].volume).round2).to_s}\" name=\"volumeGroupe#{i}\">"
      					# fichierExport.write "</td>"
      				# end
      				fichierExport.write "</tr>"
      				i += 1
      			end
      			
      			if @matiere == "Oui"
      				#tout péter
      				nb = eclater(@entities)
      				
      				#Calculer la surface des matériaux
      				calculerSurfaceMateriau(@entities)
      				
      				#On purge le tableau des matériaux qui n'ont pas de surface (cas qui peut arriver s'il y a des végétaux et que l'utilisateur à préfixé le nom
      				#avec un _
      				@tabMateriaux = purgerTab(@tabMateriaux)				
      				
      				#tout reconstruire
      				annuler(nb)
      			end
      			
      			#Matières
      			fichierExport.write "<tr><td bgcolor=\"#7CF8F8\"><b>Matières</b></td></tr>"
      			i = 0
      			@tabMateriaux.each do |matiere|
      				fichierExport.write "<tr><td></td>"
      				fichierExport.write "<td>"
      				fichierExport.write (matiere[0].display_name).to_s
      				fichierExport.write "<input type=\"hidden\" value=\"#{matiere[0].display_name.to_s}\" name=\"nomMat#{i}\">"
      				fichierExport.write "</td>"
      				# fichierExport.write "<td>" ## Ajout colonne début
      				
      				
      				
      				# fichierExport.write "</td>" ## Ajout d'une colonne fin
      				fichierExport.write "<td>"
      				fichierExport.write (matiere[1].round2).to_s
      				fichierExport.write " m²"
      				fichierExport.write "<input type=\"hidden\" value=\"#{matiere[1].round2.to_s}\" name=\"surfaceMat#{i}\">"
      				fichierExport.write "</td>"
      				fichierExport.write "</tr>"
      				i += 1
      			end	
      		
      			#Nombre de groupes, de composants et de matériau
      			fichierExport.write "<input type=\"hidden\" value=\"#{@tabGroupes.length}\" name=\"nbGroupes\">"
      			fichierExport.write "<input type=\"hidden\" value=\"#{@tabComposants.length}\" name=\"nbCompos\">"
      			fichierExport.write "<input type=\"hidden\" value=\"#{@tabMateriaux.length}\" name=\"nbMats\">"
      		
      		#Fermeture des balises et bouton d'export au format csv
      			fichierExport.write "</table>"
      			fichierExport.write "<br />"
      			fichierExport.write "<input type=\"submit\" value=\"Exporter au format csv\">"
      			fichierExport.write "</form>"
      		fichierExport.write "</html>"
      		
      		#Fermer le fichier
      		fichierExport.close
      		
      		#Message pour l'utilisateur
      		UI.openURL @nomFichier	
      		
      	end	
      	
      	#Crée un tableau avec tout les éléments comptés par type
      	def listerElements	
      		#On parcours tout les éléments et on les comptes
      		@entities.each do |groupes|
      			if groupes.typename == "Group" && @groupe == "Oui"
      				compter(groupes, 1)
      			elsif groupes.typename == "ComponentInstance" && @composants == "Oui"
      				compter(groupes, 2)
      			end
      		end
      		if @matiere == "Oui"
      			#On purge les matériaux inutilisés
      			@materials.purge_unused
      			@materials.each do |materiau|
      				compter(materiau, 3)
      			end	
      		end
      	end
      	
      	#Regarde l'objet passé en paramètre et en tient le compte dans le tableau correspondant
      	def compter(chose, type)
      		#Init
      		trouve = false
      		
      		#On récupère le tableau qu'on l'on va devoir traiter
      		tab = @tabGroupes if type == 1
      		tab = @tabComposants if type == 2
      		tab = @tabMateriaux if type == 3
      		#x représente le nombre d'occurences, si c'est un matériau on l'initialise à 0 car on contera la surface totale plus tard.
      		#si c'est un groupe ou composant on l'initialise à 1 pour pouvoir compter
      		if type > 2
      			x = 0
      		else
      			x = 1
      		end
      		
      		
      		#On regarde si l'élément existe déja, si oui on incrémente la case du tableau qui compte, si non on ajoute une nouvelle case
      		tab.each do |element|
      			if chose.name == element[0].name
      				element[1] += x
      				trouve = true
      			end
      		end
      		
      		if trouve == false
      			tab.push([chose, x])
      		end
      		
      		#on rend le tableau que l'on à traité
      		@tabGroupes = tab if type == 1
      		@tabComposants = tab if type == 2
      		@tabMateriaux = tab if type == 3
      	end
      	
      	#Calcule la surface de chaque matériau
      	def calculerSurfaceMateriau(entities)
      		#Récupérer toutes les faces
      		tabFaces = []
      		entities.each do |element|
      			if element.typename == "Face"
      				tabFaces.push(element)
      			end
      		end
      		
      		#On regarde si la face possède un matériau, et si oui on calcule la surface
      		tabFaces.each do |face|
      			materiau = face.material
      			materiauBack = face.back_material
      			if materiau	|| materiauBack			
      				surface = p2m2(face.area)
      				@tabMateriaux.each do |materiauxEnregistres|
      					if materiau
      						if materiauxEnregistres[0].display_name == materiau.display_name
      							materiauxEnregistres[1] += surface
      						end
      					end
      					if materiauBack
      						if materiauxEnregistres[0].display_name == materiauBack.display_name
      							materiauxEnregistres[1] += surface
      						end
      					end
      				end
      			end
      		end
      	end
      
      	#Eclate tout les groupes et composants
      	def eclater(entities)
      		nb = 0
      		composantOuGroupe = true
      		#Tant qu'il reste un composant ou un groupe, on boucle en permanence pour tous les éclater. Dès qu'il n'y en a plus, on arrête		
      		while 1
      			trouve = false
      			if composantOuGroupe == false
      				break
      			end
      			# UI.messagebox "texte juste avant la boucle"
      			entities.each do |chose|
      				if chose.typename == "ComponentInstance" || chose.typename == "Group" 
      				# UI.messagebox "Texte juste apres qu'il vérifie si c'est un groupe ou si c'est un composant"
      					if chose.name[0] != 95	#On vérifie que la premiere lettre ne soit pas un _ (on compare les codes ascii), [0] designe la position du caractere a rechercher
      						chose.explode
      						nb += 1
      						trouve = true
      					end
      				end
      			end
      			if trouve == false
      				composantOuGroupe = false
      			end
      		end
      		return nb
      	end
      	
      	#Annule nb actions
      	def annuler(nb)
      		nb.times do
      			Sketchup.undo
      		end
      	end
      	
      	#Recoit un tableau de tableau et le vide des éléments uniques
      	def purgerTab(tab)
      		tabReturn = []
      		tab.each do |element|
      			if element[1] != 0
      				tabReturn.push(element)
      			end
      		end
      		return tabReturn
      	end
      end
      
      posted in Developers' Forum
      N
      njeremy2
    • RE: ComponentInstance name and Group name

      My plugin :

      http://img850.imageshack.us/img850/4889/99044371.png

      http://img844.imageshack.us/img844/2120/46271262.png

      http://img198.imageshack.us/img198/9208/98217431.png

      http://img59.imageshack.us/img59/1905/86462454.png

      http://img32.imageshack.us/img32/4237/71551261.png

      My group has a name : "GroupWood"
      2 same components : 1 with name "Bench1" and the 2nd without name.
      The plugin will retrive all informations and put that in table in HTML webpage.
      In component section, if the name of component is empty, the plugin retrive definition name. If it has a name, it takes the name.

      If I put "" before the name of the group or name of component, the plugin ignore the texture of them.
      But if I put "
      " before the definition name, it doesn't work. I would like to add this third condition my program.

      Someone can help me ? 😄

      http://img42.imageshack.us/img42/2721/36062394.png

      posted in Developers' Forum
      N
      njeremy2
    • RE: ComponentInstance name and Group name

      @thomthom said:

      I wrote a summary about instances and definitions in SketchUp: http://www.thomthom.net/thoughts/2012/02/definitions-and-instances-in-sketchup/
      Hope it might help.

      I already read it 😉 thanks you !

      posted in Developers' Forum
      N
      njeremy2
    • RE: ComponentInstance name and Group name

      @tig said:

      Instead of iterating entities to get all instances and then find their definitions, why not iterate the definitions list to get their instances ?

      I just beginning ruby for sketchup less than 7 days, I don't know anything... 😞

      I just modified the code from someone.
      Tomorrow, I will show you exactly what i'm trying to do.
      I don't have sketchup in that computer

      posted in Developers' Forum
      N
      njeremy2
    • RE: ComponentInstance name and Group name

      thx ! I'll try this tomorrow

      Hmmm let me explain, it's little bit difficult for me to explain that in English

      I want to create a plugin which count every components and groups in the design.
      With this plugin, you can calculate the texture you need for a group or component (Tomorrow, I will take screenshot to show you my work (but it's in French...)

      For example, I have a component called "Wood Table" (definition name) and you call it "Table 200x300"
      My plugin will count how many tables I have on design and how much texture of Wood I apply on all tables.
      If I don't the plugin calculate the texture (I hope you understand this sentence 😄 ), I have to put "_" (character n° 95 in ASCII TABLE) and the plugin ignore the Table. (ex: "Table 200x300 --> "_Table 200x300")
      But in my case, it only work for the name of groups and component, but I want to add the case for component-name. How should I do ?

      Thanks a lot to everyone ! 😉

      Jeremy

      posted in Developers' Forum
      N
      njeremy2
    • RE: ComponentInstance name and Group name

      this is my code :

      	#Explode all components and groups
      	def Explosion(entities)
      		nb = 0
      		componentOrGroup = true
      		#Stop until there is no group ou component left
      		while 1
      			found = false
      			if componentOrGroup == false
      				break
      			end
      			entities.each do |chose|
      				if chose.typename == "ComponentInstance" || chose.typename == "Group" || ????
      					if chose.name[0] != 95	#We check if the first character is "_" from ASCII table, if it's right we explode the group or component
      						chose.explode
      						nb += 1
      						found = true
      					end
      				end
      			end
      			if found == false
      				componentOrGroup = false
      			end
      		end
      		return nb
      	end
      
      posted in Developers' Forum
      N
      njeremy2
    • RE: ComponentInstance name and Group name

      I'm a beginner, it's my first week in Ruby developement

      I've just finish to read "Automatic_Sketchup.pdf" from http://www.autosketchup.com/ and it's really good !

      chose.typename == "ComponentInstance"
      chose.typename == "Group"
      

      The entire code already work, but I just want to add a third condition.

      I don't really know how to use it.

      if chose.typename == "ComponentInstance" || chose.typename == "Group" || [b]groupdefn[/b]
      
      
      posted in Developers' Forum
      N
      njeremy2
    • ComponentInstance name and Group name

      Hello, I'm new here and I'm from France.

      I have a problem in Ruby development.

      I need to retrieve 3 elements:
      chose.typename == "ComponentInstance" --> Name field from component info
      chose.typename == "Group" --> Name Field from group info
      And the third one, Definition name from compononent info.

      Someone can help me ? I hope you understand me 😄

      I put an image of my code to show you

      http://img29.imageshack.us/img29/4190/finalmi.jpg

      posted in Developers' Forum
      N
      njeremy2
    • 1
    • 2
    • 3
    • 3 / 3