Jump to content

Mline: Change the justification without changing the position


Recommended Posts

Posted

Hallo,

I need to change the justification of various mline, that i have in an old drawing, withou changing the position of the mline, like the command TJUST for text.

 

There is a lisp for that?

 

Thank you!

Posted

Hi dlanorh, 

I'm referring to a mline (multi-line), I'm not speaking about a mtext (multi line text). 

:) 

Posted (edited)
3 hours ago, marmo said:

Hi dlanorh, 

I'm referring to a mline (multi-line), I'm not speaking about a mtext (multi line text). 

:)

 

Just checking.

 

Try this. It works on a single object at a time but could be adapted.

 

(vl-load-com)

(defun c:mlj ( / *error* c_doc ms ml_obj o_lyr objs a_lst e_lst)

	(defun *error* ( msg ) 
		(if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc))
		(if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nOops an Error : " msg " occurred.")))
		(princ)
	);_end_*error*_defun

  (setq dynp (getvar 'dynprompt)
        dynm (getvar 'dynmode)
  )
  (setvar 'dynprompt 1)
  (setvar 'dynmode 3)
  
	(setq c_doc (vla-get-activedocument (vlax-get-acad-object))
        j_lst '((0 . "Top") (1 . "Middle") (2 . "Bottom"))
        jp_lst '("Top" "Middle" "Bottom")
  );end_setq
  
  (while (not ml_obj) 
    (setq ent (car (entsel "\nSelect Multiline Object : ")))
    (if (= (cdr (assoc 0 (entget ent))) "MLINE")
      (setq ml_obj (vlax-ename->vla-object ent))
    );end_if
  );end_while  
  
	(if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc))
	(vla-startundomark c_doc)
  
  (setq ml_just (vlax-get-property ml_obj 'justification))
  
  (initget 1 (vl-string-right-trim " "(apply 'strcat (mapcar '(lambda (x) (strcat x " ")) jp_lst))))
  (setq choice (getkword (strcat "["(vl-string-right-trim "/"(apply 'strcat (mapcar '(lambda (x) (strcat x "/")) jp_lst)))"] <" (cdr (assoc ml_just j_lst)) "> : ")))

  
  (cond ( (= choice "Top") (setq ml_just 0))
        ( (= choice "Middle") (setq ml_just 1))
        ( (= choice "Bottom") (setq ml_just 2))
  );end_cond
  (vlax-put-property ml_obj 'justification ml_just)
   
  (setvar 'dynprompt dynp)
  (setvar 'dynmode dynm)
  (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc))
  (princ) 
);end_defun

 

Edited by dlanorh
code updated
Posted

Thankyou dlanorh but the lisp not useful for my purpose because when you change the justification the mline moves accordingly to the new justification.

 

Instead I would like to change the justification without moving the mline.

That is the problem. 

 

Posted
19 hours ago, ronjonp said:

Post an example drawing.

Hi ronjonp,

I think that it's not necessary.

To verify that is enough:

1) draw an mline

2) open the properties panel

3) look at the justification row at the bottom of the properties panel

4) change directly from the panel the justification of the mline (you have 3 possible choises : Top, bottom, zero)

5) when you do that you see that the mline moves accordingly!

 

The question is to change the justification point and keep fixed the position of the mline.

 

Thankyou :)

 

Posted (edited)

https://forums.autodesk.com/t5/autocad-forum/changing-mline-grip-to-center/td-p/7183627

 

This one shows more or less the question I'm writing about. At the end they say that is not possible to change the position of the grip whitout changing the geometry of the mline.

Is it ALWAYS true? There is a way via lisp to solve the problem?

For example for texts you can use the both ways, you can change the grip position with or without moving the text.  

 

 

Edited by marmo
Posted (edited)
2 hours ago, marmo said:

https://forums.autodesk.com/t5/autocad-forum/changing-mline-grip-to-center/td-p/7183627

 

This one shows more or less the question I'm writing about. At the end they say that is not possible to change the position of the grip whitout changing the geometry of the mline.

Is it ALWAYS true? There is a way via lisp to solve the problem?

For example for texts you can use the both ways, you can change the grip position with or without moving the text.  

 

 

 

Changing the justification of a mline changes the geometry of the mline since the mline coordinates remain the same no matter the justification; and the grips remain at the vertices. The lines change to accomodate the new justification.

 

You can extract the mline coordinates, its current justification and width (MLineScale property).

It may then be possible to draw a pline through the coordinates, offset that by the required distance for the new justification and constructing a new mline using the coords of the offset line with the required justification; or simply write the new coordinates back into the existing mline and change the justification. Having never done that, I couldn't say if the new mline would exactly follow the old mline.

 

Bottom justification is always to the right of the direction in which it was constructed.

Edited by dlanorh
Posted

Maybe a hack like this .. definitely works with two point mlines:

(defun c:foo (/ a b i o s)
  ;; RJP » 2018-10-17
  (cond	((setq s (ssget ":L" '((0 . "mline"))))
	 (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
	   (setq o (vlax-ename->vla-object x))
	   (setq i (vla-get-justification o))
	   (vla-getboundingbox o 'a z)
	   (setq b a)
	   (vla-put-justification
	     o
	     (if (< i 2)
	       (1+ i)
	       0
	     )
	   )
	   (vla-update o)
	   (vla-getboundingbox o 'a z)
	   (vla-move o a b)
	 )
	 (sssetfirst nil s)
	)
  )
  (princ)
)

 

2018-10-17_11-01-58.gif

  • Like 1
Posted

Here's a version where you can choose the justification:

(defun c:foo (/ a b c d i o s)
  ;; RJP » 2018-10-17
  (setq c '("Top" "Zero" "Bottom"))
  (initget "Top Zero Bottom")
  (setq	d (cond	((getkword "\nEnter justification [Top/Zero/Bottom]<Top>:"))
		("Top")
	  )
  )
  (cond	((setq s (ssget ":L" '((0 . "mline"))))
	 (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
	   (setq o (vlax-ename->vla-object x))
	   (setq i (vla-get-justification o))
	   (vla-getboundingbox o 'a z)
	   (setq b a)
	   (vla-put-justification o (vl-position d c))
	   (vla-update o)
	   (vla-getboundingbox o 'a z)
	   (vla-move o a b)
	 )
	)
  )
  (princ)
)

 

  • Like 1
Posted

Perfect!

Thank you guys!
You are geniuses!

  • 3 weeks later...
Posted
2 hours ago, marmo said:

For some reasons it doesn't work in this file. It changes the geometries.

 

test MLJUST.dwg

 

This is not a problem with my MLJUST program, but rather a problem or corruption with the Multiline Styles in your drawing - if you change the MLine justification using the AutoCAD Properties Palette you will receive the same result as with my program.

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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...