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.

to top

You are here: CoCreateModeling > OsdmMacros > MacroSwapColor

r1.3 - 01 May 2007 - 15:15 - ClausBrod to top

CoCreateModeling
CoCreate ModelingRSS
FAQ
  Introduction
  Hardware
  Operating system
  Memory management
  File handling
  Installation
  Licensing
  Graphics
  App. knowhow
  Lisp
    Learning
    Programming
    Debugging
    DDE
    Compiler
    Customization
  Troubleshooting
  Links
Code examples
Viewbench
News
Changes
Index
Search
Impressum
Home

  • My links
  • Show me topics of interest

TWiki

Welcome


TWiki Web TWiki Web Home Changes Topics Index Search


TWiki Webs Atari Blog Main OneSpaceModeling? Sandbox TWiki TWiki Webs Atari Blog Main OneSpaceModeling? Sandbox TWiki

Jump:

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