COMMAND OR LISP TO INSERT TEXT WITH CRITERIA

COMMAND OR LISP TO INSERT TEXT WITH CRITERIA

mbracciahubbard
Contributor Contributor
902 Views
8 Replies
Message 1 of 9

COMMAND OR LISP TO INSERT TEXT WITH CRITERIA

mbracciahubbard
Contributor
Contributor

i am looking for a solution to my multi-part request.

 

part1)

I am looking for a lisp or command that will:

insert an MTEXT with a specific layer, justify "top center" (also how would i do the same for other justify settings)

 

In addition to this, i'd like to be able to select the insert location for that lisp and have the first line be above the insert location and have the rest go below the set location

 

part2)

I am looking for a lisp or command alias that will change all of my styles (text style, dimstyle, leaderstyle) to specific styles. for example. i have a "details" style for each, i'd like to just click a button (like let's say "1") and have each of them set to the details style, etc for other styles

0 Likes
903 Views
8 Replies
Replies (8)
Message 2 of 9

tatetopggg
Observer
Observer

@mbracciahubbard wrote:

i am looking for a solution to my multi-part request.

 

part1)

I am looking for a lisp or command that will:

insert an MTEXT with a specific layer, justify "top center" (also how would i do the same for other justify settings)

 

In addition to this, i'd like to be able to select the insert location for that lisp and have the first line be above the insert location and have the rest go below the set location

 

part2)

I am looking for a lisp or command alias that will change all of my styles (text style, dimstyle, leaderstyle) to specific styles. for example. i have a "details" style for each, i'd like to just click a button (like let's say "1") and have each of them set to the details style, etc for other styles


For a solution to your two-part request, an AutoLISP script can be created to simplify both tasks. In the first part, the script will insert MTEXT on a specified layer with "Top Center" justification, allowing you to select an insertion point where the first line will appear above the insertion point and subsequent lines below it.

For adjusting other justifications, you can modify the "AttachmentPoint" property within the script according to the desired alignment settings (e.g., 1 for Top Left). The second part involves a script that sets the text, dimension, and leader styles to a specific predefined style with a single command. This can be done by creating a shortcut (like "1") that applies the desired style across all specified settings, allowing for quick changes in your workspace.

0 Likes
Message 3 of 9

Kent1Cooper
Consultant
Consultant

@tatetopggg wrote:.... an AutoLISP script can be created ... the script will insert MTEXT ... with "Top Center" justification, allowing you to select an insertion point where the first line will appear above the insertion point and subsequent lines below it. ....

To respond to a post that says "I am looking for a routine that will do X" by saying only that "a routine to do X could be written," without offering anything that does X, seems less than helpful.  But in this case I think it is also false.  I don't know of a way to have the insertion point of Mtext below the first line only of content, other than in specific conditions under the one justification that does not have the insertion point around the edges somewhere, i.e. Middle-Center justification.  Under that, the first line will appear above the insertion point only if there is more than one line of content, and if there are more than two lines, more than just the first line will be above the insertion point -- part or all of some subsequent line(s) will also be above it.  Only Mtext with two lines of content could fit the description, and only if Middle-Center [not Top-Center] justified.

 

Can you demonstrate how what they are looking for, and what you describe, is possible?

 

[One possible way:  use a Block with a single-line Attribute for the top line, and a multi-line Attribute for whatever subsequent line(s) there may be.  But that would restrict the possibilities compared to Mtext, for editing the content, word-wrapping relative to defining box width, etc.  And an AutoLisp routine to automate it would not involve Mtext, but Insert, requiring that the Block definition exists, etc.]

Kent Cooper, AIA
0 Likes
Message 4 of 9

Sea-Haven
Mentor
Mentor

"justify top center" is yes.

 

Above pick point is yes, you need to know the height of the text being used in the mtext, you can work out a fuzz factor for the shift vertically from the picked point. Which should be close enough for what you want. A style "Standard" text height 2.5 has a line feed of approx 4.2.

 

you can set most values before entering text.

(command-s "mtext")
Multiline Text: First corner for block of text: 
Select Opposite corner for block of text or [Justification/Rotation angle/text Style/text Height/Direction/Width/Line spacing/Columns]: 
0 Likes
Message 5 of 9

ryanatkins49056
Enthusiast
Enthusiast

So I can help out with the first part at least but keep in mind that short of using a whole heap of maths calculations based on your current user settings then I have no idea how to make your insertion point below the fist line.

 

The following will create your MTEXT entity to a specific layer, top centre justification.

 

 

(defun c:mbracciahubbardtext ( / mbrtxtmtxtalpt mbrtxtcontents mbrnewtextent)
  (setq mbrtxtmtxtalpt (getpoint "Pick point for text..."));pick a point on the screen for justification point location of text
  (setq mbrtxtcontents (getstring T "\n Enter text... "));text to be used for entity
  (setq mbrnewtextent
              (entmakex
                (list
                  (cons 0 "MTEXT");(required for entmakex)
                  (cons 100 "AcDbEntity");(required for entmakex)
                  (cons 100 "AcDbMText");(required for entmakex)
                  (cons 10 mbrtxtmtxtalpt);justification point location (required for entmakex)
                  (cons 1 mbrtxtcontents);text string (required for entmakex)
                  (cons 71 2);MTEXT justification
                  (cons 8 "0");layer (enter name of layer, always a string value)
                );(list)
              );(entmakex)
  )
  (entupd mbrnewtextent)
);(defun)

 

 
With the getstring function I have supplied the T argument so spaces can be accepted however as this will create an entity with no formatting don't go over 240 or so characters as then overflow DXF fields will come into play.
 
For more info on the DXF values (particularly field 71 for justification values) refer below
 
Hopefully this will be a good starting place and I've commented alot of it to hopefully help things along.
0 Likes
Message 6 of 9

ryanatkins49056
Enthusiast
Enthusiast

Hello again,

 

So I got a little curious on the math side of things to work out how to get the first line above the point you select. Now keep in mind I am basing this off top justification and the pickpoint/justification point will merely be shifted upward. In that you're not going to have the pick point sitting between lines of text.

 

This will also work on all text sizes ue to the variable being pulled for calculations.

 

(defun c:mbracciahubbardtext ( / mbrtxtmtxtsize mbrtxtmtxtalpt mbrtxtcontents mbrnewtextent mbrtxtmtxtpt mbrtxtmtxtptx mbrtxtmtxtpty mbrtxtmtxtalpty)
  (setq mbrtxtmtxtsize (getvar "TEXTSIZE"));get defualt font size
  (setq mbrtxtmtxtpt (getpoint "Pick point for text..."));pick a point on the screen for justification point location of text
  (setq mbrtxtmtxtptx (nth 0 mbrtxtmtxtpt));get selected X value
  (setq mbrtxtmtxtpty (nth 1 mbrtxtmtxtpt));get selected Y value
  (setq mbrtxtmtxtalpty (+ mbrtxtmtxtpty (* mbrtxtmtxtsize (/ 5 3.))));calculate entire line height for new Y point
  (setq mbrtxtmtxtalpt (list mbrtxtmtxtptx mbrtxtmtxtalpty 0))
  (setq mbrtxtcontents (getstring T "\n Enter text... "));text to be used for entity
  (setq mbrnewtextent
              (entmakex
                (list
                  (cons 0 "MTEXT");(required for entmakex)
                  (cons 100 "AcDbEntity");(required for entmakex)
                  (cons 100 "AcDbMText");(required for entmakex)
                  (cons 10 mbrtxtmtxtalpt);justification point location (required for entmakex)
                  (cons 1 mbrtxtcontents);text string (required for entmakex)
                  (cons 71 2);MTEXT justification
                  (cons 8 "0");layer (enter name of layer, always a string value)
                );(list)
              );(entmakex)
  )
  (entupd mbrnewtextent)
);(defun)
 
Keep in mind as well that this will calculate based off total line length. That is the top of the second line of text will be the point you selected.
0 Likes
Message 7 of 9

Sea-Haven
Mentor
Mentor

A couple of problems (getvar "TEXTSIZE") will return an incorrect value. Depends on text style, my Standard style has a text height of zero, but the default when using MTEXT is 2.5 so it would be better to set the mtext text height to say match a style. If you read my post again a text of 2.5 has a line spacing of 4.2 approximately. text style may change this.

 

So if you pick a point say pt then 

 

 

(setq p2 (mapcar '+ pt (list 0.0 4.2 0.0)))

look at (cons 10 p2) its now 4.2 higher up.

 

Look at dxf (cons 43 textht) maybe.

 

0 Likes
Message 8 of 9

ryanatkins49056
Enthusiast
Enthusiast

I understand that the variable TEXTSIZE can return 0 but would this normally only happen if the defined font itself has a locked font size within the definition itself?

 

Now the code I posted obviously takes into account a variable font size (and admittedly this is from experience as where I work we don't have locked font sizes just the fonts and then a variable height as however needed).

 

I am curious as well if this was in your case @Sea-Haven if you had a larger font size (say 5mm) would you prefer to double the 4.2 to 8.4 or go for some way of calculating the 5-on-3 rule?

(I ask for accuracy calculations with the decimal point)

0 Likes
Message 9 of 9

Sea-Haven
Mentor
Mentor

Using dumpit returns the property " LineSpacingDistance" which is what you want to adjust the inserted position, so maybe just make the mtext and then move it up "LineSpacingDistance", if you use (Entget (entlast)) then (assoc 42 will return 2x the line spacing not sure why 2x.

0 Likes