Jump to content

How to change alignment of MTEXT object, while vla-put-alignmentput isn't valid for it.


Recommended Posts

Ahankhah

Hi all,

 

how is it possible to get and put alignment of a MTEXT object via AutoLISP?

 

I appreciate any help.

Edited by Ahankhah
Link to post
Share on other sites
Jonathan Handojo

It's the "AttachmentPoint" property... It's value is one of the following:

 

acTopLeft

acTopCenter

acTopRight

acMiddleLeft

acMiddleCenter

acMiddleRight

acBottomLeft

acBottomCenter

acBottomRight

Edited by Jonathan Handojo
  • Like 1
Link to post
Share on other sites

I'm quite new to all the vla functions myself, so it took me a while to figure out how to use the list above.

But this works. Here is how to get the object:

(setq obj (vlax-ename->vla-object (car (entsel))))

And this to get the alignment of that object:

(vla-get-attachmentPoint obj)

And this to set the alignment of that object:

(vla-put-attachmentPoint obj 1)

 

Not sure how to add error handling and to check if the AttachmentPoint property actually exists in the object.

  • Like 1
Link to post
Share on other sites
Ahankhah
16 hours ago, Jonathan Handojo said:

It's the "AttachmentPoint" property... It's value is one of the following:

 

acTopLeft

acTopCenter

acTopRight

acMiddleLeft

acMiddleCenter

acMiddleRight

acBottomLeft

acBottomCenter

acBottomRight

Jonathan, thank you very much, but I am seeking then function to get/put these justifications from/on MTEXT object.

Link to post
Share on other sites
Ahankhah
10 hours ago, BIGAL said:

Can use numbers a bit easier to type 1-9 

 

AttachmentPoint = 5 middle centre.

BIGAL, you are right, it is easier to type, but the writing code with constants is a good method to further references.

Link to post
Share on other sites
Ahankhah
56 minutes ago, dexus said:

I'm quite new to all the vla functions myself, so it took me a while to figure out how to use the list above.

But this works. Here is how to get the object:


(setq obj (vlax-ename->vla-object (car (entsel))))

And this to get the alignment of that object:


(vla-get-attachmentPoint obj)

And this to set the alignment of that object:


(vla-put-attachmentPoint obj 1)

 

Not sure how to add error handling and to check if the AttachmentPoint property actually exists in the object.

dexus,

this is exactly what I was searching for. Thank you very much.

Indeed I was searching something like: "alignment" or "justify" or "justifications" in the properties of "MTEXT".

Again I appreciate your kind help.

Link to post
Share on other sites
Jonathan Handojo
6 hours ago, Ahankhah said:

Jonathan, thank you very much, but I am seeking then function to get/put these justifications from/on MTEXT object.

No problem. It's exactly as how @dexus pointed out. You can run into an error when applying for something that doesn't exist. I normally do:

 

(vla-put-AttachmentPoint obj acMiddleCenter)

 

You can pass it this way if you want to see whether it's valid:

 

(vl-catch-all-error-p (vl-catch-all-apply 'vla-put-AttachmentPoint (list obj num)))

 

 

8 hours ago, dexus said:

I'm quite new to all the vla functions myself, so it took me a while to figure out how to use the list above.

But this works. Here is how to get the object:


(setq obj (vlax-ename->vla-object (car (entsel))))

And this to get the alignment of that object:


(vla-get-attachmentPoint obj)

And this to set the alignment of that object:


(vla-put-attachmentPoint obj 1)

 

Not sure how to add error handling and to check if the AttachmentPoint property actually exists in the object.

 

If my explanation above returns T, then you know something is wrong. The number is invalid, or the layer of the text itself is locked/frozen, etc...

You can find out whether it's a number issue using vl-catch-all-error-message though. The returned message is "Automation Error. Invalid argument attPoint in DrawingDirection"

 

So in the end, it comes to something like the below

 

(if
    (vl-catch-all-error-p
	(setq err
		 (vl-catch-all-apply
		     'vla-put-AttachmentPoint
		     (list
			 )
		     )
	      )
	)
    (if (wcmatch (vl-catch-all-error-message err) "*Invalid argument attPoint in DrawingDirection")
	(princ "\nInvalid attachment")
	(princ "\nOther error")
	)
    )

 

Link to post
Share on other sites
  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...