DesignCAD 3D Max 2027 box
Now available

DesignCAD 2027

Hatches that follow their boundaries, an on-screen dial to turn your model, and a way to find any command by name, in a clean Windows 11 look.

Constructing a Text Block from random text

Started by samdavo, April 18, 2013, 01:34:12 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

samdavo

ok - Suppose you have some text that is randomly aligned / justified.
Here are 3 macros, called LJ, CJ, and RJ , (left centre and right justification)...

'LJ = Left Justification of text or lines etc in XY plane
>AlignObjects
{
  <Type 0
  }


'CJ = Centre Justification of text or lines etc in XY plane
>AlignObjects
{
  <Type 4
  }


'RJ = Right Justification of text or lines etc in XY plane
>AlignObjects
{
  <Type 1
  }


TO let you experiment with these, I enclose a drawing with randomly justified text, then after applying each of these macros  -   but I want to move on to a more complicated matter - namely the title of this thread  - more to follow...

samdavo

#1
Now, I started to think, that is so close to a "Text-Block-Reconstruction-from-random-text", that I thought , why not write a macro to do just that?

Firstly I will say this is only 50%Tip  (and the other half is 50% trick lol).
Reason being, I haven't completed (or started) the macro I plan to write "one day".
Reasons for not writing it ...  well they are threefold, no fourfold ...

1. there might be a macro around here already written to do just that(?)
2. it will take me some time to write it, and I bet others here would be much more efficient on that score,
3. I am slipping around on a number of slippery learning slopes at the moment, and want to concentrate on "Paperspace" just now
4. I figure that the macros in the earlier post will help bigtime to tidy up a lot of "almost-text-blocks", which might be enough for some (me anyway) for the time being.

There are macros out there which can be cannibalised and combined, ...   (I'm thinking of DT's Flatten - and also Fix text) ...  I'll firstly explain what I believe to be the required flow chart...

MISSION then is as follows :-  To write a macro to tidy up a block of text that is written in the X direction (and in the XY plane)
- left justify text, and also
- make the lines equally separated ( at 2 x text size) in the Y direction,  and also
- make all text the same size, colour and layer. 

a. select text (only) - say max 10 lines - (or 20 if you prefer)
b. check that it is all 2D text, if not change it to 2D text, also change it all to the current colour and layer
c. count the number of entities in the selection
d. give them numbers in an array from 1 to 10, where the largest y value is line 1 of text, and so on down the text...
e. ask "do you want text size of "n"??,  or just use a typical value in that selection?"...
f. starting with the entity with the greatest y value = entity #1 in the array , hence the top line, (which will be the text size (ts) in the event that nothing is entered for "n" - and it will also be the anchor handle for the textblock),  check the text size, and record the x and y coordinates  (call these xo and yo)
g. go to the next line of text (#2 in the array), interrogate its x- and y-value, set its x value to xo;  and its y value to
(yo - 2.ts).
h. continue through all the text items.  (yo-4ts = third line, and so on).  I believe  at this point you have turned the random text into a TextBlock (2 cents), INCLUDING equal spacing.
I. regen etc.

PS If you then want to centre-justify it, run the macro in the original post.

samdavo

#2
PS slightly different topic, but I also offer this macro which basically brings "edit/selection/align" to your fingertips.  NB I am talking 2D only.  Kinda important because the macro calls up "Align type6", which gives a different result when you are in 2D than if you are in 3D.

The attached drawing includes two white "groups" (in layer #1), with a red cross (in a locked layer #2).

Now when you select both white groups, (or if you prefer, just select all), and run the macro "Align2D", then depending on which alignment-option you pick - you will end up with them in left right top or bottom corners ( or centre?).

Now, one thing that I find interesting... when I tried this in 3D, (refer the thread talking about aligning plates in a 3D stack - all of which is based on ideas put forward by Minstrel - thanks m8) , there was no predictability as to WHERE the entities would align, say in the X direction - and often it seemed to be the "average X location".

Yet here there is no doubt, the leftmost entity determines where they all line up   if you click align to the left sketch, etc.  - for discussion as necessary.

PS Appreciate any advice by others who might know what they are talking about lol. 

PS that macro is deadly simple - using Align type6, which , as I say above, gives a different result for 2D than for 3D, probably because it is not specifically covered in 2D (?)

'Align 2D is macro to give options for aligning text or lines
'or other entities in 2D, with options given in the alignment window
'basically a quick access to 'edit-selection-alignment'
>AlignObjects
{
  <Type 6
  }

prl

If you take your random text and group it, you can use the mtext.d3m routine below.  It will take that group of text and dump it into the DesignCAD Text Block  dialog box.  You can edit the text, change alignments etc. and position it as you wish.  Note the DesignCAD entity order in which you created your text is important when grouping text for this macro.  In other words, if you created your second block text sentence before you wrote your first sentence, the text dumped into the DesignCAD text block command will be in that order (backwards.) I use a more complicated version of this routine to dump text into an external text editor but perhaps this gives you a start on your version.



'Program mtext.d3m

dim textline$(500), ecount(500)

include "dcadalias.d3i"
Sys(33) = 1 'truetype/vector toggle
Sys$(95) = "Simplex2w"

if sys(1)=0 and sys(80)=0 then end

if sys(1) = 1 then
    >PointSelect
     {   
     <Type 1
     <Usepresetpoints
     }
    sys(1)=0
endif

sys(1)=0

count=0
first=1
maxsel= sys(80)

for j = 1 To maxsel
    getselect j, ent
    entity ent
    getattr ent, type, select, laynum, grouporig, rc, gc, bc

    if type = 3 or type = 13 then
       if first = 1 then
          pointval x0 y0 z0 1
          pointval x1 y1 z1 3
          dy = y1 - y0
          dx = x1 - x0

          Query T_Angle, ang
          Query T_SIZE, tsize
          Query Ent_Layer, elayer

          sys(12) = tsize
          first = 0
       endif
       count=count+1
       ecount(count)= ent
       textline$(count)=sys$(1)
    endif

next j

sys(80)=0

for j = 1 to count 'reselect only text entities
   getattr ecount(j), type, select
   putattr ecount(j), type, select
next j

>erase
{
}

tsize = round(tsize*120)/120

>TextBlock
{
<Pointxyz [x1,y1,z1]
  for j = 1 to count
      <Text [textline$(j)]
  next j
<Type 0 'always want normal text, not exploded lines 
<Angle [ang]
<Size [tsize]
<Distance .5
<incomplete
}

sys(80)=0
sys(1)=0

regen   
end

samdavo

#4
bRILLIANT, thanks prl.
(PS has that already been discussed here ?  An old thread maybe?  I couldn't find it in a quick search ?)

PPS It is telling me I need "dcadalias.d3i"  (?)  Not quite there yet.

prl

Quote from: samdavo on April 18, 2013, 03:26:37 AM
bRILLIANT, thanks prl.
(PS has that already been discussed here ?  An old thread maybe?  I couldn't find it in a quick search ?)

Probably not discussed here.  Never liked the way DesignCAD treated blocks of text and my drawings always have many paragraphs of text.

Even now I consider the multi-line text editor to be a pain.  Rolled my own many moons ago using a decent external text editor.  I only use the DesignCAD "block text" command to position the text.  So in essence, I suck the text out of DesignCAD into the editor, and then when done adding/deleting text, dump it back into the "block text" dialog using similar code to what you see above.

Regarding the other issues, the "dcadalias.d3i" is something that should be in your macro directory.  If not, I've attached the file.

samdavo

Thanks prl
adding that makes all the difference - and much better than my proposed macro (being edible etc)
so I'll withdraw my offer to write that macro lol
cheers
sam