Jump to content

Match Properties in reverse pick order


Recommended Posts

Posted

Normally when applying the matchprop command in CAD, one has to first pick the template element, and then select the elements which should have this template element's properties copied to/matched.

 

is it possible (via lisp perhaps?) to reverse this order, so that i can select a bunch of elements (e.g. through the quickselect icon) and THEN apply a matchpropertieslisp command, then select a single template element which the initially selected elements should mimic?

Posted

In principle, yes it would be possible to create and populate a selection set in LISP, then pick your template object and then assign that object's properties to each object in the selection set.

 

Personally I've never seen such a routine, but there are many more qualified people than me here in the forum to answer that question.

Posted

Thanks Tyke

 

big up to germany! I've been livign/working in Munich since January!

Posted

if you know the properties you want to match rather than match an object you can select your elements and then use the properties palette.

Posted (edited)

got the nugget i was after from Lee Mac on another forum. Works perfectly:

 

 

(defun c:mp ( / ss )
   (if (setq ss (ssget "_:L"))
       (command "_.matchprop" pause ss "")
   )
   (princ)
)

Edited by SLW210
placed code in tags.
Posted
got the nugget i was after from Lee Mac on another forum. Works perfectly:

 

 

(defun c:mp ( / ss )
   (if (setq ss (ssget "_:L"))
       (command "_.matchprop" pause ss "")
   )
   (princ)

)

 

Careful what you say now Barry, Lee Mac is VERY active in this forum too and you will no doubt get a response from him here, right Lee ;)

 

Are you using a German or Engish version of AutoCAD?

 

See you at the Oktoberfest :beer:

 

PS don't forget to wrap any code in code tags, before one of the Mods gets you.

  • 13 years later...
Posted (edited)

To expand on @barry2104's answers here's one that I wrote.

 

;;
;; 3dwannab_MatchPropsMod.lsp
;;
;; Author: 3dwannab
;;
;; Version History:
;;   v1.0 - 2024.12.28 First written.
;;   v1.1 - 2025.05.23 Last updated.
;;   v1.2 - 2025.06.16 Last updated.
;;   v1.3 - 2025.07.06 Add vla-highlight to preselected entities
;;
;; Reverse MATCHPROP: Select destination objects first, then the source object.
;;
;; Type the MA command to allow selecting destination objects first, then the source object.
;; If nothing is preselected, runs the standard MATCHPROP command.
;; Useful for workflows where you want to pick what to change before picking the entity to match.
;;
;; NOTES:
;; - Uses the standard MATCHPROP command internally.
;; - No known bugs.
;;
;; TO DO:
;; – NA
;;

(vl-load-com)

(defun c:MA (/ _HighlightSelectionSet *error* acDoc en len ss var_cmdecho var_osmode) 

  (defun _HighlightSelectionSet (ss / i ename vlaObj) 
    (if ss 
      (progn 
        (setq i 0)
        (while (< i (sslength ss)) 
          (setq ename (ssname ss i))
          (setq vlaObj (vlax-ename->vla-object ename))
          (vla-highlight vlaObj :vlax-true) ; :vlax-true = highlight ON
          (setq i (1+ i))
        )
      )
    )
  )

  (defun *error* (errmsg) 
    (and acDoc (vla-EndUndoMark acDoc))
    (and errmsg 
         (not (wcmatch (strcase errmsg) "*CANCEL*,*EXIT*"))
         (princ (strcat "\n<< Error: " errmsg " >>\n"))
    )

    (setvar 'cmdecho var_cmdecho)
    (setvar 'osmode var_osmode)
  )

  (setq acDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (or (vla-EndUndoMark acDoc) (vla-StartUndoMark acDoc))

  (setq var_cmdecho (getvar "cmdecho"))
  (setq var_osmode (getvar "osmode"))

  (setvar 'cmdecho 0)
  (setvar 'osmode 0)

  ;; Get a preselection if one exists
  ;; There's a bug when only using the "_I" Implied selection when the selection set only contains one object.
  ;; So set the selection to the ss variable with "_:L" which only allows for the selection of unlocked layers.
  (if (ssget "_I") 
    (setq ss (ssget "_:L"))
  )

  ; (command "_.undefine" "MA") ;; DON'T NEED THIS: Undefine the shortcut MA for MATCHPROP so this program can use it.

  ;; Check for a selection set if one has been selected.
  (if ss 
    (progn 

      (_HighlightSelectionSet ss)

      (setvar 'errno 0)
      (princ "\nUsing inverted MATCHPROP command\n")
      (while 
        (not 
          (or 
            (= 52 (getvar 'errno))
            (setq en (car (entsel "\nSelect source object: ")))
          )
        )
        (princ "\n** Nothing Selected **")
      )
      en

      ;; If a selection set exists, perform inverted match properties

      (command "_.matchprop" "_non" en "_non" ss "")
      (sssetfirst nil ss)
      (command "_.regen")
      (princ (strcat "\n>>> " (itoa (setq len (sslength ss))) (if (> len 1) " <<< entities" " <<< entity") " matched\n"))
    )
    ;; Otherwise, use the default MATCHPROP command
    (progn 
      (princ "\nNo pre-selection detected. Using default MATCHPROP command\n")
      (command "matchprop")
    )
  )

  (vla-EndUndoMark acDoc)

  (*error* nil)
  (princ)
)

(princ "\n3dwannab_MatchPropsMod.lsp loaded...")

; (c:MA) ;; Unblock for testing

 

Edited by 3dwannab
updated

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...