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

    [Plugin] importDXFtext

    Scheduled Pinned Locked Moved Plugins
    165 Posts 18 Posters 84.8k Views 18 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.
    • uwesketchU Offline
      uwesketch
      last edited by

      I tested v4.4 with the testfile "dxf issues with special chars.dxf".
      The displacement of rotated MTexts is the same as with v4.2 reported in this post:

      http://sketchucation.com/forums/viewtopic.php?f=323&t=23002&p=678093#p678060

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

        Here's v4.5
        I'm hopeful it addresses the alignment / rotation weirdness...
        https://sketchucation.com/pluginstore?pln=importDXFtext
        Please test and report back...

        TIG

        1 Reply Last reply Reply Quote 0
        • uwesketchU Offline
          uwesketch
          last edited by

          The first test with the imported file "map with Isocontours TEXT.dxf" showed no differences to the dxf file anymore. Very nice!

          Also the file "dxf issues with special chars.dxf" did not show position diffs due to rotation. But there is another issue, which I will report in a later post, as it does not have to do with rotation.

          However I have another file called "map with Isocontours.dxf" where all text are MTEXTs. (see attachment)
          99% are at the right position, but the imported text is slightly wider than the text in dxf.
          I checked the dxf and saw, that these MTEXTs have a "width factor" of 0.84 defined. This factor pretty much explains the difference. It is defined on style level. The style is called "ERSTELLTER_STIL_1" and in code 41 you find the 0.84. I think the factor could be applied as well in SketchUp by using the "Scale feature".
          Text scaling issue:
          During import, this style is also read and the factor properly reported as WidthFactor, but it is not applied.
          The console output is:

          
          2 DXF STYLES;
          
          Name = ERSTELLTER_STIL_1
          Height = 0.0
          WidthFactor = 0.84
          Oblique = 0.0
          Flipped = 0
          FontFile = 
          FontName = Arial
          Color = 256
          

          In below screen shot, green is the DXF file, red the imported 3DText.
          DXF v4.5 MTEXT scaling issue 1.png

          Only two MTEXTS are not right positioned:
          It seems it has to do with the letters qpgjy, but this time it is shifted downwards.

          In below screen shots, green is the DXF file, red the imported 3DText.

          DXF v4.5 MTEXT scaling and shifting issue 2.png

          DXF v4.5 MTEXT scaling and shifting issue 3.png


          map with Isocontours.dxf

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

            Here's v4.6
            https://sketchucation.com/pluginstore?pln=importDXFtext
            I think it addresses the Mtext dropped string problem if there are certain dropped letters like 'g'.
            The width-scaling should also now works. [Also the DXF Style 'Standard' is now applied more logically]
            Some add string formatting with residual \A characters is also improved ?

            Please report back...

            TIG

            1 Reply Last reply Reply Quote 0
            • uwesketchU Offline
              uwesketch
              last edited by

              Sorry, took a bit longer this time.

              I dislocated for the weekend and have to install version 4.5 and 4.6 on another PC.
              Somehow I have the impression that v4.5 is perfect for TEXT, but 4.6 not anymore.
              But let me test all files in details and come back.

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

                For v4.6 it seems to work OK with TEXT for me, but I welcome your insights / comments ...

                In passing, I have now added the text's box-width to MTEXT, but currently do nothing with it.
                Usually it's 0.0, but if the text-string is long it can have a dimension.
                However using that to divide up and wrap the string using \n is fraught with issues - like how do we decide where to break etc... So I've left it along, for now...

                TIG

                1 Reply Last reply Reply Quote 0
                • uwesketchU Offline
                  uwesketch
                  last edited by

                  I think I found the issue regarding TEXT:
                  in v4.5 you take the font Arial Narrow, as indicated int he DXF "map with Isocontours TEXT.dxf".
                  In v4.6 you take the font Arial.
                  The screen shot below shows in green the original DXF, in black the text imported with v4.6
                  The text in grey above is a 3DText I created with font Arial. The text in grey at the bopttom is a 3DText I created with font Arial Narrow (same as when imported with v4.5.
                  Can you change that back for TEXT to how it worked in v4.5?
                  DXF v4.6 Font Issue.png

                  Oblique angle: Where we will always have a difference is the oblique angle. It is in this DXF 15° - see green text above. As there is no corresponding feature in SketchUp 3DText and the scale tool cannot be used, an approximation would be making the text italic. However italic has an obliquity angle of only 9°.

                  MTEXT in "map with Isocoutours.dxf" imported with v4.6:
                  This looks now perfect!

                  MTEXTs and ATEXT in "dxf issues with special chars.dxf" imported with v4.6:
                  also here all looks very good. Great.
                  The "Nische für späteren Duscheneinbau is now as well shifted to the right height.
                  Also the text with "Masse am Bau:"

                  text word wrap: Indeed, the next step would be to do the text word wrap. I have written down a few ideas. From a simple approximation to a luxury implementation.
                  Unfortunately I forgot to take the notes with me. So I can only send it next week.
                  But I remember the simple approach 😄

                  • Get the width of the box (BoxWidth) from code 41 not being empty/missing and not 0
                  • calculate an average character width (CharWidth). This is done by taking 2/3 of the letter height - which we know from the DXF.
                  • calculate the number of characters fitting into the width of the box:
                    NoOfChars = BoxWidth / CharWidth
                  • Loop over each line in the MText (= \P delimited string) and wrap this line using some regexp or below piece of ruby:
                  
                  BoxWidth= 660
                  CharHeight = 100
                  CharWidth = CharHeight * 2/3
                  NoOfChars = BoxWidth / CharWidth
                  result = ""
                  word_array = 'To be or not to be-that is longwordwise the question'.split(/\s/)
                  line = word_array.shift
                  word_array.each do |word|
                    if (line + " " + word).length <= max_length
                      line << " " + word
                    elsif word.length > max_length
                      result << line + "\n" unless line.empty?
                      line = word
                    else
                      result << line + "\n"
                      line = word
                    end
                  end
                  result << line
                  puts result
                  
                  

                  Maybe you can already do something with it and maybe it is even enough.

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

                    Thanks for the word-wrap ideas...
                    I had some similar ideas...
                    I'll investigate further...

                    The 'Font' name is taken from the DXF text's entries [3] from Style 1000.
                    in ...TEXT.dxf 'Arial Narrow' is the font in the STYLE 'STANDARD'
                    It defaults to 'Arial' if the font is not available on your PC computer.
                    But 'Arial Narrow' should be available !?

                    Although the ...TEXT.dxf includes that Font in a Style, it is not picked up in the file parsing...
                    But some other Fonts are e.g. 'Cadastra' and 'Univers'...
                    It's because the names 'Standard' & 'STANDARD' are used in the file in different lines...
                    Now trapped...

                    Here's v4.7
                    https://sketchucation.com/pluginstore?pln=importDXFtext

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • uwesketchU Offline
                      uwesketch
                      last edited by

                      Well done. I looked at the "map with Isocontours TEXT.dxf" and now all fine!
                      The other imported dxf files are unchanged good.
                      Looking forward to see how the word wrapping works.

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

                        Here's v4.8
                        https://sketchucation.com/pluginstore?pln=importDXFtext
                        MTEXT with overly long text strings, but with a predefined 'width-box', now get extra \n's added to split them into shorter strings.
                        Thanks for your ideas which helped me crystallize my code...

                        TIG

                        1 Reply Last reply Reply Quote 0
                        • uwesketchU Offline
                          uwesketch
                          last edited by

                          Instead of assuming an average width of a character, we could also do it precisely without having to change the code sent earlier too much. Just create the 3Dtext for each line and word, get the width and then compare this with the BoxWidth. It takes now more time to calculate the word wrap.

                          
                          boxwidth= 600
                          charheight = 100
                          result = ""
                          word_array = 'To be or not to be-that is longwordwidest the question'.split(/\s/)
                          line = word_array.shift
                          word_array.each do |word|
                            txt = line + " " + word
                            group = Sketchup.active_model.entities.add_group
                            group.entities.add_3d_text(txt, TextAlignLeft, "Arial Narrow",true, false, CharHeight, 0.0, 0, false, 0)
                            txtwidth=group.bounds.width
                            group.erase!
                            group = Sketchup.active_model.entities.add_group
                            group.entities.add_3d_text(word, TextAlignLeft, "Arial Narrow",true, false, charheight, 0.0, 0, false, 0)
                            wordwidth=group.bounds.width
                            group.erase!
                            if txtwidth <= boxwidth
                              line << " " + word
                            elsif wordwidth > boxwidth
                              result << line + "\n" unless line.empty?
                              line = word
                            else
                              result << line + "\n"
                              line = word
                            end
                          end
                          result << line
                          puts result
                          
                          
                          1 Reply Last reply Reply Quote 0
                          • uwesketchU Offline
                            uwesketch
                            last edited by

                            OOps, our messages just crossed.
                            Cool. I will have a look, thanks.

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

                              That was the type of solution I was originally looking at, but seems long winded...
                              The method I used is pretty much like your earlier idea...
                              I think - 'sufficient is fit' - to quote someone...

                              TIG

                              1 Reply Last reply Reply Quote 0
                              • uwesketchU Offline
                                uwesketch
                                last edited by

                                Somehow the wordwrap is now based on a too narrow box. What is the width you take for below two cases (file "dcf issues with special cahrs.dxf")?
                                It seems it is that narrow, that each word is on a new line. Even two short words like "vor der".
                                Here the "sufficient" is too tight 😉

                                DXF v4.8 WordWrap Issuse 1 Nische.png

                                DXF v4.8 WordWrap Issuse 2 Masse.png

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

                                  I don't get that !
                                  What dxf file & units are you testing ?
                                  I think I'm using the same one ??
                                  But I have noticed the \P is not being respected as \n and I'll fix that !
                                  Capture1.PNG
                                  Capture2.PNG

                                  TIG

                                  1 Reply Last reply Reply Quote 0
                                  • uwesketchU Offline
                                    uwesketch
                                    last edited by

                                    I took “m” as import units

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

                                      With 'inches' it works - I can trap that !?
                                      Inches defaults from the DXF's units settings !

                                      TIG

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

                                        Here's v4.9
                                        https://sketchucation.com/pluginstore?pln=importDXFtext
                                        MTEXT with overly long strings originally with \P v \n addressed, also non-specified units no longer affects the words' wrapping.

                                        TIG

                                        1 Reply Last reply Reply Quote 0
                                        • uwesketchU Offline
                                          uwesketch
                                          last edited by

                                          Looks good, except that the line spacing for the text "Masse am Bau" is far to big.
                                          For the "Nische ..." it is better.

                                          In the dxf file, the Text "Nische ..." ha a line spacing defined in Code 44 being 0.9381651742200441
                                          The Text "Masse am Bau...." has a line spacing defined with Code 44 being 0.6070814881175318

                                          Do you catch this line spacing?

                                          Assuming, the line spacing is not considered for the import:

                                          It seems the line spacing in the imported text "Nische..." is 1 and in the DXF it is defined as 0.938. So that looks good.
                                          DXF v4.9 WordWrap Issuse 1 Nische.png

                                          But for the long text "Masse ..." the imported line spacing is much more than 1.
                                          In below picture, the green text is the text from the DXF with line spacing 0.6.
                                          The yellow text I created in SketchUp with the "3DText" tool (line spacing 1, I assume).
                                          The red text is the imported text.
                                          The letter height of the green text is 125mm, the yellow text is 116mm, the red text 118mm.
                                          The numbers in the picture are the distances between two lines
                                          green: 256mm ( ~391 * 0.6 )
                                          yellow: 391mm
                                          red 460mm (line spacing ~1.16 = 460 / 391)

                                          As the letter height is not exactly the same for all texts, the measured line spacing values above do not perfectly match the formula. (256 should be 0.6 * 391)

                                          My Question: Why is the line spacing of the imported text that big, meaning why is it not 1?
                                          Would it be possible to apply the line spacing as defined in the DXF or do you simply generate the whole 3DText using the add_3d_text command and hence there is no way to indicate a line spacing?

                                          DXF v4.9 WordWrap Issuse 2 Masse.png

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

                                            The text's line spacing is set by the 3d-text, and is fixed.
                                            Why it's different between the manually made version and this tool's seems very odd though.

                                            I see no way of using the dxf's line-spacing setting to adjust the 3d-text in the tool...

                                            So this might be as good as it gets...

                                            TIG

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

                                            Advertisement