Reset Scale

Hello
I created a new function for dynamic components, according to the TIG method by integrating
if not DCFunctionsV1.method_defined? (: parametres3dtext)
defparametres3dtext (a)
I was largely inspired by TIG’s TextTag plugin
Thank you TIG
The parameter3dtext function works well! It creates the attributes (font, text, alignment, bold …), It erases all the entities of the component, it adds a group to it and in this last it models the 3d text with add3dtext () on the entities of the group.

The downside is that the text is distorted by the old component scale. The only manual remedy is the right click reset the scale.
How to do this scale reset but in ruby.

I read several related posts but without understanding the steps and the result of each. I do not know where to look, thank you for agreeing to explain me step by step.

 # encoding: UTF-8
#
# file "sj_AddDCFunctions/AddDcFunctions.rb"

# add_DC_function.rb
# extends DCs functions


require('sketchup')
require('su_dynamiccomponents.rb')
if defined?($dc_observers)
# Open SketchUp's Dynamic Component Functions (V1) class.
# BUT only if DC extension is active...
class DCFunctionsV1
    protected       
        # Creation d'attributs de parametrage d'un texte 3D        
        # # DC Function Usage: =parmetres3dText()
        if not DCFunctionsV1.method_defined?(:parametres3dtext)
            def parametres3dtext(a)
                
               # Initialisation des valeurs par défault
               #Liste des font vous pouvez mofifier l'array en ajoutant ou supprimant les noms de police.
               # Elle doivent exister au format 
               fontlist=["Arial","Arial Black","Arial Narrow","Bookman Old Style","Bradley Hand ITC","Century","Century Gothic","CityBlueprint","Corbel","Comic Sans MS","Courier New","Eurostile","Garamond","Georgia","Impact","Lucida Console","Monotxt","Monotype Corsiva","Papyrus","Rockwell","RomanT","Romantic","SansSerif","Simplex","Stylus BT","Symbol","Tahoma","Technic","Times New Roman","Trebuchet MS","Verdana","Vineta BT","Vrinda","Webdings","Wingdings","Wingdings 2","Wingdings 3"]
               fontlist_option="&"+fontlist .map {|a|a+"="+a+"&"}.join()
               align = 1
               font = "Comic sans MS"
               bold = false
               italic = false
               height = 10.cm
               height_s = 3.937007874015748
               tol = 0.1.mm
               tol_s = 0.003937007874015749
               z = 0
               filled = true
               extrusion = 2.cm
               extrusion_s = 0.7874015748031495
               so = 1.mm
               text = "DC3dText"

                #model=SketchUp.active_model
                #definitions = model.definitions
                dcdict = "dynamic_attributes"

                source_def = @source_entity.definition
                source_ents = source_def.entities

                #On supprime la formule rentrée dans txt_ini qui à appeller la création des attributs
                source_def.delete_attribute(dcdict,"_txt_ini_formula")
                @source_entity.delete_attribute(dcdict,"_txt_ini_formula")

                #On efface les entités à l'interieur
                xents=source_ents.to_a ###***
                xents.each{|e|e.erase! if e.valid?}### remove old stuff***

                group_text_new = source_ents.add_group()
                group_text_new.description = "DC3dtext"
                group_text_new_ents = group_text_new.entities
                group_text_new_ents.add_3d_text(text,align,font,bold,italic,height,tol,z,filled,extrusion)

                pt=Geom::Point3d.new(0,0,so)
                t=Geom::Transformation.new(pt)
                group_text_new.move!(t)
                group_text_new.explode



                #Créations des attributs de controle du texte 

                #Creation de l'attribut font
                source_def.set_attribute(dcdict, "txt_01_font", "Arial")
                source_def.set_attribute(dcdict,"_txt_01_font_label","txt_01_font")
                source_def.set_attribute(dcdict,"_txt_01_font_formulaunits","STRING")
                source_def.set_attribute(dcdict,"_txt_01_font_units","STRING")
                source_def.set_attribute(dcdict,"_txt_01_font_access","LIST")
                source_def.set_attribute(dcdict,"_txt_01_font_options", fontlist_option)
                source_def.set_attribute(dcdict,"_txt_01_font_formlabel","Police")
                

                #Creation de l'attribut alignement
                source_def.set_attribute(dcdict, "txt_02_align", "0")
                source_def.set_attribute(dcdict,"_txt_02_align_label","txt_02_align")
                source_def.set_attribute(dcdict,"_txt_02_align_formulaunits","STRING")
                source_def.set_attribute(dcdict,"_txt_02_align_units","STRING")
                source_def.set_attribute(dcdict,"_txt_02_align_access","LIST")
                source_def.set_attribute(dcdict,"_txt_02_align_options","&Left=0&Center=1&Right=2&")
                source_def.set_attribute(dcdict,"_txt_02_align_formlabel","Alignement")

                #Creation de l'attribut italic
                source_def.set_attribute(dcdict, "txt_03_italic", "FALSE")
                source_def.set_attribute(dcdict,"_txt_03_italic_label","txt_03_italic")
                source_def.set_attribute(dcdict,"_txt_03_italic_formulaunits","STRING")
                source_def.set_attribute(dcdict,"_txt_03_italic_units","STRING")
                source_def.set_attribute(dcdict,"_txt_03_italic_access","LIST")
                source_def.set_attribute(dcdict,"_txt_03_italic_options","&Non=FALSE&Oui=TRUE&")
                source_def.set_attribute(dcdict,"_txt_03_italic_formlabel","Italic")

                #Creation de l'attribut bold
                source_def.set_attribute(dcdict, "txt_04_bold", "FALSE")
                source_def.set_attribute(dcdict,"_txt_04_bold_label","txt_04_bold")
                source_def.set_attribute(dcdict,"_txt_04_bold_formulaunits","STRING")
                source_def.set_attribute(dcdict,"_txt_04_bold_units","STRING")
                source_def.set_attribute(dcdict,"_txt_04_bold_access","LIST")
                source_def.set_attribute(dcdict,"_txt_04_bold_options","&Non=FALSE&Oui=TRUE&")
                source_def.set_attribute(dcdict,"_txt_04_bold_formlabel","Gras")



                #Creation de l'attribut height
                source_def.set_attribute(dcdict, "txt_05_height", height_s)
                source_def.set_attribute(dcdict,"_txt_05_height_label","txt_05_height")
                source_def.set_attribute(dcdict,"_txt_05_height_formulaunits","CENTIMETERS")
                source_def.set_attribute(dcdict,"_txt_05_height_units","CENTIMETERS")
                source_def.set_attribute(dcdict,"_txt_05_height_access","TEXTBOX")
                source_def.set_attribute(dcdict,"_txt_05_height_formlabel","Hauteur caractère")
                source_def.set_attribute(dcdict,"_txt_06_filled_formula","")

                #Creation de l'attribut filled
                source_def.set_attribute(dcdict, "txt_06_filled", "TRUE")
                source_def.set_attribute(dcdict,"_txt_06_filled_label","txt_06_filled")
                source_def.set_attribute(dcdict,"_txt_06_filled_formulaunits","STRING")
                source_def.set_attribute(dcdict,"_txt_06_filled_units","STRING")
                source_def.set_attribute(dcdict,"_txt_06_filled_access","LIST")
                source_def.set_attribute(dcdict,"_txt_06_filled_options","&Non=FALSE&Oui=TRUE&")
                source_def.set_attribute(dcdict,"_txt_06_filled_formlabel","Rempli")
                source_def.set_attribute(dcdict,"_txt_06_filled_formula","")

                #Creation de l'attribut extrusion
                source_def.set_attribute(dcdict, "txt_07_extrusion", extrusion_s)
                source_def.set_attribute(dcdict,"_txt_07_extrusion_label","txt_07_extrusion")
                source_def.set_attribute(dcdict,"_txt_07_extrusion_formulaunits","CENTIMETERS")
                source_def.set_attribute(dcdict,"_txt_07_extrusion_units","CENTIMETERS")
                source_def.set_attribute(dcdict,"_txt_07_extrusion_access","TEXTBOX")
                source_def.set_attribute(dcdict,"_txt_07_extrusion_formlabel","Hauteur d'extrusion")
                source_def.set_attribute(dcdict,"_txt_07_extrusion_formula","")

                #Creation de l'attribut decallage en z
                source_def.set_attribute(dcdict, "txt_08_zoffset", "0")
                source_def.set_attribute(dcdict,"_txt_08_zoffset_label","txt_08_zoffset")
                source_def.set_attribute(dcdict,"_txt_08_zoffset_formulaunits","CENTIMETERS")
                source_def.set_attribute(dcdict,"_txt_08_zoffset_units","CENTIMETERS")
                source_def.set_attribute(dcdict,"_txt_08_zoffset_access","TEXTBOX")
                source_def.set_attribute(dcdict,"_txt_08_zoffset_formlabel","Décallage z")
                source_def.set_attribute(dcdict,"_txt_08_zoffset_formula","")

                #Creation de l'attribut tolerance arrondi 0.1mm
                source_def.set_attribute(dcdict, "txt_09_tol", tol_s)
                source_def.set_attribute(dcdict,"_txt_09_tol_label","txt_09_tol")
                source_def.set_attribute(dcdict,"_txt_09_tol_formulaunits","CENTIMETERS")
                source_def.set_attribute(dcdict,"_txt_09_tol_units","MILLIMETERS")
                source_def.set_attribute(dcdict,"_txt_09_tol_access","TEXTBOX")
                source_def.set_attribute(dcdict,"_txt_09_tol_formlabel","Tolérence arrondi")
                source_def.set_attribute(dcdict,"_txt_09_tol_formula","")


                #Creation de l'attribut actualtexte Remplacement saut de ligne
                source_def.set_attribute(dcdict, "txt_10_linebreak", "LB")
                source_def.set_attribute(dcdict,"_txt_10_linebreak_label","txt_10_linebreak")
                source_def.set_attribute(dcdict,"_txt_10_linebreak_formulaunits","STRING")
                source_def.set_attribute(dcdict,"_txt_10_linebreak_units","STRING")
                source_def.set_attribute(dcdict,"_txt_10_linebreak_access","TEXTBOX")
                source_def.set_attribute(dcdict,"_txt_10_linebreak_formlabel","Caractère(s) saut de ligne")
                source_def.set_attribute(dcdict,"_txt_10_linebreak_formula","")


                #Creation de l'attribut texte
                source_def.set_attribute(dcdict, "txt_11_texte", "DC3dtext")
                source_def.set_attribute(dcdict,"_txt_11_texte_label","txt_11_texte")
                source_def.set_attribute(dcdict,"_txt_11_texte_formulaunits","STRING")
                source_def.set_attribute(dcdict,"_txt_11_texte_units","STRING")
                source_def.set_attribute(dcdict,"_txt_11_texte_access","TEXTBOX")
                source_def.set_attribute(dcdict,"_txt_11_texte_formlabel","Texte")
                source_def.set_attribute(dcdict,"_txt_11_texte_formula","")

                #Creation de l'attribut actualiser
                source_def.set_attribute(dcdict, "txt_12_actualiser", "FALSE")
                source_def.set_attribute(dcdict,"_txt_12_actualiser_label","txt_12_actualiser")
                source_def.set_attribute(dcdict,"_txt_12_actualiser_formulaunits","STRING")
                source_def.set_attribute(dcdict,"_txt_12_actualiser_units","STRING")
                source_def.set_attribute(dcdict,"_txt_12_actualiser_access","LIST")
                source_def.set_attribute(dcdict,"_txt_12_actualiser_options","&Non=FALSE&Oui=TRUE&")
                source_def.set_attribute(dcdict,"_txt_12_actualiser_formlabel","Actualiser")
                source_def.set_attribute(dcdict,"_txt_12_actualiser_formula","")

                #Creation de l'attribut edition
                source_def.set_attribute(dcdict, "txt_13_edit", "Texte non edité")
                source_def.set_attribute(dcdict,"_txt_13_edit_label","txt_13_edit")
                source_def.set_attribute(dcdict,"_txt_13_edit_formulaunits","STRING")
                source_def.set_attribute(dcdict,"_txt_13_edit_units","STRING")
                source_def.set_attribute(dcdict,"_txt_13_edit_access","VIEW")
                source_def.set_attribute(dcdict,"_txt_13_edit_formula","EDIT3DTEXT( txt_11_texte , txt_10_linebreak , txt_02_align , txt_01_font , txt_04_bold , txt_03_italic , txt_05_height , txt_09_tol , txt_08_zoffset , txt_06_filled , txt_07_extrusion , txt_12_actualiser )")
                source_def.set_attribute(dcdict,"_txt_13_edit_formlabel","Edition")

                #Creation de l'attribut layer
                source_def.set_attribute(dcdict, "txt_14_layer", "")
                source_def.set_attribute(dcdict,"_txt_14_layer_label","txt_14_layer")
                source_def.set_attribute(dcdict,"_txt_14_layer_formulaunits","STRING")
                source_def.set_attribute(dcdict,"_txt_14_layer_units","STRING")
                source_def.set_attribute(dcdict,"_txt_14_layer_access","TEXTBOX")
                source_def.set_attribute(dcdict,"_txt_14_layer_options","&")
                source_def.set_attribute(dcdict,"_txt_14_layer_formlabel","Calque/Balise")
                source_def.set_attribute(dcdict,"_txt_14_layer_formula","")

                #Creation de l'attribut layer
                source_def.set_attribute(dcdict, "txt_15_setlayer", "")
                source_def.set_attribute(dcdict,"_txt_15_setlayer_label","txt_15_setlayer")
                source_def.set_attribute(dcdict,"_txt_15_setlayer_formulaunits","STRING")
                source_def.set_attribute(dcdict,"_txt_15_setlayer_units","STRING")
                source_def.set_attribute(dcdict,"_txt_15_setlayer_access","NONE")
                source_def.set_attribute(dcdict,"_txt_15_setlayer_options","&")
                source_def.set_attribute(dcdict,"_txt_15_setlayer_formlabel","calcul setlayer")
                source_def.set_attribute(dcdict,"_txt_15_setlayer_formula","SETLAYER(txt_14_layer)")

                #Creation de l'attribut layer
                source_def.set_attribute(dcdict, "txt_16_color", "default")
                source_def.set_attribute(dcdict,"_txt_16_color_label","txt_16_color")
                source_def.set_attribute(dcdict,"_txt_16_color_formulaunits","STRING")
                source_def.set_attribute(dcdict,"_txt_16_color_units","STRING")
                source_def.set_attribute(dcdict,"_txt_16_color_access","TEXTBOX")
                source_def.set_attribute(dcdict,"_txt_16_color_options","&")
                source_def.set_attribute(dcdict,"_txt_16_color_formlabel","Couleur")
                source_def.set_attribute(dcdict,"_txt_16_color_formula","")

                #Creation de l'attribut layer
                source_def.set_attribute(dcdict, "txt_17_setmaterial", "Default")
                source_def.set_attribute(dcdict,"_txt_17_setmaterial_label","txt_17_setmaterial")
                source_def.set_attribute(dcdict,"_txt_17_setmaterial_formulaunits","STRING")
                source_def.set_attribute(dcdict,"_txt_17_setmaterial_units","STRING")
                source_def.set_attribute(dcdict,"_txt_17_setmaterial_access","NONE")
                source_def.set_attribute(dcdict,"_txt_17_setmaterial_options","&")
                source_def.set_attribute(dcdict,"_txt_17_setmaterial_formlabel","calcul setmaterial")
                source_def.set_attribute(dcdict,"_txt_17_setmaterial_formula","SETMATERIAL(txt_16_color)")

                return "Attributs texte créés"
                

            end
        end
    end#class
end#if

Thank you

Do you realize that changing the DCFunctionsV1 class makes it no longer version 1 ?

This means it can only work with your own components and cannot be released as an extension on the EW, and should not be released as an extension anywhere at all.

2 Likes

Good evening Dan,
I do not modify the DCFunctionsV1 in any way, I ask it blindly if the function named “xx” exists and I implement my function in a very separate file. So no I am not modifying the Trimble proprietary file. I do this for myself and share it with anyone who finds it useful. If Trimble feels offended and does not want to open their platform to me to share this code, well too bad for them! After this clarification are you willing to continue to help me.
Thank you

I remembered that old link
http://www.martinrinehart.com/models/tutorial/tutorial_t.html

So I would think like this… using Transformation .scaling method

def reset_scale_a(obj)
  tr_matrix = obj.transformation.to_a
  xscale = tr_matrix[0]
  yscale = tr_matrix[5]
  zscale = tr_matrix[10]
  tr_reset_scale = Geom::Transformation.scaling(1.0/xscale, 1.0/yscale, 1.0/zscale)
  obj.transform!(tr_reset_scale)
end

or:

def reset_scale_b(obj)
  tr_matrix = obj.transformation.to_a
  xscale = tr_matrix[0]
  yscale = tr_matrix[5]
  zscale = tr_matrix[10]
  cp = obj.bounds.center
  tr_reset_scale= Geom::Transformation.scaling(cp, 1.0/xscale, 1.0/yscale, 1.0/zscale)
  obj.transform!(tr_reset_scale)
end

So you can call these methods by put your desired group to argument, like:

reset_scale_a(group_text_new)

or

reset_scale_b(group_text_new)

2 Likes

Thanks a lot Dezmo
I go to test and I come back

Incorrect. You are modifying the DCFunctionsV1 class.

NO

1 Like

You are welcome! BUT:
I have to agree with Dan!
Keep the code for yourself, for your own “educational” or other own purposes only!