Lisp to conver Mleader arrow angle to zero

Lisp to conver Mleader arrow angle to zero

atawk
Enthusiast Enthusiast
5,160 Views
25 Replies
Message 1 of 26

Lisp to conver Mleader arrow angle to zero

atawk
Enthusiast
Enthusiast

Do you have a lisp that convert the Mleader arrow's "angle" to 180 degree?

0 Likes
Accepted solutions (1)
5,161 Views
25 Replies
Replies (25)
Message 2 of 26

ВeekeeCZ
Consultant
Consultant
Accepted solution

Just thought that I will learn something new.

 

(vl-load-com)

(defun c:MleaderFlat ( / s i c o)
  (if (setq s (ssget "_:L" '((0 . "MULTILEADER"))))
    (repeat (setq i (sslength s))
      (if (and (setq o (vlax-ename->vla-object (ssname s (setq i (1- i)))))
	       (setq c (vlax-safearray->list (vlax-variant-value (vla-getleaderlinevertices o 0))))
	       (setq c (apply 'list (mapcar '(lambda (x) (nth x c)) '(0 1 2 3 1 5)))))
	(vla-SetLeaderLineVertices o 0 (vlax-safearray-fill (vlax-make-safearray vlax-vbDouble '(0 . 5)) c)))))
  (princ)
  )
 

 

Message 3 of 26

Automohan
Advocate
Advocate

Please can you modify for 45 degree

MLeader.jpg

"Save Energy"
Did you find this reply helpful? If so please use the Accept as Solution
0 Likes
Message 4 of 26

Automohan
Advocate
Advocate

girl-tired-waiting-boredom-long-wait-flat-vector-illustration-144907399.jpg

"Save Energy"
Did you find this reply helpful? If so please use the Accept as Solution
0 Likes
Message 5 of 26

devitg
Advisor
Advisor

be it can help  

 

devitg_0-1621707080217.png

 

0 Likes
Message 6 of 26

Automohan
Advocate
Advocate

not asking to create new mleaders, need to edit the existing mleaders

-sorry if i am mistakenly sound- i will try also. . .

"Save Energy"
Did you find this reply helpful? If so please use the Accept as Solution
0 Likes
Message 7 of 26

devitg
Advisor
Advisor

@Automohan so please upload a sample dwg , and state constriant to do it . 

 

Better a before and an after . 

 

 

0 Likes
Message 8 of 26

ВeekeeCZ
Consultant
Consultant
(vl-load-com)

(defun c:Mleader45 ( / s i c o h v)
  (if (setq s (ssget "_:L" '((0 . "MULTILEADER"))))
    (repeat (setq i (sslength s))
      (if (and (setq o (vlax-ename->vla-object (ssname s (setq i (1- i)))))
	       (setq c (vlax-safearray->list (vlax-variant-value (vla-getleaderlinevertices o 0))))
	       (setq h (apply 'list (mapcar '(lambda (x) (nth x c)) '(0 1 2))))
	       (setq v (apply 'list (mapcar '(lambda (x) (nth x c)) '(3 4 5))))
	       (setq h (polar v (* 1.25 pi) (distance h v))))
	(vla-SetLeaderLineVertices o 0 (vlax-safearray-fill (vlax-make-safearray vlax-vbDouble '(0 . 5)) (append h v))))))
  (princ)
  )
Message 9 of 26

Automohan
Advocate
Advocate

Wow! That worked beautifully. Thank you. I appreciate the help very much!

"Save Energy"
Did you find this reply helpful? If so please use the Accept as Solution
0 Likes
Message 10 of 26

margono_bersinar
Enthusiast
Enthusiast

how if we want to make it 30 degrees or 60 degrees , i try change the pi to 0.33 or .66 but that one not accurate. can you help me sir.

0 Likes
Message 11 of 26

ВeekeeCZ
Consultant
Consultant

How about 0.333333333333333333, does it help? If that's still not enough, add some more, you can go up to 15 digits. 

0 Likes
Message 12 of 26

margono_bersinar
Enthusiast
Enthusiast

yes sir it can better than before. thank you

i thought we can do with fraction number.

0 Likes
Message 13 of 26

ВeekeeCZ
Consultant
Consultant

@margono_bersinar wrote:

yes sir it can better than before. thank you

i thought we can do with fraction number.


 

No, fraction numbers are not supported. You need to use a division. See HERE a list of arithmetical functions that we have available. 

Message 14 of 26

komondormrex
Mentor
Mentor

This is a function, which takes a decimal degrees angle both positive and negative as an argument. Should be called like (mleader_angle 60) or (mleader_angle -60) etc.

 

 

(defun mleader_angle (_angle / mleader_sset index line1 angle_negativity line1_point2)
	(vla-startundomark (vla-get-activedocument (vlax-get-acad-object)))
	(if (not (zerop _angle)) (setq angle_negativity (/ _angle (abs _angle))))
	(if (< 360 (abs _angle))
		(* angle_negativity (setq _angle (- (abs _angle) (* (fix (/ (abs _angle) 360)) 360))))
	)
	(if (minusp _angle)
		(setq _angle (/ (* (- 360 (abs _angle)) pi) 180))
		(setq _angle (/ (* _angle pi) 180))
	)
	(if (setq mleader_sset (ssget "_:L" '((0 . "multileader"))))
    		(repeat (setq index (sslength mleader_sset))
			(setq line1 (vlax-invoke (setq mleader_object (vlax-ename->vla-object (ssname mleader_sset (setq index (1- index))))) 'getleaderlinevertices 0)
			      line1_point2 (polar (list (nth 0 line1) (nth 1 line1))
						  _angle
						  (distance (list (nth 0 line1) (nth 1 line1)) (list (nth 3 line1) (nth 4 line1)))
					   )
			)
			(vlax-invoke mleader_object 'setleaderlinevertices 0 (list (nth 0 line1) (nth 1 line1) (nth 2 line1) (car line1_point2) (cadr line1_point2) (nth 2 line1)))
			(if (< (car line1_point2) (car line1))
			  	(progn
					(vl-catch-all-apply 'vla-setdoglegdirection (list mleader_object 0 (vlax-3d-point '(-1.0 0.0 0.0))))
				  	(vl-catch-all-apply 'vla-setdoglegdirection (list mleader_object 1 (vlax-3d-point '(-1.0 0.0 0.0))))
				)
				(progn
					(vl-catch-all-apply 'vla-setdoglegdirection (list mleader_object 0 (vlax-3d-point '(+1.0 0.0 0.0))))
				  	(vl-catch-all-apply 'vla-setdoglegdirection (list mleader_object 1 (vlax-3d-point '(+1.0 0.0 0.0))))
				)
			)
			(vlax-invoke mleader_object 'setleaderlinevertices 0 (list (nth 0 line1) (nth 1 line1) (nth 2 line1) (car line1_point2) (cadr line1_point2) (nth 2 line1)))
			(princ (strcat "\rMLeaders remain to process: " (itoa index)))
		)
	)
	(vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
	(princ)
)

updated

 

 

0 Likes
Message 15 of 26

margono_bersinar
Enthusiast
Enthusiast

how to use this lsp sir?

I copy to my pc can"t use it. can you explain?



0 Likes
Message 16 of 26

komondormrex
Mentor
Mentor

as far as i remember

1.  type in in command line (load ''saved_code.lsp") <Enter> -> MLEADER_ANGLE

2. type in in command line eg. (mleader_angle 60) <Enter>

3. select mleaders...

0 Likes
Message 17 of 26

margono_bersinar
Enthusiast
Enthusiast

when i type "mleader_angle" on command that one "Unknown command "MLEADER_ANGLE". Press F1 for help"

have problem with this lsp?

and can i type command "mleader_angle 60" using space?

 

0 Likes
Message 18 of 26

komondormrex
Mentor
Mentor

it is a function, so it must have parens at both sides "(mleader_angle 60)"

0 Likes
Message 19 of 26

margono_bersinar
Enthusiast
Enthusiast

ok sir, it's work. thank you

but no simple one to do like LISP in generally sir?

because we always need to copy & paste if we want to use it. use enter after paste the code can't use twice.

0 Likes
Message 20 of 26

margono_bersinar
Enthusiast
Enthusiast

when i update my autocad to 2021, some mleader in my darwing can't use but other can use this LSP and showing like this "Select objects: ; error: Automation Error. Invalid index". any something reson for this one sir?

 

0 Likes