Move a group....API Ruby

Hello, everyone, help me, please,
I inserted a metal bar and a hole on the head of a pillar their position is located on the center of the side of the pillar…
To insert of a side shelf I need to move the metal bar and the hole to 5 cm…
I can move the metal bar but the hole no…
thanks…
Joseph


Metal bar creation code portion…(group_bf)

if sceltaBarraFilettata == true 
    			#Creiamo l'oggetto(barra_filettata)chiamando la funzione(def)...(metodo)...(class BarraFilettata) con ".new" della classe "GC_Pil_1bsx"...
				#passando i valori numerici(diam_bf..es= 3 cm., alt_bf..es= 50 cm...valori presi dal "dlg.add_action_callback("ottieniInput")"..javascript e html..)..
				#passandoli ai parametri(diam, alt) del metodo/oggetto "class BarraFilettata"...  
				barra_filettata = BarraFilettata.new(diam_bf, alt_bf)#Passiamo i valori numerici(diametro_bf, alt_bf) all'oggetto della classe "BarraFilettata"...presi dal callback ottieniInput...
				altezza_da_ppboc_bf = (alt_imbicch + alt_ppf_sopra_bicch + alt_h1_pil - alt_neop)
				pt_inserimento_bf = Geom::Point3d.new(0, (-lato_y_pil/2)+16.cm, altezza_da_ppboc_bf)
			end # Chiusura dell'if bf_si.....

			unless barra_filettata.nil?# a meno che(unless) la barra filettata sia stata definita....
				group_bf = container.add_group#creiamo il "contenitore", in cui inserire le sucessive entità che compongono il gruppo "barra Filettata"....
				group_bf.name = 'bf'
				group_bf.material = "Ferro_01"
				#creazione e inserimento barra filettata
				bf = group_bf.entities.add_circle(pt_inserimento_bf, vector, barra_filettata.diametro / 2)
				face8 = group_bf.entities.add_face(bf)
				bf = face8.pushpull(barra_filettata.altezza)
			end
            .........................................
            ..............................................
            ........................................................

#################################
Portion of hole creation code…(group_pl_ent)

if sceltaPluviale == true  
					
			#### FORO DI ENTRATA DEL PLUVIALE ###
			foro_pluviale_ent = Pluviale.new(diametro_pl)
			altezza_da_ppboc_pl = (alt_imbicch + alt_ppf_sopra_bicch + alt_h1_pil - alt_neop)
			pt_inserimento_pluvEntrata = Geom::Point3d.new(0, -(lato_y_pil/2 - (6.cm + diametro_pl/2)), altezza_da_ppboc_pl -15.cm)#punto inserimento pluviale in ENTRATA....
					
			group_pl_ent = container.add_group
			group_pl_ent.name = 'pl_ent'
			group_pl_ent.material = "PVC_01"
			
			pl_entrata = group_pl_ent.entities.add_circle(pt_inserimento_pluvEntrata, vector, foro_pluviale_ent.diametro_foro_pl / 2)
			face_entrata = group_pl_ent.entities.add_face(pl_entrata)
			face_entrata.reverse!
			#face_entrata.material = "PVC_01"
			face_entrata.pushpull -15.cm
			group_pil = group_pl_ent.subtract(group_pil)
            ............................................
            ......................................................

#####################################
Portion of code where I move the hole and the metal bar by 5 cm…

if sceltaMensolaTestata == true # Se(if) il "radioButton"(html /NO/SI) Mensola di Testata è sul "SI"(id='me_si').....
			     
				 mensola_testata = MensolaTestata.new(alt_MensTest_H, dim_MensTest_Sp) #Passiamo i valori numerici(alt_MensTest_H, dim_MensTest_Sp) all'oggetto della classe "MensolaTestata"...presi dal callback ottieniInput...
				 
				if mensolaTestata_latoY_int == true then # Se(if) il "radioButton"(html /Lato "X" interno/Lato "Y" interno) Lato Interno Mensola Testata è falso...
					
					altezza_da_ppboc_me = (alt_imbicch + alt_ppf_sopra_bicch + alt_h1_pil - alt_neop)
					pt1_mT = pt_orig.transform([lato_x_pil/2, -lato_y_pil/2, altezza_da_ppboc_me]) #punto_1 inserimento Faccia Mensola Testata lato Y....
					pt2_mT = pt_orig.transform([lato_x_pil/2, lato_y_pil/2, altezza_da_ppboc_me]) #punto_2 inserimento Faccia Mensola Testata lato Y....
					pt2a_mT = pt2_mT.transform([mensola_testata.sporgenza_mensola_testata, 0, 0])
					pt3_mT = pt_orig.transform([lato_x_pil/2, lato_y_pil/2, altezza_da_ppboc_me -(mensola_testata.altezza_mensola_testata)]) #punto_3 inserimento Faccia Mensola Testata lato Y....
					pt3a_mT = pt3_mT.transform([mensola_testata.sporgenza_mensola_testata, 0, 0])
					pt4_mT = pt_orig.transform([lato_x_pil/2, -lato_y_pil/2, altezza_da_ppboc_me -(mensola_testata.altezza_mensola_testata)]) #punto_4 inserimento Faccia Mensola Testata lato Y....
					
					faccia_MensTest = pt1_mT, pt2_mT, pt3_mT, pt4_mT 
					
					unless mensola_testata.nil? # a meno che(unless) la mensola di testata non sia stata definita....
						mensTestata = group_pil.entities.add_face(faccia_MensTest)
						mensTestata.pushpull (mensola_testata.sporgenza_mensola_testata)
					end #Chiusura della "unless" della Mensola di Testata lato "Y" interno .....
					

					unless foro_pluviale_ent.nil?
					   pt_inserimento_pluvEntrata_con_mens = Geom::Point3d.new(-5.cm, 0, 0)
					   transf_pl_ent = Geom::Transformation.new(pt_inserimento_pluvEntrata_con_mens)
					   group_pl_ent = group_pl_ent.move! transf_pl_ent
					end
								
					unless barra_filettata.nil? 
						if sceltaPluviale == true
							pt_inser_bf_con_mens = Geom::Point3d.new(-5.cm, ((lato_y_pil/2)+(lato_y_pil/2-16.cm)-16.cm), 0)
							else
							pt_inser_bf_con_mens = Geom::Point3d.new(-5.cm, 0, 0)
						end
						transf_bf_mens = Geom::Transformation.new(pt_inser_bf_con_mens)
						group_bf = group_bf.move! transf_bf_mens
					end
                    ....................................................
                    ...................................................
                    ..................................................

########################################
Portion of code where I move the metal bar by 5 cm and it works…

unless barra_filettata.nil? 
	if sceltaPluviale == true
	   pt_inser_bf_con_mens = Geom::Point3d.new(-5.cm, ((lato_y_pil/2)+(lato_y_pil/2-16.cm)-16.cm), 0)
	else
	   pt_inser_bf_con_mens = Geom::Point3d.new(-5.cm, 0, 0)
	end
	  transf_bf_mens = Geom::Transformation.new(pt_inser_bf_con_mens)
	  group_bf = group_bf.move! transf_bf_mens
end					

#####################################
Portion of code where I move the hole 5 cm and Not Work…

unless foro_pluviale_ent.nil?
   pt_inserimento_pluvEntrata_con_mens = Geom::Point3d.new(-5.cm, 0, 0)
   transf_pl_ent = Geom::Transformation.new(pt_inserimento_pluvEntrata_con_mens)
   group_pl_ent = group_pl_ent.move! transf_pl_ent
end

########################################

Is the hole a subgroup of the pillar group? Or is it primitive geometry ?


P.S.

  1. When you post a problem like this also post the test model SKP file.

  2. Ruby uses 2 space indents. Make sure your editor is set to replace tab characters with 2 spaces. (Tabs do not post well in the forums.)

Thank you, Mr DanRathbun, for taking an interest in my problem,
I want to assure you that before applying for help in the forum
spend several hours if not days trying to solve the problem alone
When I don’t know where to hit my head, I ask for help…
The hole group, I create it after I’ve already created the pillar group…
So it should be a subgroup…
I attach the Skp file and the rb file…
Thank you
Greetings
Joseph

Pillar.skp (77.8 KB)

Pil_1bsx.rb (27.5 KB)

Just an FYI, do not use the #move! method unless you are doing animation.
Use the #transform! method to permanently move geometry.

I looked at your model, and as I suspected, the hole is not a subgroup. It is primitive geometry.

To relocate primitive geometry, you need to use the Entities.transform_entities method.

As for your code, I’m sorry but I do not read Italian so it is too difficult to even try to figure out where the error is.

This statement seems a problem to me. #move! (and #transform! as @DanRathbun suggested) both return a boolean true/false indicating whether the operation succeeded. Assigning group_pl_ent to the returned value is going to abandon your reference to that group.

Edit: but I think Dan’s observation that the hole is ungrouped geometry is the heart of the problem. If I understand, you created the hole by a subtract operation on the pillar. That opens a hole in the pillar, but doesn’t make that hole a group.

Yes, that’s right, I created the hole by a subtract operation on the pillar…

Okay, I’ll try the suggested route…

To move the metal bar I replaced the #move! method with #transform! and it works
but it doesn’t work for the hole…

unless foro_pluviale_ent.nil?
	   group_pl_ent = container.add_group
	   group_pl_ent.name = 'pl_ent'
	   group_pl_ent.material = "PVC_01"
				   
	   pt_inserimento_pluvEntrata_con_mens = Geom::Point3d.new(-5.cm, -(lato_y_pil/2 - (6.cm + diametro_pl/2)), altezza_da_ppboc_pl -15.cm)
	   transf_pl_ent = Geom::Transformation.new(pt_inserimento_pluvEntrata_con_mens)
	   group_pl_ent = group_pl_ent.transform! transf_pl_ent
end

unless barra_filettata.nil? 
	if sceltaPluviale == true
		pt_inser_bf_con_mens = Geom::Point3d.new(-5.cm, 0, 0)
	end
		transf_bf_mens = Geom::Transformation.new(pt_inser_bf_con_mens)
		group_bf = group_bf.transform! transf_bf_mens
end

I was convinced that writing lines of code in this way created the group of the hole…

group_pl_ent = container.add_group
    group_pl_ent.name = 'pl_ent'
	group_pl_ent.material = "PVC_01"

##########

#### FORO DI ENTRATA DEL PLUVIALE ###
foro_pluviale_ent = Pluviale.new(diametro_pl)
altezza_da_ppboc_pl = (alt_imbicch + alt_ppf_sopra_bicch + alt_h1_pil - alt_neop)
pt_inserimento_pluvEntrata = Geom::Point3d.new(0, -(lato_y_pil/2 - (6.cm + diametro_pl/2)), altezza_da_ppboc_pl -15.cm)#punto inserimento pluviale in ENTRATA....
					
		group_pl_ent = container.add_group
		group_pl_ent.name = 'pl_ent'
		group_pl_ent.material = "PVC_01"
			
		pl_entrata = group_pl_ent.entities.add_circle(pt_inserimento_pluvEntrata, vector, foro_pluviale_ent.diametro_foro_pl / 2)
		face_entrata = group_pl_ent.entities.add_face(pl_entrata)
		face_entrata.reverse!
		#face_entrata.material = "PVC_01"
		face_entrata.pushpull -15.cm
		group_pil = group_pl_ent.subtract(group_pil)

##########

What you may be missing is that the subtract operation does not nest the subtracted cylinder group into the pillar, it creates new “loose” geometry equivalent to the original group. The hole is not a group after the subtract.

Okay, I can’t figure out how to make the hole a group after removing it from the main pillar group and then moving it with the #transform! method… you can help me figure out how to do…
Joseph

No matter how you proceed, you will need to identify the geometry that makes up the hole, since its assembly as a group has been lost in the subtraction.

At that point you can move it using Entities#transform_entities or Entities#transform_by_vectors without bothering to make a group. Or, if the nesting will have further use, make a nested group and then apply a transformation to it.

1 Like

Ciao a tutti, per il momento l’ho risolto in questo modo …
All’inizio della sceneggiatura, quando creo la barra di metallo (if sceltaBarraFilettata == true),
creo un punto con le coordinate x, y e z, per inserire la barra di metallo ,

.........................
...................................
............................................
if sceltaBarraFilettata == true 
    			
	barra_filettata = BarraFilettata.new(diam_bf, alt_bf)#Passiamo i valori numerici(diametro_bf, alt_bf) all'oggetto della classe "BarraFilettata"...presi dal callback ottieniInput...
	altezza_da_ppboc_bf = (alt_imbicch + alt_ppf_sopra_bicch + alt_h1_pil - alt_neop)
			
	x_inserimento_bf = 0
	y_inserimento_bf = (-lato_y_pil/2)+16.cm
	z_inserimento_bf = altezza_da_ppboc_bf
				
	if sceltaMensolaTestata and (mensolaTestata_latoY_int or mensolaTestata_latoXY_int)
		x_inserimento_bf = -5.cm
	end 
				
	if sceltaPluviale == true
		y_inserimento_bf = lato_y_pil/2 - 16.cm
	end
				
	pt_inserimento_bf = Geom::Point3d.new(x_inserimento_bf, y_inserimento_bf, z_inserimento_bf)
end # Chiusura dell'if bf_si.....
...............................
..........................................
...................................................

same thing for the rain hole(if sceltaPluviale == true)…

...................
..............................
.....................................
if sceltaPluviale == true  
  
  foro_pluviale_ent = Pluviale.new(diametro_pl)
  altezza_da_ppboc_pl = (alt_imbicch + alt_ppf_sopra_bicch + alt_h1_pil - alt_neop)
				
 x_inserimento_pl = 0
 y_inserimento_pl = -(lato_y_pil/2 - (6.cm + diametro_pl/2))
 z_inserimento_pl = altezza_da_ppboc_pl -15.cm
					
  if sceltaMensolaTestata and (mensolaTestata_latoY_int or mensolaTestata_latoXY_int)
	x_inserimento_pl = -5.cm
  end 
					
  pt_inserimento_pluvEntrata = Geom::Point3d.new(x_inserimento_pl, y_inserimento_pl, z_inserimento_pl)#punto inserimento pluviale in ENTRATA....
					
		group_pl_ent = container.add_group
		group_pl_ent.name = 'pl_ent'
		group_pl_ent.material = "PVC_01"
										
 pl_entrata = group_pl_ent.entities.add_circle(pt_inserimento_pluvEntrata, vector, foro_pluviale_ent.diametro_foro_pl / 2)
	face_entrata = group_pl_ent.entities.add_face(pl_entrata)
	face_entrata.reverse!
	face_entrata.pushpull -15.cm
										
	group_pil = group_pl_ent.subtract(group_pil)
...............
.........................
...................................

Video_gif

Video1_gif

I thank you for the good advice, I will try to do it, for now as you will see I have solved in another way, I managed to do only this as a change… thanks
Joseph

Many thanks, to all participants in this discussion, for all the valuable advice and solutions proposed…
Joseph