Matchproperty MText with Background Mask Excluding Rotation

Matchproperty MText with Background Mask Excluding Rotation

sdhara.hit
Advocate Advocate
469 Views
4 Replies
Message 1 of 5

Matchproperty MText with Background Mask Excluding Rotation

sdhara.hit
Advocate
Advocate

Required autocad lsp for autocad2019 to Matchproperty MText with Background Mask Excluding Rotation 

0 Likes
470 Views
4 Replies
Replies (4)
Message 2 of 5

john.uhden
Mentor
Mentor

@sdhara.hit ,

Please explain further.

Do you want to match all properties except rotation (and position I presume),

OR

Do you want to match just the masking (background fill)?

John F. Uhden

0 Likes
Message 3 of 5

sdhara.hit
Advocate
Advocate
match all properties except rotation (and position I presume),
0 Likes
Message 4 of 5

komondormrex
Mentor
Mentor

check the following

 

;***********************************************************************************************************************

;	komondormrex, aug 2024

;***********************************************************************************************************************

(defun put_props (source target prop_list)
	(foreach property prop_list
		(vl-catch-all-apply (read (strcat "vla-put-" (vl-symbol-name property)))
							(list target
								  (vl-catch-all-apply
								  	(read (strcat "vla-get-" (vl-symbol-name property)))
									(list source)
								  )
							)
		)
	)
)

;***********************************************************************************************************************

(defun c:match_mtxt_props (/ source prompt_ source_dxf mtext_sset rotation source_mask_data)
	(if (setq source (car (entsel "\nPick Mtext to copy props from: ")))
		(if (setq prompt_ "Select MTexts to paste props onto: "
				  source_dxf (entget source)
				  source (vlax-ename->vla-object source)
				  mtext_sset (ssget ":l" '((0 . "mtext")))
			)
			(foreach target (mapcar 'vlax-ename->vla-object
									(vl-remove-if 'listp (mapcar 'cadr (ssnamex mtext_sset)))
							)
				(setq rotation (vla-get-rotation target))
				(if (minusp (vlax-get source 'backgroundfill))
					(setq source_mask_data
							(vl-remove nil
									  (mapcar '(lambda (group) (if (assoc group source_dxf)
																   (cons group (cdr (assoc group source_dxf))))
											   )
											  '(90 63 421 431 45)
									  )
						    )
					)
				)
				(put_props source
						   target
						  '(attachmentpoint backgroundfill drawingdirection entitytransparency height
						  	layer linespacingdistance linespacingfactor linespacingstyle linetype
							linetypescale lineweight material normal plotstylename stylename truecolor
						   )
				)
				(vla-put-rotation target rotation)
				(setq target_dxf (entget (vlax-vla-object->ename target)))
				(if (minusp (vlax-get target 'backgroundfill))
					(entmod (append (reverse (cdr (member (assoc 90 target_dxf) (reverse target_dxf))))
									 source_mask_data
							)
					)
					(entmod (append (reverse (cdr (member (assoc 44 target_dxf) (reverse target_dxf))))
									source_mask_data
									(cdr (member (assoc 44 target_dxf) target_dxf))
							)
					)
				)
			)
		)
	)
	(princ)
)

;***********************************************************************************************************************

 

0 Likes
Message 5 of 5

Kent1Cooper
Consultant
Consultant

If you're talking about Matching one target Mtext to the source in everything [including background mask] except the target's Rotation, in simplest terms:

 

(defun C:MPMTnoR ; = Match Properties of MText except Rotation
  (/ source target targetR)
  (setq
    source (car (entsel "\nSource Mtext for Properties to Match: "))
    target (car (entsel "\nTarget Mtext to get Properties but keep its Rotation: "))
    targetR (getpropertyvalue target "Rotation")
  ); setq
  (command "_.matchprop" source target "")
  (setpropertyvalue target "Rotation" targetR)
  (prin1)
)

 

If more than one target, each potentially with its own Rotation:

 

(defun C:MPMTnoR ; = Match Properties of MText except Rotation
  (/ source targets n target targetR)
  (if
    (and
      (setq source (car (entsel "\nSource Mtext for Properties to Match: ")))
      (member '(0 . "MTEXT") (entget source))
      (setq targets (ssget "_:L" '((0 . "MTEXT"))))
    ); and
    (repeat (setq n (sslength targets)); then
      (setq
        target (ssname targets (setq n (1- n)))
        targetR (getpropertyvalue target "Rotation")
      ); setq
      (command "_.matchprop" source target "")
      (setpropertyvalue target "Rotation" targetR)
    ); repeat
  ); if
  (prin1)
)

 

which has the difference from regular MATCHPROP that it doesn't change the properties of each target one as you select it [if you pick one by one], but waits until you make the entire selection [by whatever mode(s)] before processing them.

The second one's a little less simple than the first, in limiting selection to the right kind of objects, but both could use the other usual enhancements.

Kent Cooper, AIA
0 Likes