sketchucation logo sketchucation
    • Login
    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!
    🫛 Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

    Text position problem

    Scheduled Pinned Locked Moved Developers' Forum
    23 Posts 5 Posters 2.6k Views 5 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.
    • J Offline
      Jorgensen
      last edited by

      I'm working on my very own (noooooob) area script.

      And now I'm having my first problem - when add a text to a face in Sketchup, by doubbleclick, the text is visible from allmost every angle, but if I use

      coordinates = object.bounds.center
      model = Sketchup.active_model
      entities = model.entities
      point = Geom::Point3d.new coordinates
      
      $area = (object.area / (39.3700787*39.3700787)).round
      $text = "#{object.layer.name}\n#$area m2"
      $textObjects.push(entities.add_text $text, point)
      

      It seems like the text is being cut by the face - is there a way to avoid this ?

      And a other small thing - how do I add a ² to the areatext ?

      Thanks
      Jorgensen

      Here is the complete script:

      $textObjects = Array.new

      def tmTextAdd
      tmSelectAllFaces
      model = Sketchup.active_model
      ss = model.selection
      for object in ss

      end
      ss.clear
      end

      def tmSelectAllFaces
      model = Sketchup.active_model
      ss = model.selection
      ss.clear
      for ent in model.entities
      if (ent.kind_of?(Sketchup::Face))
      ss.add(ent)
      end
      end
      end

      def tmTextDelete
      if $textObjects.length > 0
      $textObjects.each do |e|
      if(not e.deleted?)
      e.erase!
      end
      end
      $textObjects.clear
      end
      end

      #tmSelectAllFaces
      #tmTextAdd
      #tmTextDelete

      #---------------------------------------------------------------
      #- Setup menu -
      #---------------------------------------------------------------
      if(not $TM_area_loaded)
      Mejeriet_menu = UI.menu("Plugins").add_submenu("TM").add_submenu("Arealer")
      Mejeriet_menu.add_item("On") { tmTextAdd }
      Mejeriet_menu.add_item("Off") { tmTextDelete }
      end
      $TM_area_loaded = true

      sketchup pro 2016 16.1.1449 64 bit | windows 10 pro | i7-3770k @3.5 GHz | 16gb ram | gtx 780 ti / gtx 980 ti | nvidia driver 368.39

      1 Reply Last reply Reply Quote 0
      • A Offline
        azuby
        last edited by

        I've done a bit cosmetics to your script and put all the code togehter (you wrote, "complete script", but the text-adding wasn't in)

        $textObjects = Array.new
        
        def tmTextAdd
          tmSelectAllFaces
          model    = Sketchup.active_model
          entities = model.entities
          ss       = model.selection
          for object in ss
            point = Geom;;Point3d.new object.bounds.center
            area  = (object.area / (39.3700787*39.3700787)).round
            text  = "#{object.layer.name}\n#{area} m²"
            $textObjects.push entities.add_text(text, point)
          end
          ss.clear
        end
        
        def tmSelectAllFaces
          model = Sketchup.active_model
          ss = model.selection
          ss.clear
          for ent in model.entities do
              ss.add ent if ent.kind_of? Sketchup;;Face
          end
        end
        
        def tmTextDelete
          unless $textObjects.empty?
            for e in $textObjects do
              e.erase! unless e.deleted?
            end
            $textObjects.clear
          end
        end
        
        
        #---------------------------------------------------------------
        #- Setup menu -
        #---------------------------------------------------------------
        unless $TM_area_loaded
          Mejeriet_menu = UI.menu("Plugins").add_submenu("TM").add_submenu("Arealer")
          Mejeriet_menu.add_item("On") { tmTextAdd }
          Mejeriet_menu.add_item("Off") { tmTextDelete }
        end
        $TM_area_loaded = true
        

        And for me it worked. I can see all texts from all directions.

        azuby

        *error initus :: Blocks | CurrentDate | d/Code | extensionmanager | FFlipper | HideEdges | MeasuredArea | ModelHistory | PluginsHelp | PronButton | SAWSO | SCP | SU²CATT

        Bad English? PM me, correct me. :smile:**

        1 Reply Last reply Reply Quote 0
        • J Offline
          Jorgensen
          last edited by

          Hi azuby

          Thanks for your help - but I still have the problem that the text gets cut off - se images.

          The 'test' text is added via mouseclick and does not have this problem 😞

          EDIT
          Is this the proper group/place for such technical questions ?


          1.jpg


          2.jpg

          sketchup pro 2016 16.1.1449 64 bit | windows 10 pro | i7-3770k @3.5 GHz | 16gb ram | gtx 780 ti / gtx 980 ti | nvidia driver 368.39

          1 Reply Last reply Reply Quote 0
          • A Offline
            azuby
            last edited by

            Hmmm maybe it's a problem with OpenGL?

            azuby

            *error initus :: Blocks | CurrentDate | d/Code | extensionmanager | FFlipper | HideEdges | MeasuredArea | ModelHistory | PluginsHelp | PronButton | SAWSO | SCP | SU²CATT

            Bad English? PM me, correct me. :smile:**

            1 Reply Last reply Reply Quote 0
            • J Offline
              Jorgensen
              last edited by

              If I afterwards manual move the text 200mm, on the blue axis, the problem dissapers.

              But how do I do this automatic ?
              point = Geom::Point3d.new object.bounds.center
              Adding 200mm to the Z axe of point ?

              Sorry, I have quite a lot questions.... and still a lot to come

              Thanks
              Jorgensen

              sketchup pro 2016 16.1.1449 64 bit | windows 10 pro | i7-3770k @3.5 GHz | 16gb ram | gtx 780 ti / gtx 980 ti | nvidia driver 368.39

              1 Reply Last reply Reply Quote 0
              • Didier BurD Offline
                Didier Bur
                last edited by

                Adding a small leader to the text would solve the problem (if you don't mind having such text)

                For instance:
                text = model.active_entities.add_text "your_text_here", point, Geom::Vector3d.new(0,0,10)

                increase vector.z value to get greater leader. What I often do is to have the same value for text height and vector.z value
                Hope this helps,

                DB

                1 Reply Last reply Reply Quote 0
                • J Offline
                  Jorgensen
                  last edited by

                  Thanks Didier - I added point.z = point.z + 6 - this helped 😄

                  Jorgensen

                  sketchup pro 2016 16.1.1449 64 bit | windows 10 pro | i7-3770k @3.5 GHz | 16gb ram | gtx 780 ti / gtx 980 ti | nvidia driver 368.39

                  1 Reply Last reply Reply Quote 0
                  • Didier BurD Offline
                    Didier Bur
                    last edited by

                    BTW, your way of calculating (converting from inches2 to m2) areas is quite strange.

                    $area = (object.area / (39.3700787*39.3700787)).round
                    $text = "#{object.layer.name}\n#$area m2"
                    

                    Try this:

                    $text=Sketchup.format_area object.area
                    

                    Whatever unit the user has set, area (numeric) will be converted to this unit (string) and a ² is added to the text as well 😍

                    DB

                    1 Reply Last reply Reply Quote 0
                    • J Offline
                      Jorgensen
                      last edited by

                      Hi All

                      Thanks for your input.

                      @Didier
                      I have tried that - belive me - but I don't no why, but if I do an Object.area on a face that is 1000x1000mm I get an area of 1,550m2 ? And I have setup units in Model Info - strange ???

                      Another problem. If I doubbleclick the mouse I get a 'attaced' text, that keeps the position inside the face, even if I move the sides. This does not happen when using Object.add_text 😞 does any know if it is possible to achieve this by script ?

                      What I'm trying to create is a small script that has the function as I have tried to sketch on the attached image. This would be very useful for me when sketching plans 😄

                      The next problem - how do I get group names, add listing them inside a group and adding text inside this group - a lot to learn..... 😞


                      Areas.jpg

                      sketchup pro 2016 16.1.1449 64 bit | windows 10 pro | i7-3770k @3.5 GHz | 16gb ram | gtx 780 ti / gtx 980 ti | nvidia driver 368.39

                      1 Reply Last reply Reply Quote 0
                      • Didier BurD Offline
                        Didier Bur
                        last edited by

                        Jorgensen,
                        Try attached script.
                        Acces it via context menu, when a single face is selected in the model.
                        It creates a formatted text on a layer "Areas".

                        For the rest, I don't understand exactly what you mean (groups, and so)...


                        txt_area.rb

                        DB

                        1 Reply Last reply Reply Quote 0
                        • J Offline
                          Jorgensen
                          last edited by

                          Hi Didier

                          I will have a look at the script.

                          What I main by groups. Is, that I have:

                          • a ground level wich is on Layer 00
                          • first floor in layer 01

                          On layer 00 (ground level), I would like a group that contains a 'area group' for each room, Kitchen, livingroom, and so on... .Each areagrop should have the name of the room, so that a script, can update the Text and area.

                          So, in the maingroup on layer 00, holds a text (on layer 0t Text) that says kitchen size ...., and a group named Kitchen (on layer 0A Area, so it can be turned off).

                          A bit dificult to explain 😞

                          Jorgensen

                          sketchup pro 2016 16.1.1449 64 bit | windows 10 pro | i7-3770k @3.5 GHz | 16gb ram | gtx 780 ti / gtx 980 ti | nvidia driver 368.39

                          1 Reply Last reply Reply Quote 0
                          • Didier BurD Offline
                            Didier Bur
                            last edited by

                            OK, I understand.
                            This is doable, but I have not much time to help you by now 😢
                            Remind me...

                            DB

                            1 Reply Last reply Reply Quote 0
                            • J Offline
                              Jorgensen
                              last edited by

                              Hi Didier

                              Thank - you have allready helped. I'll se what I can fix myself.

                              By the help from this forum, it might be possible 😄

                              Jorgensen

                              sketchup pro 2016 16.1.1449 64 bit | windows 10 pro | i7-3770k @3.5 GHz | 16gb ram | gtx 780 ti / gtx 980 ti | nvidia driver 368.39

                              1 Reply Last reply Reply Quote 0
                              • J Offline
                                Jorgensen
                                last edited by

                                Hi

                                I have a question about the Sketchup.format_area utility.

                                My model is in mm, but I would like the result to be in m2 not as Sketchup.format_area shows mm2 - is this somehow possible ?

                                Thanks

                                sketchup pro 2016 16.1.1449 64 bit | windows 10 pro | i7-3770k @3.5 GHz | 16gb ram | gtx 780 ti / gtx 980 ti | nvidia driver 368.39

                                1 Reply Last reply Reply Quote 0
                                • J Offline
                                  Jorgensen
                                  last edited by

                                  Its now going the right way... 😄

                                  I have one question.
                                  I have a group on each level of the building (the levelGroup). Each levelGroup contains a number of groups, that holds info for each room, the area and name. roomGroups.

                                  I then doubbleclick, and get inside a levelgroup, and update the roomGroups.

                                  To keep track of the roomGroups I use:
                                  target = Sketchup.active_model.active_entities;
                                  $areaObjects.push target.add_text text, coordinates

                                  I then have an array $areaObjects, that cointain all the text added (roomGroups).
                                  If I wan't to delete/update all the text, I can read the array again and then erase! them, but this will delete all the text on in all levelGroups.

                                  Is there a way to tjek if the roomGroup is inside the active group ?

                                  Thanks
                                  Jorgensen

                                  sketchup pro 2016 16.1.1449 64 bit | windows 10 pro | i7-3770k @3.5 GHz | 16gb ram | gtx 780 ti / gtx 980 ti | nvidia driver 368.39

                                  1 Reply Last reply Reply Quote 0
                                  • Didier BurD Offline
                                    Didier Bur
                                    last edited by

                                    @unknownuser said:

                                    I would like the result to be in m2 not as Sketchup.format_area shows mm2 - is this somehow possible ?

                                    Yes:
                                    Switch to meters unit just before the format_area instruction, then switch back to mm:

                                    old_unit=Sketchup.active_model.options["UnitsOptions"]["LengthUnit"]
                                    Sketchup.active_model.options["UnitsOptions"]["LengthUnit"]=4
                                    
                                    then_call_the_format_area_instruction_here
                                    (result is a string so it would'nt be affect by later changes)
                                    
                                    Sketchup.active_model.options["UnitsOptions"]["LengthUnit"]=old_unit
                                    (to switch back to mm in your case
                                    

                                    DB

                                    1 Reply Last reply Reply Quote 0
                                    • J Offline
                                      Jorgensen
                                      last edited by

                                      Hi Didier

                                      Thanks for your reply. Just the way I would do, I just could'nt find the settings in Ruby.

                                      One problem however, the text now becomes 14 Meters2 - should be 14 M2 - I guess I'll have to do somekind ereg_replace....

                                      Thanks for your help.
                                      Jorgensen

                                      sketchup pro 2016 16.1.1449 64 bit | windows 10 pro | i7-3770k @3.5 GHz | 16gb ram | gtx 780 ti / gtx 980 ti | nvidia driver 368.39

                                      1 Reply Last reply Reply Quote 0
                                      • J Offline
                                        Jorgensen
                                        last edited by

                                        Easy area = area.sub("eters ", "") 😄

                                        This is fun 😍

                                        sketchup pro 2016 16.1.1449 64 bit | windows 10 pro | i7-3770k @3.5 GHz | 16gb ram | gtx 780 ti / gtx 980 ti | nvidia driver 368.39

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

                                          I did an AreaFormat tool a while ago... see: http://www.sketchucation.com/forums/scf/viewtopic.php?p=12808#p12808
                                          It could easily be adjusted to suit your current units if they are not listed...

                                          TIG

                                          1 Reply Last reply Reply Quote 0
                                          • J Offline
                                            Jorgensen
                                            last edited by

                                            Thanks TIG - I'll have a look at it...

                                            Right now I have a problem, actual the last before I can use the script at work...

                                            I use this to tjek and delete objects in the active group:
                                            def tmAreaDelete
                                            objects_active = Sketchup.active_model.active_entities
                                            for object in objects_active
                                            if($areaObjects.include?object)
                                            object.erase! unless object.deleted?
                                            $areaObjects.delete object
                                            end
                                            end
                                            end

                                            What teases me, is I have to run the tmAreaDelete tree times to delete all text objects - and I just can't se why 😞 It works if I skip the line '$areaObjects.delete object' but that can't be a good solution.

                                            Jorgensen

                                            sketchup pro 2016 16.1.1449 64 bit | windows 10 pro | i7-3770k @3.5 GHz | 16gb ram | gtx 780 ti / gtx 980 ti | nvidia driver 368.39

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

                                            Advertisement