sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Create a group and manipulate add geom

    Scheduled Pinned Locked Moved Developers' Forum
    11 Posts 3 Posters 861 Views 3 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.
    • S Offline
      Skippy1974
      last edited by

      Hello,
      I m a newbee
      couple of weeks, I start to dev using the ruby API
      For my plugin create a projector and all the parametric pyrammid
      I have 2 problems

      • I m not able to do the same think as File/import a skp file. I have to create a new one using the folloing

      Sketchup.open_file "C:/ANTYCIP/Sketchup components/Projectors/ProjectionDesign_F12.skp"
      proj = Sketchup.active_model.entities.add_group


      someone has a idea please?

      • after my creation, I want to put every body un a group and manupilate the group (translation / rotation / scale
        I m not able to add some thing or everything in a group

      create group

      group1 = ent.add_group projection_surface.all_connected (bad fonction)
      group1.name = "pyramid"


      idea

      thanks a lot

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        model.definitions.load will let you import components.
        http://code.google.com/apis/sketchup/docs/ourdoc/definitionlist.html#load

        @skippy1974 said:

        • after my creation, I want to put every body un a group and manupilate the group (translation / rotation / scale
          I m not able to add some thing or everything in a group

        I am not entirely sure what you are trying to do here...
        You want to import multiple components into group?

        Thomas Thomassen — SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • S Offline
          Skippy1974
          last edited by

          thx
          I created several faces.
          I want ti select all and put in a group and after move the group

          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by

            All face geometry and intended group must be in the same context ['entities'].
            Make an array of the faces ['faces'].
            To make a group use...
            group=faces[0].parent.entities.add_group(faces)
            You can now change the group.name, group.layer, group.material etc.
            To move the group to a new point...
            pt=Geom::Point3d.new(1,2,3) ### or whatever x/y/z is required
            tr=Geom::Transformation.new(pt)
            then
            group.transform(tr)
            The 'group' is now at 'pt'...

            TIG

            1 Reply Last reply Reply Quote 0
            • thomthomT Offline
              thomthom
              last edited by

              @skippy1974 said:

              thx
              I created several faces.
              I want ti select all and put in a group and after move the group

              If you are creating all the geometry your self, then create the group first, then add the geometry directly into the group. It a different approach than when you model where you create geometry and then group.

              Thomas Thomassen — SketchUp Monkey & Coding addict
              List of my plugins and link to the CookieWare fund

              1 Reply Last reply Reply Quote 0
              • S Offline
                Skippy1974
                last edited by

                Thx I will try tomorrow

                1 Reply Last reply Reply Quote 0
                • S Offline
                  Skippy1974
                  last edited by

                  hello,
                  nothing works
                  I quite sure, the base of my code is ugly
                  could you help me to start with somthing well

                  
                  # Name ;          Projector 0.9b
                  
                  # Description ;   Generic projector drawing
                  
                  # Author ;        Sebastien CANAUD
                  #				  
                  
                  # Usage ;         1. Execute the script
                  #				  2. Fill in the GUI
                  
                  # Type ;      	Script
                  
                  # History; 
                  #                 Beta  (25.August.2010) - beta version
                  
                  # First we pull in the standard API hooks.
                  require 'sketchup'
                  
                  # Show the Ruby Console at startup so we can
                  # see any programming errors we may make.
                  Sketchup.send_action "showRubyPanel;"
                  
                  
                  # Add a menu item to launch our plugin.
                  def create_generic_projector
                   	# Access the Entities object
                  	model = Sketchup.active_model
                  	ent = model.entities
                  
                  	# Create the input box
                  	@projector_choise = "F22" if not @projector_choise 
                  	
                  	projector_choise = ["F12","F22","F32", "LX1500", "CP635"]
                      enums = [projector_choise.join("|")]
                  	
                  	prompts = ["Projector", "Ratio H", "Ratio V", "lens", "Vertical Shift", "Horizontal Shift ", "Screen height","X", "Y","Z", "Heading", "Pitch", "Roll"]
                  	defaults = [@projector_choise,"4", "3", "1.03", "110", "0", "2.2", "0", "0", "0", "0", "0", "0"]
                  	results = inputbox prompts, defaults, enums,"Projector Settings"
                  	return if not results
                  	projector_choise, results[0],results[1], results[2], results[3], results[4], results[5], results[6], results[7], results[8], results[9], results[10], results[11] = results
                  	
                  	# load projector
                  	if( projector_choise == "F12" )
                  		Sketchup.open_file "C;/ANTYCIP/Sketchup components/Projectors/ProjectionDesign_F12.skp"
                  		proj = Sketchup.active_model.entities.add_group
                  	end
                  	if( projector_choise == "F22" )
                  		Sketchup.open_file "C;/ANTYCIP/Sketchup components/Projectors/ProjectionDesign_F22.skp"
                  		proj = Sketchup.active_model.entities.add_group
                  	end
                  	if( projector_choise == "F32" )
                  		Sketchup.open_file "C;/ANTYCIP/Sketchup components/Projectors/ProjectionDesign_F32.skp"
                  		proj = Sketchup.active_model.entities.add_group
                  	end
                  	if( projector_choise == "LX1500" )
                  		Sketchup.open_file "C;/ANTYCIP/Sketchup components/Projectors/ChristieDigital_LX1500.skp"
                  		proj = Sketchup.active_model.entities.add_group
                  	end
                  	if( projector_choise == "CP635" )
                  		Sketchup.open_file "C;/ANTYCIP/Sketchup components/Projectors/Hitachi_CP635.skp"
                  		proj = Sketchup.active_model.entities.add_group
                  	end
                     
                  	# Projector settings
                  	ratioH = results[0].to_f
                  	ratioV = results[1].to_f
                  	lens = results[2].to_f
                  	verticalShift = results[3].to_f
                  	horizontalShift = results[4].to_f
                  	screenHeight = results[5].to_f
                  	x = results[9].to_f.mm
                  	y = results[10].to_f.mm
                  	z = results[11].to_f.mm
                  	heading = results[9].to_f.degrees
                  	pitch = results[10].to_f.degrees
                  	roll = results[11].to_f.degrees
                  	
                  	# temp
                  	norme = ratioH
                  	ratioH_in = ratioH.m
                  	ratioV_in = ratioV.m
                  	new_translationV_in = -verticalShift/2/100.0*ratioV/norme
                  	new_translationH_in = -horizontalShift/2/100.0
                  	scale_factor = screenHeight * (ratioH/ratioV)
                  
                  	# Create the five points of the pyramid
                  	pt1 = [0, 0, 0]
                  	pt2 = [lens*ratioH_in/norme, -ratioH_in/2/norme, ratioV_in/2/norme]
                  	pt3 = [lens*ratioH_in/norme, ratioH_in/2/norme, ratioV_in/2/norme]
                  	pt4 = [lens*ratioH_in/norme, ratioH_in/2/norme, -ratioV_in/2/norme]
                  	pt5 = [lens*ratioH_in/norme, -ratioH_in/2/norme, -ratioV_in/2/norme]
                  
                  	# Draw the faces
                  	ent.add_face(pt1, pt2, pt3)
                  	ent.add_face(pt1, pt3, pt4)
                  	ent.add_face(pt1, pt4, pt5)
                  	ent.add_face(pt1, pt5, pt2)
                  	projection_surface = ent.add_face(pt2, pt3, pt4, pt5)
                  
                  	# translation for the horizontal and vertical shift
                  	tr = Geom;;Transformation.translation [0, new_translationH_in.m, new_translationV_in.m]
                  	ent.transform_entities tr, projection_surface
                  
                  	# create group 
                  	group1 = ent.add_group projection_surface.all_connected
                  	group1.name = "pyramid"
                  	
                  	# scale
                  	s = Geom;;Transformation.scaling [0, 0, 0], scale_factor, scale_factor, scale_factor
                  	ent.transform_entities s, group1
                  	
                  	
                  	# rotation
                  	rh = Geom;;Transformation.rotation [0, 0, 0], [0, 0, 1], heading
                  	rp = Geom;;Transformation.rotation [0, 0, 0], [0, 1, 0], pitch
                  	rr = Geom;;Transformation.rotation [0, 0, 0], [1, 0, 0], roll
                  
                  	ent.transform_entities rh, group1
                  	ent.transform_entities rp, group1
                  	ent.transform_entities rr, group1
                  	
                  
                  
                  # Create the message box
                  #UI.messagebox results[1], MB_MULTILINE, results[0]
                  
                  #	printf("screenHeight ;%f",screenHeight)
                  
                  
                  end
                  #--------------------------------------------------------------------------
                  if( not file_loaded?("projector.rb") )
                      add_separator_to_menu("Plugins")
                      UI.menu("Plugins").add_item("Generic Projector") { create_generic_projector }
                  end
                  #--------------------------------------------------------------------------
                  file_loaded("projector.rb")
                  
                  
                  1 Reply Last reply Reply Quote 0
                  • thomthomT Offline
                    thomthom
                    last edited by

                    @skippy1974 said:

                    nothing works

                    Could you please be more specific? Error messages? Unexpected behaviour? (If so, what is expected?)

                    Thomas Thomassen — SketchUp Monkey & Coding addict
                    List of my plugins and link to the CookieWare fund

                    1 Reply Last reply Reply Quote 0
                    • S Offline
                      Skippy1974
                      last edited by

                      hello,
                      As I m a bigginer, I played with the script but I m not sure the based works.

                      http://sebcanaud.free.fr/Perso/sketchup0.jpg

                      the goal is to import a .skp (it's a projector). as I m not able to load I open a new file with the good projector shape.

                              Sketchup.open_file "C;/Program Files/Google/Google SketchUp 7/Plugins/Projectors/ProjectionDesign_F12.skp"
                      

                      After that, I create the pyramid of projection using specific parameter.
                      at the end I would like to move and rotate everthing. But I rotate only the pyramid I would like to merge the 2 group but as the Projector group is not loaded but as open file, I have not the hand on it

                          # create group 
                          group1 = ent.add_group projection_surface.all_connected
                          group1.name = "pyramid"
                          
                          # scale
                          s = Geom;;Transformation.scaling [0, 0, 0], scale_factor, scale_factor, scale_factor
                          ent.transform_entities s, group1
                          
                          
                          # rotation
                          rh = Geom;;Transformation.rotation [0, 0, 0], [0, 0, 1], heading
                          rp = Geom;;Transformation.rotation [0, 0, 0], [0, 1, 0], pitch
                          rr = Geom;;Transformation.rotation [0, 0, 0], [1, 0, 0], roll
                      
                          ent.transform_entities rh, group1
                          ent.transform_entities rp, group1
                          ent.transform_entities rr, group1
                      

                      http://sebcanaud.free.fr/Perso/sketchup1.jpg

                      thanks

                      1 Reply Last reply Reply Quote 0
                      • thomthomT Offline
                        thomthom
                        last edited by

                        You are opening the file because you could not load it as a component? Why did you not investigate to why you could not load the component?
                        hmm.... model.definitions.load did you perhaps assume would insert an instance of the component? model.definitions.load only loads the .skp into the model - you then have to place it in the model afterwards.

                        model = Sketchup.active_model projector_def = model.definitions.load "C:/Program Files/Google/Google SketchUp 7/Plugins/Projectors/ProjectionDesign_F12.skp" t = Geom::Transformation.new # This will load the component to the origin [0,0,0] projector = model.active_entities.add_instance( projector_def, t )

                        Thomas Thomassen — SketchUp Monkey & Coding addict
                        List of my plugins and link to the CookieWare fund

                        1 Reply Last reply Reply Quote 0
                        • S Offline
                          Skippy1974
                          last edited by

                          Perfect
                          I made a stupid mistake
                          I investigate not
                          thanks a lot

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

                          Advertisement