Ahankhah Posted January 17, 2021 Posted January 17, 2021 (edited) Hi all, how is it possible to get and put alignment of a MTEXT object via AutoLISP? I appreciate any help. Edited January 17, 2021 by Ahankhah Quote
Jonathan Handojo Posted January 17, 2021 Posted January 17, 2021 (edited) It's the "AttachmentPoint" property... It's value is one of the following: acTopLeft acTopCenter acTopRight acMiddleLeft acMiddleCenter acMiddleRight acBottomLeft acBottomCenter acBottomRight Edited January 17, 2021 by Jonathan Handojo 1 Quote
BIGAL Posted January 17, 2021 Posted January 17, 2021 Can use numbers a bit easier to type 1-9 AttachmentPoint = 5 middle centre. 1 Quote
dexus Posted January 18, 2021 Posted January 18, 2021 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. 1 Quote
Ahankhah Posted January 18, 2021 Author Posted January 18, 2021 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. Quote
Ahankhah Posted January 18, 2021 Author Posted January 18, 2021 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. Quote
Ahankhah Posted January 18, 2021 Author Posted January 18, 2021 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. Quote
Jonathan Handojo Posted January 18, 2021 Posted January 18, 2021 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") ) ) Quote
Ahankhah Posted February 4, 2021 Author Posted February 4, 2021 Jonathan Handojo, the information you offered is very helpful. Thank you very much. Quote
Recommended Posts
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.