OneSpace Modeling: Swap part color

A customer recenty asked for a tool to change the color of any part which matches a given color, i.e. change the color of all red parts to blue.

It is almost trivial to re-use the approach described here for this purpose: Instead of specifying a pattern and searching for parts which match it, we search for parts with a given color; and instead of deleting matching parts, we change their color - that's all.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Description:  Changes colors for parts with a specified color
;; Author:       Claus Brod
;; Created:      3/20/2006 20:20    
;; Language:     Lisp
;;
;; (C) Copyright 2006 Claus Brod, all rights reserved
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
(in-package :clausbrod.de)
(use-package :oli)

(sd-defdialog 'CHANGE_COLOR
  :dialog-title "Change part color" :toolbox-button t

  :variables 
  '(
    (parts :value-type :part :multiple-items t)
    (oldcolor :value-type :rgb-color :title "Old color")
    (newcolor :value-type :rgb-color :title "New color")
    )
  
  :local-functions 
  '(
    (change-color (item)
        (when (= (sd-rgb-to-color (sd-inq-part-color item)) oldcolor)
          (sd-call-cmds (part_prop item :color newcolor :done))))
    )
  
  :ok-action '(mapc #'change-color parts)
  )

There is one problem with this: If the user selects all parts in a very large assembly, the variable parts will hold a long list, even though maybe only a few parts would have to change their color.

A more efficient solution is to use get_selection with a :check-function which allows to filter parts with the matching color.

-- ClausBrod - 20 Mar 2006


When asked for a TWiki account, use your own or the default TWikiGuest account.

Revision: r1.3 - 01 May 2007 - 15:15 - ClausBrod
CoCreateModeling > OsdmMacros > MacroSwapColor
Copyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback