Text Height Update In C Sharp

Text Height Update In C Sharp

muckmailer
Collaborator Collaborator
4,201 Views
45 Replies
Message 1 of 46

Text Height Update In C Sharp

muckmailer
Collaborator
Collaborator

The following Lisp route will update text by style. Can this be done in C sharp?

 

I am looking for a c sharp routine that would have an select all so I can make changes to all text in the drawing.

 

 

;;  TextHeightUpdate.lsp [command name: THU]
;;  To Update the Height of Text and Mtext in Styles with defined heights,
;;    when height has been changed in Style definition.  Checks Style of all
;;    selected Text/Mtext, and it has a defined height, imposes that on object.
(defun C:THU (/ ss n obj ht)
  (prompt "\nTo Update the Height of fixed-height Text/Mtext,")
  (if (setq ss (ssget '((0 . "TEXT,MTEXT"))))
    (repeat (setq n (sslength ss))
      (setq obj (vlax-ename->vla-object (ssname ss (setq n (1- n)))))
      (if
        (> (setq ht (cdr (assoc 40 (tblsearch "style" (vla-get-StyleName obj))))) 0)
        (vla-put-Height obj ht); then
      ); if
    ); repeat
  ); if
  (princ)
); defun
(vl-load-com)
(prompt "\nType THU for Text Height Update.")

Thank you

 

0 Likes
Accepted solutions (1)
4,202 Views
45 Replies
Replies (45)
Message 41 of 46

ActivistInvestor
Mentor
Mentor

@muckmailer wrote:

If I start the update routine using a form button with the attached code the
routine does not do anything until after:

1. The button is pushed
2. I exit the form the button is in.
3. I hit the return key on the keyboard

 

How can I put this routine in a loop?
For example a file loop to that open and closes
several drawings for update?

 

 


Download the code attached to this post, and you'll find an example showing how to do that.

 

However, that code presumes a reasonable level of familiarity with C#, .NET, and the AutoCAD .NET API. Without that, it's going to be difficult to solve any problem, regardless of how much code you get others to write for you here.

 

 

0 Likes
Message 42 of 46

ActivistInvestor
Mentor
Mentor

In the code you show below, the reason the command doesn't run until you close the form and press enter, is because you didn't include a newline character at the end of the command name in SendStringToExecute(), like this:

 

 

doc.SendStringToExecute("THWU\n", false, false, false);

As far how to use the code in a batch-process, see my other reply above.

 


@muckmailer wrote:

If I start the update routine using a form button with the attached code the
routine does not do anything until after:

1. The button is pushed
2. I exit the form the button is in.
3. I hit the return key on the keyboard

 

How can I put this routine in a loop?
For example a file loop to that open and closes
several drawings for update?

Thank you,

private void button7_Click(object sender, EventArgs e)
        {
           //Routine TextHeightUpdateNoElock() [CommandMethod("THWU")]
            var doc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
            if (doc != null)
                doc.SendStringToExecute("THWU", false, false, false);
        }

 


 

0 Likes
Message 43 of 46

muckmailer
Collaborator
Collaborator

At times it seems like the update THWD routine changes width based on a style height.
Is there some restriction on height to width ratios or something?
I am trying to figure out what is is doing here?

 

I have not found any information on the follow statment
if (textStyleWidths..ContainsKey(text.TextStyleName))
text.WidthFactor = textStyleWidths[text.TextStyleName];

I googled textStyleWidths.ContainsKey to but I did not find anything on it.
Maybe that has something to do with it.

Thank you,

0 Likes
Message 44 of 46

_gile
Consultant
Consultant

textStyleWidths is a local variable of type Dictionary<string, double>.

 

Looks like your ambitions far exceed your C# skills
In the first message, it was just a question of translating a small LISP routine to select all texts and mtextes and assign them the height defined in the text style.
We are in more than 40 messages and whenever you have been offered an answer to your request, you have responded with a new request, although you have obviously not understood the code provided to you. .
I'm afraid I can not continue on this path, it's not the right way to learn.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 45 of 46

ActivistInvestor
Mentor
Mentor

I'm going to have to agree with @_gile.

 

The plugin you're trying to build requires at least a year of full-time experience with the API.

 

You can find plenty of learning materials >here<

 

 

 

0 Likes
Message 46 of 46

muckmailer
Collaborator
Collaborator
Accepted solution

Unfortunately I don't have the time to do this 24/7 full time

and that is what I think it might take to fully understand the code.

but I think I have enough to use the code.

 

 

 

 

0 Likes