sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Can you get a list of OSX fonts somehow?

    Scheduled Pinned Locked Moved Developers' Forum
    110 Posts 6 Posters 13.9k Views 6 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.
    • thomthomT Offline
      thomthom
      last edited by

      Tried to output to file:

      fc-list : family >> ~/Desktop/fonts.txt

      Empty when run from within SketchUp, populated when run in a native console.

      Something is messed up with the messaging system! 😞

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

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

        system(fc-list : family | out) ?
        running out of permutations...

        TIG

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

          Won't that just list fonts with "out" in them?

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

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

            The 'grep' is for pattern matching...
            The | pipes/passes the output to something else ['out'].
            What do you call the 'output' on a MAC ??
            The > puts the output into a file.
            The >> appends the output to a file.
            How do you 'pass/send' something ?

            TIG

            1 Reply Last reply Reply Quote 0
            • D Offline
              driven
              last edited by

              TT
              what osx are you running.
              'shell' change to AT&T version with 10.5 , so the syntax needs to be checked

              FontBook has had lots of revisions/additions
              and those osascripts run it in the background, take miliseconds on my mac.

              the nice thing is people could set a 'SU 3D Font Collection in fontbook and you can allow them to use just those
              john

              learn from the mistakes of others, you may not live long enough to make them all yourself...

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

                @driven said:

                what osx are you running.

                10.5

                @driven said:

                'shell' change to AT&T version with 10.5 , so the syntax needs to be checked
                But it works in the system console, and it works from IRB calling system command - but not from SketchUp calling system command.

                @driven said:

                FontBook has had lots of revisions/additions
                and those osascripts run it in the background, take miliseconds on my mac.

                Mine took a noticeable lag the first time I ran it, but quick the next runs. And Font Book's icon appeared in the dock.

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

                1 Reply Last reply Reply Quote 0
                • D Offline
                  driven
                  last edited by

                  @thomthom said:

                  But it works in the system console, and it works from IRB calling system command - but not from SketchUp calling system command.

                  it is possible to get an output to Ruby Console using echo <dev/nul, but I need to dig thru for a working example..

                  @unknownuser said:

                  Mine took a noticeable lag the first time I ran it, but quick the next runs. And Font Book's icon appeared in the dock.

                  I think I would run only once, hold the list in the plugin, but add an update function/item for people who add fonts to FontBook [very few]...
                  added to the end of the osascript should close it after use -e 'tell application "Font Book" to quit' -e 'end'
                  john

                  learn from the mistakes of others, you may not live long enough to make them all yourself...

                  1 Reply Last reply Reply Quote 0
                  • D Offline
                    driven
                    last edited by

                    I've been trying loads of different ways to get the exact font list that SU shows under 'Window' >> 'Show Fonts' all 297 on my mac, this is by far the easiest

                    macFonts=[]
                    macFonts=(`osascript -e 'tell application "Font Book" to set macFonts to name of every font family'`).split(",").uniq.each {|a| a.strip! if a.respond_to? ;strip! }.sort
                    quitFontBook=(`osascript -e 'tell application "Font Book" to quit'`)
                     if macFonts.length > 1
                     then quitFontBook
                     end
                    macFonts.length
                    

                    john

                    learn from the mistakes of others, you may not live long enough to make them all yourself...

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

                      I'll try it on my mac

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

                      1 Reply Last reply Reply Quote 0
                      • D Offline
                        driven
                        last edited by

                        @thomthom said:

                        I'll try it on my mac

                        when you do...
                        For seeing if they all will work from code, I've been trying to make a '3d Font Sampler' using the 'macFont' array for both the 'string' and 'font' and the index number for 'z' position, but I keep screwing it up... could you cobble something together? or pointers...

                        another way to get the SU Font List, but not in ruby

                        tell application "Sketchup"
                        	activate
                        end tell
                        
                        tell application "System Events"
                        	
                        	if UI elements enabled then
                        		tell process "SketchUp"
                        			click the menu "Window" of menu bar 1
                        			delay 1
                        			click menu item "Show Fonts" of menu "Window" of menu bar 1
                        			delay 1
                        			
                        			tell window "Fonts"
                        				
                        				set results to value of text field 1 of every row of table 1 of scroll area 3
                        				delay 1
                        				
                        			end tell
                        		end tell
                        		tell application "System Events"
                        			tell process "SketchUp"
                        				click the menu "Window" of menu bar 1
                        				delay 1
                        				click menu item "Hide Fonts" of menu "Window" of menu bar 1
                        				delay 1
                        				return results
                        			end tell
                        		end tell
                        	else
                        		tell application "System Preferences"
                        			activate
                        			set current pane to pane "com.apple.preference.universalaccess"
                        			display dialog "UI element scripting is not enabled. Check \"Enable access for assistive devices\""
                        		end tell
                        	end if
                        end tell
                        

                        learn from the mistakes of others, you may not live long enough to make them all yourself...

                        1 Reply Last reply Reply Quote 0
                        • D Offline
                          driven
                          last edited by

                          I managed to get a list to manually test all the fonts [via copy/paste]... they all work
                          but I can't work out how I can have each as a group, or how even how to get SU to just make them...

                          macFonts.each_with_index do |item, index|
                          puts %(Sketchup.active_model.entities.add_3d_text("#{item}" , TextAlignCenter, "#{item}" , true, false, 1.0, 0.0, #{index}, true, 0.05))
                          end
                          

                          works as a puts which I can copy/paste in batches to make, but fails as a direct method

                          macFonts.each_with_index do |item, index|
                          Sketchup.active_model.entities.add_3d_text("#{item}" , TextAlignCenter, "#{item}" , true, false, 1.0, 0.0, #{index}, true, 0.05)
                          end
                          

                          ...why???
                          john

                          learn from the mistakes of others, you may not live long enough to make them all yourself...

                          1 Reply Last reply Reply Quote 0
                          • Dan RathbunD Offline
                            Dan Rathbun
                            last edited by

                            Oh it's just a head-smackin' boo-boo.
                            The z arg takes a Numeric and the index is already a Numeric subclass ( Integer,)
                            so you do not use the #{ ... } string replacement syntax.
                            (But you don't want to stack them vertically, move them -Y so they are all in a column (see below.)

                            Another quirk about add_3d_text(), is that unlike the OEM tool, the Ruby method does not put the primitives into a group.

                            So we encourage you to create group(s) then call the method on the group's Entities collection:

                            macFonts.each_with_index do |item, index|
                            
                              grp = Sketchup.active_model.entities.add_group()
                              grp.entities.add_3d_text( "#{item}", TextAlignCenter, "#{item}",
                                true, false, 1.0, 0.0, 0.0, true, 0.05 )
                              grp.name= item
                              grp.move!( Geom;;Transformation.new(Geom;;Vector3d.new(0,-index,0)) )
                              
                            end
                            

                            I'm not here much anymore.

                            1 Reply Last reply Reply Quote 0
                            • D Offline
                              driven
                              last edited by

                              cheers dan,
                              This is a one off, so dosen't really matter, but out of curiousity
                              as both 3DText and Group generation can lock up the mac, how can I split this into a batch mode, so SU makes first 12, then next 12, then next 12, etc... but still uses the original index for position.
                              Could I need to make a hash using -index%(:#{item}) then split into new arrays of hashes with max items(12), then process those, I was looking at

                              macFonts.each_with_index do |item, index|
                               puts %(#{item}, #{index}).to_a
                               end
                              

                              and then

                              
                              # use as array.chunk
                              class Array
                                def chunk(pieces=2)
                                  len = self.length;
                                  mid = (len/pieces)
                                  chunks = []
                                  start = 0
                                  1.upto(pieces) do |i|
                                    last = start+mid
                                    last = last-1 unless len%pieces >= i
                                    chunks << self[start..last] || []
                                    start = last+1
                                  end
                                  chunks
                                end
                              end
                              

                              then

                              macFonts.chunk 12
                              

                              then process those, but I do get lost... john

                              learn from the mistakes of others, you may not live long enough to make them all yourself...

                              1 Reply Last reply Reply Quote 0
                              • D Offline
                                driven
                                last edited by

                                Hi dan,

                                @unknownuser said:

                                It is very bad to modify base classes. (spanky spanky)

                                it a one off, and the stand alone version was more complex for me to use...

                                # use as standalone function
                                def chunk_array(array, pieces=2)
                                  len = array.length;
                                  mid = (len/pieces)
                                  chunks = []
                                  start = 0
                                  1.upto(pieces) do |i|
                                    last = start+mid
                                    last = last-1 unless len%pieces >= i
                                    chunks << array[start..last] || []
                                    start = last+1
                                  end
                                  chunks
                                end
                                

                                I also do most my testing in a separate version of SU with Pluggins turned off, and often check if methods are defined already first...

                                that works at the about the same speed as the first, not too slow, considering there are 297 fonts.

                                what i was musing, was, is there a way to have SU make one, return true, make next, return true, then next, etc...
                                so each operation is a single font... To see if that's actually faster or not. In theory it should be slower, but SU appears to bog down exponentially when I do them manually in sets of 6 V 12 V 18 V 24, and over 24 takes longer to run then the whole lot from either of your scripts.

                                Another mac 3D Font oddity I have noticed:

                                when using the native tool, I can make "" as 3D text,
                                which should be the apple icon although it may show as the windows icon on yours.

                                If I use code to try and generate the 2D Text (from console or a webdialog) although I see 'it' in the input window, I get some bizarre encoded string.

                                cheers again
                                john

                                learn from the mistakes of others, you may not live long enough to make them all yourself...

                                1 Reply Last reply Reply Quote 0
                                • Dan RathbunD Offline
                                  Dan Rathbun
                                  last edited by

                                  @driven said:

                                  what i was musing, was, is there a way to have SU make one, return true, make next, return true, then next, etc... so each operation is a single font...

                                  Set chunk = 1

                                  @driven said:

                                  ..., but SU appears to bog down exponentially when I do them manually in sets of 6 V 12 V 18 V 24, and over 24 takes longer to run then the whole lot from either of your scripts.

                                  It's a caveat of using high quality. A lot of primitives are going onto the undo stack.
                                  The higher the number of elements in the model, the slower things get.
                                  I think we already tried saving the model between operations (to clear the undo stack,) BUT tests showed it did not speed things up.

                                  @driven said:

                                  ... when using the native tool, I can make "" as 3D text,
                                  which should be the apple icon although it may show as the windows icon on yours.

                                  If I use code to try and generate the 2D Text (from console or a webdialog) although I see 'it' in the input window, I get some bizarre encoded string.

                                  It could be a unicode UTF16 codepoint. Ruby is UTF8.

                                  There are sometimes tricks you can do with Array.pack and String.unpack.

                                  Code-wise, try to save .rb files in "UTF8 (without BOM)" aka "ANSI as UTF8" encoding. I don't know what your Mac code editor calls it, but that's what Notepad++ does.

                                  I'm not here much anymore.

                                  1 Reply Last reply Reply Quote 0
                                  • D Offline
                                    driven
                                    last edited by

                                    @dan rathbun said:

                                    It could be a unicode UTF16 codepoint. Ruby is UTF8.

                                    I often use them as puts on mac only scripts to remind me it won't work on a PC, they show up in console returns, so that side is ok, also I can make 3D Text versions with the native tool (which I thought was based on Todd's 3D TextTool ruby)
                                    WebDialogs are UTF8 as well and they show up htere in most fonts [some don't have the charset]

                                    @unknownuser said:

                                    There are sometimes tricks you can do with Array.pack and String.unpack.

                                    I looked into .encode to see if I could add a conditional to make one from code, i'll look into .pack... cheers

                                    @unknownuser said:

                                    Code-wise, try to save .rb files in "UTF8 (without BOM)" aka "ANSI as UTF8" encoding. I don't know what your Mac code editor calls it, but that's what Notepad++ does.

                                    everything 'ruby' on the mac is "UTF8 (without BOM)" with unix line endings, even 'pasteBoard', 'Terminal' and 'Applescript editor' are since OSX 10.5.

                                    It's only some downloaded rubies that need changing, although if it's just line endings any will work in SU.
                                    john

                                    learn from the mistakes of others, you may not live long enough to make them all yourself...

                                    1 Reply Last reply Reply Quote 0
                                    • Dan RathbunD Offline
                                      Dan Rathbun
                                      last edited by

                                      @dan rathbun said:

                                      @driven said:

                                      what i was musing, was, is there a way to have SU make one, return true, make next, return true, then next, etc... so each operation is a single font...

                                      Set chunk = 1

                                      I really meant, set:
                                      chunksize = 1

                                      I'm not here much anymore.

                                      1 Reply Last reply Reply Quote 0
                                      • Dan RathbunD Offline
                                        Dan Rathbun
                                        last edited by

                                        It is very bad to modify base classes. (spanky spanky)

                                        This should do the job:

                                        chunksize = 12
                                        chunk = 1
                                        limit = macFonts.length
                                        model = Sketchup.active_model
                                        
                                        fsize = 1.0
                                        linespacing = 1.2
                                        
                                        bold = true
                                        italic = false
                                        thick = 0.05
                                        filled = true
                                        quality = 0.0
                                        
                                        i = 0
                                        
                                        while i < limit
                                        
                                          begin
                                            #
                                            model.start_operation("3D Fontnames (#{chunk})")
                                              #
                                              chunksize.times do |n|
                                                #
                                                break if i == limit
                                                #
                                                item = macFonts[i]
                                                grp = model.entities.add_group()
                                                grp.entities.add_3d_text( "#{item}", TextAlignCenter, "#{item}",
                                                  bold, italic, fsize, quality, 0.0, filled, thick )
                                                grp.name= item
                                                grp.move!( Geom;;Transformation.new(Geom;;Vector3d.new(0,-(i*linespacing),0)) )
                                                #
                                                i += 1
                                                #
                                              end # chunk
                                              #
                                            model.commit_operation()
                                            #
                                          rescue Exception => e
                                            puts("\n*** macFonts group Error! ***")
                                            puts("  i = #{i}")
                                            puts("  chunk = #{chunk}")
                                            puts("  font = #{macFonts[i]}\n")
                                            model.abort_operation()
                                            puts("Error #<#{e.class.name}; #{e.message}>")
                                            puts(e.backtrace) if $VERBOSE
                                            raise
                                          end
                                        
                                          chunk += 1
                                        
                                        end # while
                                        

                                        EDIT: Added a few Exception messages, and option vars before iteration.
                                        EDIT(2): Added linespacing var.

                                        I'm not here much anymore.

                                        1 Reply Last reply Reply Quote 0
                                        • Dan RathbunD Offline
                                          Dan Rathbun
                                          last edited by

                                          EDIT(2) previous code post: Added linespacing var.

                                          I'm not here much anymore.

                                          1 Reply Last reply Reply Quote 0
                                          • D Offline
                                            driven
                                            last edited by

                                            cheers again,
                                            linespacing is a nice touch.
                                            all the code runs, returns nil. then draws view with the new groups, changing chuncksize doesn't alter that.
                                            it doesn't take too long.
                                            only two fonts don't fully form, may be the size, but not bad really.

                                            so, the main purpose was to check that the osascript fonts were the right one, and they are...

                                            and I learnt a little ruby
                                            thanks dan
                                            john

                                            learn from the mistakes of others, you may not live long enough to make them all yourself...

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

                                            Advertisement