VisualLisp Command to Get/Put Rotation on MLeader

VisualLisp Command to Get/Put Rotation on MLeader

ebsoares
Collaborator Collaborator
4,010 Views
20 Replies
Message 1 of 21

VisualLisp Command to Get/Put Rotation on MLeader

ebsoares
Collaborator
Collaborator

Hi, all.

 

From what I understand, vla-get-rotation and vla-put-rotation respectively read and write the "rotation" property of blocks, text, and mtext. But for some reason it does not work for MLeaders...

 

I'm looking for the vla-* code (if it exists) that can change the rotation property of MLeaders.

 

 

Any tip is highly appreciated.

 

Edgar

0 Likes
Accepted solutions (2)
4,011 Views
20 Replies
Replies (20)
Message 2 of 21

dbroad
Mentor
Mentor

When you work with vla- methods, you need to access the available properties of the object.  There is no rotation property for multileaders. There is, however, a textrotation property.

 

Use (vlax-dump-object  <mleaderobject> T) to find out a list of properties and methods.  Use vlax-property-available-P to determine whether a property exists.

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 3 of 21

ebsoares
Collaborator
Collaborator

Thanks for the quick reply, Doug.

 

I'm new to visual lisps (very new), so I'm not sure how to do what I need with that info.

 

How would you go about changing the text rotation property of a selection of multileaders using a Lisp routine (with basic Lisp code or VLA)?

0 Likes
Message 4 of 21

Ranjit_Singh
Advisor
Advisor

Try something like this as a starting point

(defun c:somefunc  (/ ss1 rot)
 (setq ss1 (ssget '((0 . "multileader"))))
 (and ss1
      (setq rot (getreal "\nSpecify new rotation value: "))
      (mapcar '(lambda (x) (setpropertyvalue x "MText/Rotation" rot))
              (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss1)))))
 (princ))
Message 5 of 21

dbroad
Mentor
Mentor

@Ranjit_Singh wrote a nice one.  This is another approach:

(defun c:mltr ( / rot )
  (setq rot (getangle "\nNew leader text rotation angle:"))
  (prompt "nSelect leaders: ")
  (if (ssget '((0 . "MULTILEADER")))
  (vlax-for n (vla-get-activeselectionset
		(vla-get-activedocument
		  (vlax-get-acad-object)))
    (vla-put-textrotation n rot)
    )
    )
  (princ)
  )

With the properties palette, these things are relatively quick to accomplish without programming.

Architect, Registered NC, VA, SC, & GA.
Message 6 of 21

ebsoares
Collaborator
Collaborator

Hi, Ranjit! To the rescue again - Thanks! Smiley Happy

 

The routine you wrote works, but is it also possible to first "read" the current mleader's rotation value, to then add the new angle to it? And to do so to each mleader in the selection set?

 

For example, suppose we select two mleaders, one with a 0 degree rotation and another with 45 degree rotation, then we chose to add an angle of 20 degrees to them, so the first mleader's rotation becomes 20 degrees (0+20) and the second becomes 65 degrees (45+20).

 

By the way, I got the idea from Lee Mac's reply to this post, Rotate multiple blocks around their individual origin point, which does exactly that, but does not work with mleaders (only blocks, texts, and mtexts)...

0 Likes
Message 7 of 21

dbroad
Mentor
Mentor
Accepted solution
(defun c:cmltr ( / rot )
  (setq rot (getangle "\nChange rotation by what angle?:"))
  (prompt "nSelect leaders: ")
  (if (ssget '((0 . "MULTILEADER")))
  (vlax-for n (vla-get-activeselectionset
		(vla-get-activedocument
		  (vlax-get-acad-object)))
    (vla-put-textrotation n (+ (vla-get-textrotation n) rot))
    )
    )
  (princ)
  )
Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 8 of 21

Ranjit_Singh
Advisor
Advisor
Accepted solution

@ebsoares wrote:

.... is it also possible to first "read" the current mleader's rotation value, to then add the new angle to it? .....


Yes. See below edit. Also note that I was using getreal but getangle is a better option as suggested by @dbroad's post

(defun c:somefunc  (/ ss1 rot)
 (setq ss1 (ssget '((0 . "multileader"))))
 (and ss1
      (setq rot (getangle "\nSpecify new rotation value: "))
      (mapcar '(lambda (x) (setpropertyvalue x "MText/Rotation" (+ (getpropertyvalue x "MText/Rotation") rot)))
              (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss1)))))
 (princ))
Message 9 of 21

ebsoares
Collaborator
Collaborator

Wow, two great solutions for the price of one!

 

@dbroad and @Ranjit_Singh, you rock!

 

I really appreciate your help - both solutions do exactly what I'd hope for Smiley Happy

 

Again, thank you so much!

 

Edgar

0 Likes
Message 10 of 21

dbroad
Mentor
Mentor

You're welcome. Now open up vlide and start experimenting on your own.

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 11 of 21

wepp
Participant
Participant

@dbroad  написал (-а):

 

With the properties palette, these things are relatively quick to accomplish without programming.

So, is it possible to do the same, but without changing text position? Rotate not by leader point, but by the center of the text.

0 Likes
Message 12 of 21

dbroad
Mentor
Mentor

Not with the properties palette.  Is that imporant?  It isn't for me.  If I have to rotate the mleader, chances are I will have to adjust its position and size.  Grips do that fine. Where a hook line exists, it rotates it about that.

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 13 of 21

wepp
Participant
Participant

@dbroad  написал (-а):

 If I have to rotate the mleader,


I've rotated whole drawing by 180 degree. So I only need rotate text the same degree. Of course, I've done it manually, but for the future .. For text and mtext there is TORIENT with "most readable" option.

0 Likes
Message 14 of 21

dbroad
Mentor
Mentor

Not for mleaders, AFAIK.  TORIENT is an express tool.  I can't imagine that you are going to need to rotate drawings 180 degrees very often. If so, you should probably rethink your workflow.  qselect will allow you to select all mleaders at one time and then set the rotation.  You can even filter for the rotations and set only the rotations that aren't readable. IMO, it isn't work hacking together a command to extend torient to mleaders. If you want to write one yourself, the torient code can be found in the express folder in the acettxt.lsp file. I doubt Autodesk would complain about you adapting torient.

Architect, Registered NC, VA, SC, & GA.
Message 15 of 21

tjewell
Contributor
Contributor

Can the lisp routine you wrote be modified to work on multileaders using an imbedded block (keynote or detail bubble).

 

Your lisp ignores keynote type multileaders.

Thanks

T

0 Likes
Message 16 of 21

dbroad
Mentor
Mentor

What lisp program?

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 17 of 21

tjewell
Contributor
Contributor
(defun c:cmltr ( / rot )
  (setq rot (getangle "\nChange rotation by what angle?:"))
  (prompt "nSelect leaders: ")
  (if (ssget '((0 . "MULTILEADER")))
  (vlax-for n (vla-get-activeselectionset
		(vla-get-activedocument
		  (vlax-get-acad-object)))
    (vla-put-textrotation n (+ (vla-get-textrotation n) rot))
    )
    )
  (princ)
  )
0 Likes
Message 18 of 21

dbroad
Mentor
Mentor

No. I showed the easy method for text leaders.  For block content leaders, it's more complicated.  Luckily a very smart and determined guy showed the way.  See this post:

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/block-mleader-rotate-an-existing-mle...

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 19 of 21

tjewell
Contributor
Contributor

dbroad,

I really appreciate your help, that lisp worked wonderfully.

Manually rotating hundreds of keynotes is a enormous pain.

 

Thank you for taking the time to hunt down a solution to my problem.

 

Thanks again,

Tim Jewell

0 Likes
Message 20 of 21

kommu_aseervadam
Community Visitor
Community Visitor

Hi it is helped me lot. but i want text rotation value zero directly without typing value in lisp

 

 

0 Likes